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