Librarify is a PHP application using Domain-Driven Design (DDD) and Command Query Responsibility Segregation (CQRS) principles keeping the code as simple as possible.
- Install Docker
- Clone this project:
git clone https://github.com/serodas/librarify-php-ddd.git
- Move to the project folder:
cd librarify-php-ddd
- Create a local environment file (
cp .env .env.local
) if you want to modify any parameter
- Install all the dependencies and bring up the project with Docker executing:
make build
- Then you'll have 2 apps available (2 APIs):
Note: If you are using Rest Client extension in VSCode, you can use the provided requests in the etc/endpoints
folder to test the API endpoints.
- Install the dependencies if you haven't done it previously:
make deps
- Execute PHPUnit and Behat tests:
make test
This project tries to be a library platform. It's decoupled from any framework, but it has some Symfony implementation.
-
Librarify: Place to look in if you wanna see some code 🙂. Library platform with books, authors, categories, and so on.
-
Backoffice: Here you will find a projection of books stored in Elasticsearch.
This repository follows the Hexagonal Architecture pattern. Also, it's structured using modules
.
With this, we can see that the current structure of a Bounded Context is:
$ tree -L 4 src
src
|-- Librarify // Company subdomain / Bounded Context: Features related to one of the company business lines / products
| `-- Books // Some Module inside the Librarify context
| |-- Application
| | |-- Create // Inside the application layer all is structured by actions
| | | |-- BookCreator.php
| | | |-- CreateBookCommand.php
| | | `-- CreateBookCommandHandler.php
| | `-- Find
| |-- Domain
| | |-- Book.php // The Aggregate of the Module
| | |-- BookCreatedDomainEvent.php // A Domain Event
| | |-- BookDescription.php
| | |-- BookNotFound.php
| | |-- BookRepository.php // The `Interface` of the repository is inside Domain
| | |-- BookScore.php
| | `-- BookTitle.php
| `-- Infrastructure // The infrastructure of our module
| |-- DependencyInjection
| `-- Persistence
| `--DoctrineBookRepository.php // An implementation of the repository
`-- Shared // Shared Kernel: Common infrastructure and domain shared between the different Bounded Contexts
|-- Domain
`-- Infrastructure
Our repositories try to be as simple as possible usually only containing 2 methods search
and save
.
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 1 implementations of the command bus.
- Sync using the Symfony Message Bus
The Query Bus uses the Symfony Message Bus.
The Event Bus uses the Symfony Message Bus. The MySql Bus uses a MySql+Pulling as a bus. The RabbitMQ Bus uses RabbitMQ C extension.
Based on course DDD in PHP by CodelyTV