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
This project is made with Symfony 5.4.
- 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
- Create a local environment file (
cp .env .env.local
) if you want to modify any parameter
- 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.
- Install the dependencies if you haven't done it previously:
composer install
- Execute PHPUnit tests:
php bin/phpunit --configuration phpunit.xml.dist
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
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 :)