How mguinea/laravel-ddd-example works
Main Components
• API/Application Layer – Represented by the “apps/kanban-api” directory. This is the Laravel-based adapter layer that exposes HTTP endpoints (e.g., controllers for boards and health check). Include key middleware, route handling (routes/api.php), and essential configuration from “config” directory.
• Domain & Application Logic – Located in “src/Kanban/Board” and “src/Shared”. This folder structure is used to implement the core business logic. Break it into:
• Domain Layer: Contains business entities (e.g., Board, BoardId, BoardName) and domain exceptions.
• Application Layer: Includes command, query, and event classes and their corresponding handlers. This layer orchestrates use cases (e.g., create, update, delete, get boards).
• Infrastructure Layer – Found both in “apps/kanban-api” (Laravel specific repositories and service providers) and “src/Kanban/Board/Infrastructure”. This represents persistence (e.g., Eloquent implementations), external bus integrations (with Symfony Messenger), and any external integrations.
• Shared Components – In “src/Shared” which includes shared domain concepts (aggregates, buses, etc.) that work across other bounded contexts.
• External Services – Include external dependencies like RabbitMQ (see “etc/rabbitmq” and reference in the README), MySQL (configured via Docker and connections in “config/database.php”), and monitoring/log aggregation (Grafana and Prometheus in “etc/grafana”, “etc/prometheus”).
Relationships and Interactions
• The API layer (Laravel controllers) acts as an adapter, receiving HTTP requests and then dispatching commands and queries via the infrastructure’s bus (CQRS/Symfony Messenger) toward the Application layer.
• The Application layer handles incoming commands/queries, interacts with the Domain layer for business rules, and coordinates persistence using Repository interfaces defined in the Domain.
• The Infrastructure layer implements the Repository pattern and translates calls to the underlying database (MySQL).
• Event flows include domain events (e.g., BoardWasCreated) that may trigger subscribers (for example, SomethingWithCreatedBoardSubscriber) possibly plugged into RabbitMQ.
Architectural Patterns and Design Principles
• Hexagonal Architecture (Ports & Adapters): Clearly distinguish between “inside” components (domain, application) and “adapters” (Laravel API, persistence, external messaging).
• DDD Elements: Show the business logic in the Domain layer, including entities, value objects, and domain events.
• CQRS: Separate command (write) and query (read) responsibilities; mark the bus channels (CommandBus, QueryBus, EventBus) and their handlers.
• Repository Pattern: Emphasize how repositories abstract the persistence mechanism.
Relevant Technologies and Frameworks
• Laravel 8/PHP 8 for the API layer.
• Docker with provided Dockerfiles and docker-compose for environment management.
• MySQL as the persistent store.
• Symfony Messenger for implementing CQRS.
• RabbitMQ as a message broker (with associated configuration under etc/rabbitmq).
• Terraform and CI/CD (CircleCI, GitHub Actions) support continuous integration and deployment.
Additional Details
• Testing layers (tests/) to show that each component is validated via unit and integration tests.