symfony-hexagonal-architecture
symfony-hexagonal-architecture copied to clipboard
Example of a Symfony application using Domain-Driven Design (DDD) and Test Driver Development (TDD) principes keeping the code as simple as possible.
๐๐ฏ Hexagonal Architecture, DDD & TDD in Symfony
Example of a Symfony application using Domain-Driven Design (DDD) and
Test Driver Development (TDD) principes keeping the code as simple as possible.
Take a look, play and have fun with this.
Stars are welcome ๐
Report a bug
ยท
Request a feature
๐ Environment Setup
This project is made with Symfony 5.4.
๐ณ Needed tools
- PHP 7.4 or higher;
- Composer
- PDO-MySQL PHP extension enabled;
- and the usual Symfony application requirements.
- NodeJS v14.*.
- Clone this project:
git clone https://github.com/dahromy/symfony-hexagonal-architecture sf-hexa-example
- Move to the project folder:
cd sf-hexa-example
๐ ๏ธ Environment configuration
- Create a local environment file (
cp .env .env.local
) if you want to modify any parameter
๐ฅ Application execution
- Install the backend dependencies:
composer install
. - Create database & tables with
php bin/console d:d:c
thenphp bin/console make:migration
andphp bin/console migration:migrate
or force withphp bin/console d:s:u -f
- Install the fronted dependencies:
yarn install
ornpm install
. - For the development purpose, run
yarn watch
ornpm run watch
. For the production version, runyarn build
ornpm run build
. - Start the server with Symfony:
symfony serve
. Then access the application in your browser at the given URL (https://localhost:8000 by default). If you don't have the Symfony binary installed, runphp -S localhost:8000 -t public/
to use the built-in PHP web server or configure a web server like Apache to run the application.
โ Tests execution
- Install the dependencies if you haven't done it previously:
composer install
- Execute PHPUnit tests:
php bin/phpunit --configuration phpunit.xml.dist
๐ฏ Hexagonal Architecture
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 5 src
src
โโโ Application // The application layer of our app
โ โโโ Post // Inside the application layer all is structured by actions
โ โโโ Create
โ โโโ CreatePostCommand.php
โ โโโ CreatePostUseCase.php
โโโ Domain // The domain layer of our app
โ โโโ Post
โ โโโ Post.php // The Aggregate of the Module
โ โโโ Repository
โ โโโ PostRepositoryInterface.php // The `Interface` of the repository is inside Domain
โโโ Infrastructure // The layer infrastructure of our app
โ โโโ Controller
โ โโโ Persistence
โ โโโ Doctrine
โ โ โโโ Post
โ โ โโโ PostDoctrineParser.php
โ โ โโโ PostDoctrineRepository.php // An implementation of the repository
โ โ โโโ Post.php
โ โโโ InFile
โ โ โโโ FilesystemHandler.php
โ โ โโโ Post
โ โ โโโ InFilePostParser.php
โ โ โโโ InFilePostRepository.php
โ โโโ InMemory
โ โโโ Post
โ โโโ InMemoryPostRepository.php
โโโ Kernel.php
๐ค Contributing
There are some things missing (add some features: exception, ui, improve documentation...), feel free to add this if you want! If you want some guidelines feel free to contact us :)