What directory structure for my Laminas Project

Reading Time: 2 minutes
Explore the benefits of efficient module directory organization, including streamlined configurations, improved authentication and increased API versioning.
directory structure for laminas

Table of Contents

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. 

Share it on:

Twitter
LinkedIn
Facebook
WhatsApp

About the Author

Gary Gitton
Hello, I'm Gary Gitton - an accomplished Software Engineer, Tech Lead, specializing in PHP, API Engineering, DevOps, and Cloud Management. Throughout my career, I've had the privilege to enhance multiple software solutions with my expertise in multiple languages and platforms. I bring my unique blend of technical and business acumen to every project, ensuring efficient, scalable, and innovative outcomes. I'm also passionate about fostering a culture of continuous learning, mentoring developers, and leading projects with agile methodologies. Whether concocting a bespoke API or orchestrating cloud environments, I'm committed to delivering quality and excellence. Let's connect and transform your vision into a digital reality.

You might also like