Skip to content

Hexagonal Architecture + DDD + CQRS in PHP using Laravel 8

Notifications You must be signed in to change notification settings

mguinea/laravel-ddd-example

Repository files navigation

Hexagonal Architecture, DDD & CQRS in Laravel PHP

Laravel 8 PHP Docker MySql Terraform CircleCI GithubActions

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

CI pipeline status

Installation

Requirements

Environment

  • Clone this project: git clone https://github.com/mguinea/laravel-ddd-example laravel-ddd-example
  • Move to the project folder: cd laravel-ddd-example

Execution

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):

API Documentation

Open API documentation here

Postman API collection here

Tests

Execute all test suites: make tests

Project structure and explanation

Root Folders

apps

Here are our implementations of the code we have in our base (src). Here can be any framework, etc...

etc

etc is for "Editable Text Configurations". So here we can put any configuration by xml, yaml etc... like Docker setup.

src

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).

Bounded contexts

Kanban: Place where the main functionality is implemented. Management of boards...

Architecture and Structure

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

Repositories

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).

CQRS

Symfony Messenger has been used to implement commands, queries and events.

Infrastructure

RabbitMQ

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.

References