The module directory
The good way
module/
- ProductA/
- Billing/
- Money/
- Geo/
The bad way
module/
- ProductA/
- - src/
- - - Billing/
- - - Money/
- - - Geo/
Advantage of doing the good way:
- We can use multiple doctrine entity manager with consistent and simple configuration
- Launching test module in parallele and loading only the code needed for the module.
- We can setup different type of authentication by module as it’s already done (admin: use http basic authentication, shipping use token authentication)
- Possibility to use the shared service manager
- We can increase API version (with laminas api tool) module by module
- We can use one entity manager by module
Product module architecture
Now let’s assume that the ProductA we talked about before is a Blog. This is how I would organise my module.
Blog/
- src/
- - Application/
- - - Command/
- - - - Handler/
- - - - - CreateArticleHandler.php
- - - - CreateArticleCommand.php
- - - Exception/
- - - - BlogNotFoundException.php
- - - Query/
- - - - Handler/
- - - - - GetTrendingPostHandler.php
- - - - GetTrendingPostQuery.php
- - - Service/
- - - - BlogService.php
- - Domain/
- - - Error/
- - - - ArticleUnknown.php
- - - - BlogNotUnknown.php
- - - Article.php
- - - Blog.php
- - Infrastructure/
- - - Doctrine/
- - - - Type/
- - - - - BlogIdType.php
- - - Exception/
- - - - ArticleNotFoundException.php
- - - Filter/
- - - Validator/
- - - Repository/
- - - - BlogRepository.php
- - - Resource/
- - - - ContentFull/
- - - - - ListArticleResource.php
- - V1/
- - - Rpc/
- - - - CreatePost/
- - - - - CreatePostController.php
- - - - - CreatePostControllerFactory.php
- - Module.php
- - ConfigProvider.php
- test/
- - Double/
- - - Infrastructure/
- - - - InMemoryBlogRepository.php
- - Unit/
- - Integration/
Instead of V1, we should get Presentation but as we use Laminas API Tools to generate the controllers, we don’t have much choice on the structure.