Albertobeiz

Albertobeiz

Symfony Tips #14 - Separate your application in modules

Symfony Tips #14 - Separate your application in modules

Subscribe to my newsletter and never miss my upcoming articles

🖥 Symfony Tips: Quick and practical tricks to develop solid backend systems.

What if your app keeps growing and growing? Then it can be a good idea to split it into modules.

This is OK

Captura de pantalla 2021-05-19 a las 15.41.42.png

This is better

Captura de pantalla 2021-05-19 a las 15.42.26.png

How?

First change the top level folder and update services.yaml

Captura de pantalla 2021-05-19 a las 15.47.22.png

Then move your entities and change doctrine.yaml

Captura de pantalla 2021-05-19 a las 15.49.46.png

Finally move Repositories and update all namespaces.

Now we have our module divides in Domain, where our entities live, Aplication for our Use Cases and Infrastructure for our external services (like the database)

Why?

Now each module can grow independently and maybe even extract it to an external service.

You can run php ./vendor/bin/phpunit to run the tests.

Symfony tip completed 👍! Check the final code and leave a ⭐️!

Next Tip -> Symfony Tips #15 - Dispatch Domain Events

Previous Tip -> Symfony Tips #13 - Do validation in your setters

HEY! Follow me at @albertobeiz if you found this tip useful or have any question

 
Share this