This is a repo containing a PHP application using Domain-Driven Design (DDD) and Command Query Responsibility Segregation
(CQRS) principles.
It's a basic implementation of a User - Role manager. There is a version implemented using Lumen framework and another one using Symfony framework.
Both shares the same domain logics implemented in the src folder.
Report a bug
·
Request a feature
- Clone this project:
git clone https://github.com/mguinea/php-ddd-microservice-example php-ddd-microservice-example - Move to the project folder:
cd php-ddd-microservice-example - Create a local environment file
cp .env.example .env - Change (if required) ports and any other environment variables in
.envfile
Install all the dependencies and bring up the project with Docker executing: make install
Then you'll have 2 apps available (an api made using Lumen and the same one made using Symfony):
- Lumen API: http://localhost:8180/lumen/api/v1/health-check
- Symfony API: http://localhost:8180/symfony/api/v1/health-check
Install the dependencies if you haven't done it previously: make composer-install
Execute all test suites: make tests
TODO
src folder contains the bounded context responsible for the management of users and roles and their relations.
This repository follows the Hexagonal Architecture pattern. Also, it's structured using modules. With this, we can see that the current structure of the Bounded Context is:
$ tree -L 2 src
src
├── Application
│ ├── Role
│ └── User
├── Domain
│ ├── Role
│ ├── Shared
│ └── User
└── Infrastructure
├── Role
├── Shared
└── UserOur repositories try to be as simple as possible usually only containing basic CRUD methods (delete, find, save and search).
If we need some query with more filters we use the Specification pattern also known as Criteria pattern. So we add a searchByCriteria method.
There is an implementation using Eloquent for Lumen and another one made by using PDO for Symfony
We are using symfony messenger to implement buses for Lumen and Symfony implementations.
There are some opinionated resolutions / approaches in this project.
getretrieve an entity. If not found, throws an exception.findretrieve an entity. If not found, return null.deletedelete an entity. If not found, throws an exception.createcreate an entity. If found, throw an exception.updateupdate an entity. If not found, throws an exception.searchretrieve a collection of entities by criteria. If nothing found, returns an empty collection.listingretrieve a collection of entities with no criteria. If nothing found, returns an empty collection.