Symfony Hexagonal Architecture Save

Example of a Symfony application using Domain-Driven Design (DDD) and Test Driver Development (TDD) principes keeping the code as simple as possible.

Project README

hexagon

๐Ÿ˜๐ŸŽฏ Hexagonal Architecture, DDD & TDD in Symfony

dahromy Symfony 5.4

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

  1. PHP 7.4 or higher;
  2. Composer
  3. PDO-MySQL PHP extension enabled;
  4. and the usual Symfony application requirements.
  5. NodeJS v14.*.
  6. Clone this project: git clone https://github.com/dahromy/symfony-hexagonal-architecture sf-hexa-example
  7. Move to the project folder: cd sf-hexa-example

๐Ÿ› ๏ธ Environment configuration

  1. Create a local environment file (cp .env .env.local) if you want to modify any parameter

๐Ÿ”ฅ Application execution

  1. Install the backend dependencies: composer install.
  2. Create database & tables with php bin/console d:d:c then php bin/console make:migration and php bin/console migration:migrate or force with php bin/console d:s:u -f
  3. Install the fronted dependencies: yarn install or npm install.
  4. For the development purpose, run yarn watch or npm run watch. For the production version, run yarn build or npm run build.
  5. 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, run php -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

  1. Install the dependencies if you haven't done it previously: composer install
  2. 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 :)

Open Source Agenda is not affiliated with "Symfony Hexagonal Architecture" Project. README Source: dahromy/symfony-hexagonal-architecture

Open Source Agenda Badge

Open Source Agenda Rating