How vinh0809it/laravel-ddd-salary works
Main Components
• API Gateway / Entry Point: Represent the public-facing component using Laravel’s HTTP kernel (in bootstrap, public/index.php, and routes) that handles incoming API requests.
• Domains – User and SalaryHistory: In the src folder, each domain is partitioned into four main sub-layers:
○ Presentation: Controllers and Request objects handling client HTTP requests.
○ Application: Contains use cases, command and query buses, DTOs, and handlers responsible for orchestrating business operations.
○ Domain: Contains entities, value objects, domain events, rules, exceptions, and factories encapsulating the core business logic.
○ Infrastructure: Provides concrete implementations for repositories, persistence (migrations and Eloquent models), policies, services, and provider bindings.
• Shared Components: There is a Shared folder to hold common infrastructure, application services, and exception handling logic to keep cross-cutting concerns centralized.
• External Services & Integration: Although not fully implemented, the design shows entry points for external domain services (e.g., IUserDomainService) that allow integration with external systems.
• Tests: Both Unit and Feature tests are organized to validate domain logic and API behavior, which are crucial for maintaining architectural integrity.
Relationships and Interactions Between Components
• The HTTP Layer in the Presentation folder receives API calls through Laravel’s routing (routes/web.php, routes/api.php, and domain-specific route files in Presentation).
• Controllers pass requests to the Application layer by dispatching commands/queries through command and query buses.
• The Application layer interacts with the Domain layer, instantiating entities, enforcing business rules, and triggering domain events.
• The Domain layer remains pure by containing business logic and validation, while the Infrastructure layer implements persistence (via Eloquent and migrations), policies, and external service communication.
• Shared components (in the Shared folder) provide base classes and utilities used across multiple domains.
• Data flows from the API entry point to the respective domain’s use case handlers, processes through different layers, and then returns a response to the client.
Architectural Patterns and Design Principles
• Domain-Driven Design: Clear separation of concerns across Domain, Application, Presentation, and Infrastructure layers enhances maintainability and testability.
• Command-Query Responsibility Segregation (CQRS): Notice the separate handling for commands (writes) and queries (reads), which are managed by distinct buses and handlers.
• Dependency Injection and Inversion of Control: Laravel’s Service Providers (with distinct providers in each domain’s Infrastructure) are used to bind interfaces to implementations.
• Layered Architecture: Each domain encapsulates its own full-stack (from Controller to Repository), allowing isolated evolution.
Technologies and Frameworks
• Laravel 10 and PHP 8.1, which form the backbone for the API.
• Eloquent ORM: Your persistence layer using migrations and Eloquent models.
• Testing Framework: PHPUnit for unit and feature testing.
• Composer for dependency management and package configuration.
• Postman for API testing, as evidenced in the postman folder.
• How the API Gateway (via Laravel routing and controllers) dispatches commands and queries to the respective bus in the Application layer.
• That the domain logic (entities, services, rules, etc.) remains isolated from the infrastructure-specific implementations.
• In the testing framework and configuration files as supporting auxiliary components.