Overview
We built the API with Symfony 5, TDBM, and GraphQLite.
The API is the backbone of the boilerplate:
- It centralizes most of the logic (use cases, validations, access control).
- Most of the data from and to the browser and other services transit through it.
Architecture#
The API's source code architecture is quite close to other architectures like Clean Architecture, but with shortcuts to simplify it.
On the contrary to a classic MVC architecture, the API's architecture will help you with:
- Testing.
- Separation of concerns.
- Composition.
We separate the source code into three namespaces:
App\Domain.App\UseCase.App\Infrastructure.
note
📣 The boilerplate provides the Deptrac tool to enforce where you should put your classes. More on that subject in the Static Analysis chapter.
Domain#
The App\Domain namespace is where you'll find:
- Your
Models(from the database, from the storage, etc.) - Your
DAOs, yourStorages. - Your
Enumerators. - Your base
Throwables.
note
📣 The App\Domain namespace can only call classes from its namespace.
UseCase#
The App\UseCase namespace is where you'll find your... uses cases! 😁
What's a use case?
Let's say you want to create a User and send a reset password email.
You'll create two classes:
- src/api/src/UseCase/User/CreateUser.php
- src/api/src/UseCase/User/ResetPassword/ResetPassword.php
Why two? Because of composition!
Indeed, your ResetPassword use case might be useful for another scenario.
In your CreateUser use case, you'll write the logic for creating a user and saving it in the database.
Then you'll call your ResetPassword use case.
note
📣 While developing, it's essential to think use case first.
note
📣 The use cases are also our GraphQL endpoints. See the GraphQL guide.
note
📣 The App\Usecase namespace can only call classes from its namespace and the App\Domain namespace.
Infrastructure#
The App\Infrastructure namespace is where you'll find any other classes.
For instance:
- Your REST controllers.
- Your Symfony Commands.
- Etc.
note
📣 The App\Infrastructure namespace can call classes from all namespaces.