A Symfony project made with DDD, CQRS and Hexagonal Architecture

Last update: Aug 10, 2022

Symfony Blog DDD + CQRS + Hexagonal Architecture

A Symfony blog project made with CQRS, Hexagonal Architecture and DDD

Docker integration

This project has been created using the Symfony Docker repository.

Configuration

This projects use the LexikJWTAuthenticationBundle to provide JWT authentication so you need to:

Generate the SSL Keys:

$ php bin/console lexik:jwt:generate-keypair

Deploy

  1. If not already done, install Docker Compose
  2. In docker-compose.override.yml choose between dev or prod environment
  3. Run docker-compose build --pull --no-cache to build fresh images
  4. Run docker-compose up (the logs will be displayed in the current shell)
  5. Open https://localhost in your favorite web browser and accept the auto-generated TLS certificate
  6. Run docker-compose down --remove-orphans to stop the Docker containers.
  7. If you work on linux and cannot edit some of the project files right after the first installation, you can run docker-compose run --rm php chown -R $(id -u):$ (id -g) . to set yourself as owner of the project files that were created by the docker container.

Usage

This is an API project with authentication based in JWT token.

You can first register your user and then make a login request to get the JWT token. Then you can do the authenticated requests including this token in an Authorization header with Bearer format.

Comments

I have started from the symfony-ddd-cqrs-hexagonal-skeleton project (also implemented by myself) as a base that already provides me with some functions that I need, such as CQRS with Symfony Messenger, exception handling, serialization, validation.... .

I use named constructors in some classes to prevent Symfony include them as services and due to semantic reasons.

I use adr pattern in Controllers to preserve the Single Responsability principle in them.

I'm only testing Domain Entities behaviour, sorry, I'm not very experienced in testing for now.

Why only API is implemented? I think web side should not be in the same project. It's better to separate backend and frontend into two different projects. For now I'm not interested in frontend so this project is gonna be only Api.

Why Controller is creating the identifiers? Follow CQRS standard implies return no result in commands, but it's necessary return domain objects id's as the response in POST creation requests. So, I think is acceptable create a not-domain identifier in the controller, and let the command turn it into an appropiate Domain Id.

Why update methods are empty in ORM repositories? A repository should differentiate between creating and updating, regardless of the specific implementation (ORM, ODM, Api, Redis Client...). In the case of Doctrine, no action is required to update an entity, because it is already done when the flush method is called by the DoctrineTransactionMiddleware. However, I want to keep the update action in the repository, so if in the future it has to be changed to something else that doesn't work with Doctrine (API repository, for example), update calls are already done.

Why are you including a trailing slash in all your routes? The standard is to remove the trailing slash of all routes but recently I have experimented problems in other projects with Safari and the solution was add this trailing slash in my routes to evade Symfony redirection. This is fixed in last Safari updates but I am currently adding this slash to prevents old Safari clients can't request correctly.

Why are you using specification pattern with plain values? Standard Specification pattern uses the Domain entity (DE) to validate invariants, however, this is impossible to apply to validate DE invariants because I am following the Always-valid domain model and I can't pass an invalid DE to the specification. I could simply use if sentences in the DE, but I need to do the same validations as input validations in the Application Layer, so... I decided to use a little different Specifications to validate plain values. Also, I added a validation context (only used in Application Layer) to return valid error messages to the Presentation Layer.

GitHub

https://github.com/lcavero/blog-ddd-cqrs-ha-example
You might also like...

A DDD microservice did in laravel, to test infrastructure

A DDD microservice did in laravel, to test infrastructure

Jul 8, 2022

The game is implemented as an example of scalable and high load architecture combined with modern software development practices

The game is implemented as an example of scalable and high load architecture combined with modern software development practices

Crossword game The game is implemented as an example of scalable and high load architecture combined with modern software development practices Exampl

Jun 4, 2022

my personal example of Laravel clean architecture

what is this repo about Clean Architect Laravel ###run we assume docker desktop is up and running open up a terminal cd project directory run "cp .env

Aug 4, 2022

Detect flaws in your architecture, before they drag you down into the depths of dependency hell ...

Detect flaws in your architecture, before they drag you down into the depths of dependency hell ...

