The next project is a code example for a Blog project based on Action-Domain-Responder and Symfony 4.
In order to get the project working:
- Clone the repository
- Execute
composer install
- Configure the database access in your
.env
file - Create the database:
bin/console doctrine:database:create
- Run Migrations:
bin/console doctrine:migration:migrate
- You can import the Postman Collection file on
postman/ADR-Blog.postman_collection.json
The project has the next structure:
src
|__ Action
| |__ Author
| |__ Post
|
|__ Domain
| |__ Entity
| |__ Module
| | |__ Author
| | | |__ Application
| | | | |__ CreateAuthor
| | | | |__ DeleteAuthor
| | | | |__ GetAuthor
| | | | |__ GetAuthors
| | | |
| | | |__ Domain
| | | |__ Infratructure
| | |
| | |__ Post
| | |__ Application
| | | |__ CreatePost
| | | |__ DeletePost
| | | |__ GetPost
| | | |__ GetPosts
| | |
| | |__ Domain
| | |__ Infratructure
| |
| |__ Shared
| |__ Http
| |__ Uuid
|
|__ Migrations
|__ Responder
Here we have the endpoints which allow us to perform some actions in the blog, like:
- List posts paginated
- Get a single post
- Delete a post
- Create a new post
In this directory we can found the two modules that the application is composed. Each module has exactly 3 folders:
- Application: Contains all the use cases
- Domain: Contains all the the interfaces needed to allow the talk between application and infrastructure
- Infrastructure: Contains all the concrete implementations of the domain contracts
Here we can als found two more directories:
- Entities: Where we store our models
- Shared: Where we store interfaces and classes of shared use, like exceptions or checkers.
Last but not least important, in the responder folder we can found all the classes that handle the responses.
If you want to play with the code and add your self actions, it's very easy! Take for example the case you want add an edit author action:
You just need to:
- Create your action (in the
Action\Author
folder) - Create your use case (in the
Domain\Module\Author\Application\EditAuthor
) - Think if you need an ad-hoc responder or you can use an existent (for this case, the
ResourceResponder
will do the job) - Register the route for your action in
config/routes/author.yml
That's all!