php-clean-architecture

Scaffold PHP Clean Architecture layers and enforce dependency rules with deptrac.

15|1|Updated Aug 22, 2025
One-click install
npx skills add https://github.com/giacomomasseron/php-clean-architecture --skill php-clean-architecture
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: php-clean-architecture
Source: https://github.com/giacomomasseron/php-clean-architecture/tree/main
Command: npx skills add https://github.com/giacomomasseron/php-clean-architecture --skill php-clean-architecture

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you scaffold and review PHP code so your project follows Clean Architecture layer rules and avoids dependency inversions that break maintainability.

Core Features & Use Cases

  • Layer enforcement with deptrac: Run architecture checks to detect when controllers, use cases, repositories, or entities violate the dependency direction.
  • Correct scaffolding for architecture layers: Generate Entities, Repositories, UseCases, Controllers, and Services in the right folders and namespaces configured in php-clean-architecture.yaml.
  • Consistent use-case execution and observability: Invoke UseCases via the static run() helper and hook into UseCaseStartedEvent / UseCaseCompletedEvent using the Dispatcher singleton.
  • Optional auto-fixing for marker interfaces: Apply Rector rules to automatically add the required marker interfaces based on class namespaces.

Quick Start

Use the php-clean-architecture Skill to scaffold a new Order UseCase and ensure it correctly implements UseCaseInterface, extends BaseUseCase, and can be executed via OrderPlaceUseCase::run($args) while keeping the Controller → UseCase → Repository → Entity dependency direction intact.

Frequently Asked Questions about php-clean-architecture

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce Clean Architecture dependency rules in a PHP project?

You can enforce Clean Architecture by scaffolding Entities, Repositories, UseCases, and Controllers in correct namespaces, then running deptrac architecture checks to detect dependency rule violations across layers.

How do I scaffold a UseCase in PHP Clean Architecture correctly?

Scaffolding a UseCase in PHP Clean Architecture requires creating a class that extends BaseUseCase, implements the UseCaseInterface marker, and is invoked statically via the run() method while maintaining the Controller to Repository dependency flow.

How does event dispatching work during a UseCase lifecycle in PHP?

Event dispatching during a UseCase lifecycle uses a Dispatcher singleton to emit UseCaseStartedEvent and UseCaseCompletedEvent, providing observability and instrumentation hooks throughout the static run() execution flow.

Can I automatically add marker interfaces to existing PHP classes?

Yes, you can automatically add required marker interfaces to existing PHP classes by applying Rector rules that map class namespaces to specific architecture layer interfaces.

What is the best way to configure layer paths for PHP Clean Architecture?

The best way to configure layer paths and namespaces for PHP Clean Architecture is by defining them in a php-clean-architecture.yaml configuration file, which guides correct scaffolding and deptrac rule validation.