Detect flaws in your architecture before they drag you down into the depths of dependency hell ... What it does System Requirements Installation Phive

Aug 4, 2022

The Lucid Architecture for Scalable Laravel Applications.

The Lucid Architecture for Scalable Laravel Applications.

Website: https://lucidarch.dev Documentation: https://docs.lucidarch.dev Social: we share updates & interesting content from the web Twitter: @lucid_a

Aug 10, 2022

A research raw data repository for researchers of Arba Minch University built using Codeigniter which follows MVC architecture. The front-end is build using Bootstrap.

Arba Minch University Dataset Repository This system is a research dataset repository for Arba Minch University researchers and is build using Codeign

Jul 1, 2022

Simple Symfony API-Platform Template which you can use to start to develop with symfony and api-platform

symfony-api-platform-skeleton Simple Template for Symfony API You can fork it and change the git remote to your Repo git remote set-url your-git-remo

Jan 23, 2022

CaraCracha - a captive portal project made for ISPs on my old city

CaraCracha - a captive portal project made for ISPs on my old city, Sobradinho, state of Bahia, Brazil. I found its code recently and hope it could be useful for someone.

Mar 9, 2022

A project of a Login screen made in PHP/CSS3/HTML5/JS with MySQL database integration

A project of a Login screen made in PHP/CSS3/HTML5/JS with MySQL database integration

A project of a Login screen made in PHP/CSS3/HTML5/JS with MySQL database integration. And animations made with CSS3 and JavaScript itself! 😊

Apr 26, 2022
🐘 🎯 Hexagonal Architecture, DDD & CQRS in PHP
 🐘 🎯 Hexagonal Architecture, DDD & CQRS in PHP

?? ?? Hexagonal Architecture, DDD & CQRS in PHP Example of a PHP application using Domain-Driven Design (DDD) and Command Query Responsibility Segrega

Aug 16, 2022
Dockerise Symfony Application (Symfony 6 + Clean Architecture+ DDD+ CQRS + Docker + Xdebug + PHPUnit + Doctrine ORM + JWT Auth + Static analysis)

Symfony Dockerise Symfony Application Install Docker Install Docker Compose Docker PHP & Nginx Create Symfony Application Debugging Install Xdebug Con

Aug 12, 2022
Clean Architecture, DDD and CQRS using Symfony 6

Task manager system using Clean Architecture, DDD and CQRS. Environment setup Install Docker Clone the project: git clone https://github.com/k0t9i/Tas

Jul 31, 2022
Enraged Xenomorph - DDD/CQRS Symfony Application Boilerplate
Enraged Xenomorph - DDD/CQRS Symfony Application Boilerplate

Enraged Xenomorph - DDD/CQRS Symfony Application Boilerplate This project is very opinionated attempt to compile a bit of experience, few good practic

Jan 10, 2022
Orkestra is a library of infrastructure and architecture helpers for creating CQRS applications

Orkestra Orkestra is an opinionated framework with a plethora of recommendations on architectural design that we use internally at Morebec to develop

Aug 18, 2021
POC d'un projet Clean Architecture + DDD

Proof Of Concept - Clean Architecture & DDD Installation Dans un premier temps, cloner le repository : git clone https://github.com/TBoileau/rse cd rs

Jul 17, 2022
FFCMS 3 version core MVC architecture. Build-on use with ffcms main architecture builder.

FFCMS 3 version core MVC architecture. Build-on use with ffcms main architecture builder.

Feb 25, 2022
Demo project for the API Platform / DDD Workshop

Workshop DDD x API Platform This is a demo project used for the DDD x API Platform Workshop by @chalasr & @mtarld from @coopTilleuls. Checkout git clo

Aug 2, 2022
Small convention based CQRS library for PHP

LiteCQRS for PHP Small naming-convention based CQRS library for PHP (loosely based on LiteCQRS for C#) that relies on the MessageBus, Command, EventSo

Jun 7, 2022
PHP Lightweight Message Bus supporting CQRS.
PHP Lightweight Message Bus supporting CQRS.

Prooph Service Bus PHP 7.1+ lightweight message bus supporting CQRS and Micro Services Important This library will receive support until December 31,

Jun 7, 2022