Explore Domain-Driven Design and CQRS in Laravel with this clean and scalable architecture template, ideal for complex applications seeking maintainability and clarity.
shahghasiadil/laravel-clean-architecture-ddd-cqrs is a Laravel package for explore domain-driven design and cqrs in laravel with this clean and scalable architecture template, ideal for complex applications seeking maintainability and clarity..
It currently has 117 GitHub stars and 54 downloads on Packagist (latest version v1.0.3).
Install it with composer require shahghasiadil/laravel-clean-architecture-ddd-cqrs.
Discover more Laravel packages by shahghasiadil
or browse all Laravel packages to compare alternatives.
Last updated
This Laravel project applies the principles of Clean Architecture, Domain-Driven Design (DDD), and Command Query Responsibility Segregation (CQRS) to create a robust, scalable, and maintainable web application. It is designed for developers who aim to build complex systems with a clear separation of concerns and a strong alignment between the business domain and technology.
This project is designed for developers and teams looking to leverage advanced architectural patterns in building complex business applications using Laravel. It is particularly suited for:
Before you begin, ensure you have met the following requirements:
Here are the steps to get your development environment running:
composer create-project shahghasiadil/laravel-clean-architecture-ddd-cqrs my-app
git clone https://github.com/shahghasiadil/laravel-clean-architecture-ddd-cqrs.git
The project follows a modular architecture based on Clean Architecture principles, separating concerns into distinct layers. Below is the directory structure and a detailed description of each layer's responsibility.
src/
├── Application/
│ ├── Bus/
│ ├── Providers/
│ └── User/
│ ├──── CommandHandlers/
│ ├──── Commands/
│ ├──── Contracts/
│ ├──── Data/
│ ├──── Queries/
│ └──── Services/
├── Domain/
│ ├── Providers/
│ ├── Common/
│ ├──── Enums/
│ ├──── Traits/
│ └── User/
│ ├──── Enums/
│ ├──── Entities/
│ ├──── Events/
│ ├──── Exceptions/
│ ├──── Observers/
│ ├──── Policies/
│ └──── Repositories/
├── Infrastructure/
│ ├── Providers/
│ └── User/
│ ├──── Jobs/
│ ├──── Notifications/
│ └──── Persistence/
│ └──────── Repositories/
├── Presentation/
│ └── UserManagement/
│ ├──── Controllers/
│ ├──── Middlewares/
│ ├──── Requests/
│ ├──── Resources/
│ └──── routes/
│ └── Controller.php
└── Shared/
├──── Contracts/
├──── Enums/
└──── Traits/
Application: Manages the application logic and orchestrates the flow of data between the domain and presentation layers. This layer includes:
Bus: Responsible for dispatching commands and queries to the appropriate handlers.Providers: Service providers specific to the application layer, registering application-specific services and dependencies.User: Contains all user-related business logic, divided into:
CommandHandlers: Handles commands related to user actions.Commands: CQRS commands for user-related operations.Contracts: Interface definitions for services and repositories dealing with user data.Data: Data transfer objects (DTOs) that carry data between processes we are using Spatie Laravel Data Package.Queries: CQRS queries for retrieving user data.Services: Services that execute business logic and use cases related to users.Domain: The heart of the business logic, defining entities, value objects, and domain events.
Providers: Domain-level service providers that bind interfaces to implementations within the domain scope.Common: Shared utilities and components that span across multiple domains:
Enums: Cross-domain enumerations defining shared constants and states.Traits: Reusable traits that provide common functionality across various domains.User: Domain logic and entities specific to user management, including:
Entities: Domain models representing users.Enums: User-specific enumerations that define states or types relevant to user management.Events: Events that are domain-specific and might trigger domain actions.Exceptions: Custom exceptions for domain-specific error handling.Observers: Observers for watching changes in domain entities.Policies: Security policies related to user entities.Repositories: Interfaces for user repository implementations.Infrastructure: Implements the interfaces defined by the domain layer, dealing with data persistence and external systems.
Providers: Infrastructure-level service providers that register infrastructure-specific services and dependencies.User: Infrastructure logic specific to user management, including:
Jobs: Background jobs for asynchronous user tasks.Notifications: Notification services to handle alerts and communications.Persistence: Persistence mechanisms for user data, including:
Repositories: Concrete implementations of user repository interfaces.Presentation: Manages the delivery mechanisms, dealing with how the application is presented to the end user (APIs, web UI, etc.).
UserManagement: Presentation logic specifically for managing users, including:
Controllers: Controllers to handle incoming API requests and deliver appropriate responses.Middlewares: Middleware to handle request filtering and pre/post processing.Requests: Form requests for validating user-related data.Resources: Resources and transformers that format domain data into user-friendly formats.routes: Routing configurations that direct incoming requests to the appropriate controllers.Shared: Contains elements that are used across multiple layers, providing cross-cutting functionality.
Contracts: Shared interface definitions that might be used by many components.Enums: Enumerations that provide a set of constants for use throughout the application.Traits: Reusable traits that provide utility functions or methods to multiple classes.This architecture not only segregates the responsibilities into clear, well-defined areas but also promotes a high degree of modularity and replaceability of components.
Contributions are welcome! Please fork the repository and submit pull requests to contribute.