Large Scale Laravel Application

Dividing the whole application into smaller parts where each part has its own files and folders like the app/ folder, and loaded via composer.json autoload, like the following -|- auth/ |- Exceptions/ |- Http/ |- Listeners/ |- Models/ |- Presenters/ |- Providers/ |- Repositories/ |- Services/ |- Transformers/ |- Validators/|- merchant/ |- Console/ |- Events/ |- Exceptions/ |- Http/ |- Jobs/ |- Listeners/ |- Models/ |- Presenters/ |- Providers/ |- Repositories/ |- Services/ |- Transformers/ |- Validators/|- database/ |- factories/ |- migrations/ |- seeders|- config/|- routes/|- resources/ |- assets/ |- lang/ |- views/But HMVC adds more complexity and when we want to move a particular module into a microservice; we still need to keep the controllers, middlewares the main codebase..Most of the time, moving to microservice requires to redefine the routes and controllers..Thus, we have to do redundant works..So I am not a big fan of this structure..Because,vI want to separate only what I (must) have to separate not anything more.Domain Driven Design can be a solutionThere is no perfect solution..Everything has a trade-off..But everyone has a preference..I am not going to discuss about Domain Driven Design (DDD) here..Developerul DeLaUnu wrote a great description about DDD in here.In my perspective, DDD (could) structures your Laravel application into 4 parts (or 3 … see how) -Application — usually holds, Controller, Middleware, RouteDomain — usually holds business logic (Model, Repository, Transformer, Policy etc.)Infrastructure —usually holds common services like Logging, Email etc.Interface —usually holds views, lang, assets.If it is this easy then why don’t we structure our application like this and use Namespace ?|- app/ |- Http/ (Application) |- Controllers/ |- Middleware/|- Domain/ |- Models/ |- Repositories/ |- Presenters/ |- Transformers/ |- Validators/ |- Services/|- Infrastructure/ |- Console/ |- Exceptions/ |- Providers/ |- Events/ |- Jobs/ |- Listeners/|- resources/ (Interface) |- assets/ |- lang/ |- views/|- routes/ |- api.php |- web.phpBecause, dividing the project into folders is not going to work..It just means we are adding nothing but a parent Namespace.Moment of truthBy this time you are probably already annoyed and just want to see the solution..So, here it is -|- app/ |- Http/ |- Controllers/ |- Middleware/ |- Providers/ |- Account/ |- Console/ |- Exceptions/ |- Events/ |- Jobs/ |- Listeners/ |- Models/ |- User.php |- Role.php |- Permission.php |- Repositories/ |- Presenters/ |- Transformers/ |- Validators/ |- Auth.php |- Acl.php |- Merchant/ |- Payment/ |- Invoice/|- resources/|- routes/The Auth.phpand Acl.php are the service files inside the app/Account/ folder.. More details

Leave a Reply