laravel-ddd-example icon indicating copy to clipboard operation
laravel-ddd-example copied to clipboard

Hexagonal Architecture + DDD + CQRS in PHP using Laravel 8

Hexagonal Architecture, DDD & CQRS in Laravel PHP

Laravel 8 PHP PhpStorm Docker MySql CircleCI GithubActions

This is a monorepo containing a PHP application using Domain-Driven Design (DDD) and Command Query Responsibility Segregation (CQRS) principles. It also has a front in Vue.js and Nuxt.js (TBD).

It's a basic implementation of a Kanban manager (at this moment, just only manages Board entity; not columns or tasks)

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:

composer build
composer migrate

and run containers:

composer up

Then you'll have 2 apps available (1 API and 1 Frontend):

  1. Kanban API: http://localhost:8080/api/v1/kanban/health-check
  2. Kanban Frontend: TBD

Tests

Execute all test suites: composer 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).

The main idea is to use this as our pure code, with no vendor

Bounded contexts

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

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

CQRS

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

References