Hexagonal Architecture + DDD + CQRS in PHP using Laravel 8
This is a monorepo containing a PHP application using Domain-Driven Design (DDD) and Command Query Responsibility Segregation
(CQRS) principles.
It's a basic implementation of a Kanban manager (at this moment, just only manages Board entity with id and name attributes)
The main objective of this implementation is to use Laravel as backend framework but instead of using MVC architecture, go for DDD and Hexagonal.
Report a bug
·
Request a feature
git clone https://github.com/mguinea/laravel-ddd-example laravel-ddd-example
cd laravel-ddd-example
Install all the dependencies and bring up the project with Docker executing:
make build
make up
make migrate
Then you’ll have 1 app available (an API):
Open API documentation here
Postman API collection here
Execute all test suites: make tests
Here are our implementations of the code we have in our base (src). Here can be any framework, etc…
etc
is for “Editable Text Configurations”. So here we can put any configuration by xml, yaml etc… like Docker setup.
src
is for “Source”. Here we put all our code base being as independent as possible of any implementation (except is there is in infrastructure
subfolder).
Kanban: Place where the main functionality is implemented. Management of boards…
This repository follows the Hexagonal Architecture pattern. Also, it’s structured using modules. With this, we can see that the current structure:
Kanban bounded context containing Board module and Shared bonded context.
$ tree -L 3 src
src
├── Kanban
│ └── Board
│ ├── Application
│ ├── Domain
│ └── Infrastructure
└── Shared
├── Domain
│ ├── Aggregate
│ └── Bus
└── Infrastructure
└── Bus
Repository pattern
Our repositories try to be as simple as possible usually only containing basic CRUD methods (delete, find, save and list using criteria pattern).
Symfony Messenger has been used to implement commands, queries and events.
There is a service with RabbitMQ to manage queues. You can access it going to http://localhost:15672
and using guest
as username and password.