How shahghasiadil/laravel-clean-architecture-ddd-cqrs works
Main Architectural Components
• Application Layer – This is mainly represented in the “src/Application” directory. It contains the command and query buses (for dispatching commands and queries), service providers, and user-specific business logic (commands, queries, command handlers, services, and data transfer objects).
• Domain Layer – Found under “src/Domain”, it represents your core business logic, including entities, domain events, custom exceptions, policies, and repositories interfaces. This is where your DDD principles shine with a focus on encapsulating business rules.
• Infrastructure Layer – In “src/Infrastructure”, this layer provides concrete implementations for domain interfaces (e.g., repositories), deals with persistence, external systems, asynchronous jobs, and notifications. This layer connects the core domain logic with real-world concerns.
• Presentation Layer – Located within “src/Presentation”, it includes controllers, middleware, request validations, resource transformers, and routes (both web and API). It is responsible for handling user requests and formatting responses.
• Shared Components – The “src/Shared” directory encapsulates contracts, common enums, and traits used across multiple layers.
Relationships & Interactions
• Data Flow: The Presentation layer (via controllers) receives incoming HTTP/API requests. These requests pass through middleware and are then forwarded to the Application layer. In the Application layer, the Command Bus and Query Bus coordinate the handling of commands and queries.
• Domain Communication: Once a command or query is dispatched, the corresponding command/query handler will coordinate with Domain services and entities. Here, business rules are applied, and domain events might be triggered.
• Infrastructure Role: When the domain needs to persist or retrieve data, it does so via repository interfaces defined in the Domain layer. The Infrastructure layer provides the concrete implementations for these repositories, handling data storage, external API calls, or integration concerns.
• Service Providers: Across layers, service providers (found in App, Application, Domain, and Infrastructure directories) are responsible for binding interfaces to their implementations, enabling the inversion of control (dependency injection).
Important Architectural Patterns
• Clean Architecture – Emphasize the dependency rule: the core (Domain) is independent of outer layers. Show that outer layers (Infrastructure, Presentation) depend on the inner layers.
• Domain-Driven Design (DDD) – Mark out Domain Entities, Value Objects, and Domain Events, showing clear separation from application logic and technical concerns.
• Command Query Responsibility Segregation (CQRS) – Clearly illustrate the separation between Command operations (writes) and Query operations (reads). You might show two distinct flows emerging from the Application layer: one for handling commands (with Command Handlers) and one for queries (with Query Handlers).
Relevant Technologies and Frameworks
• Laravel and PHP version details should be noted.
• Mention Bundled Tools/Packages like Spatie Laravel Data (for DTOs).
• Build configurations and workflows (e.g., .github/workflows/laravel.yml) can be noted as part of the CI/CD or deployment ecosystem.