We all know right now Laravel is the most popular PHP framework. The directory structure is great, well organized, defined and straight-forward. Working in the default project structure provided by Laravel website development services are absolutely fine when we are working in a small or medium sized project. But, when it is a large application with more than 50 models, that is the time we start to choke on our own code base. Maintaining a large application is no joke. Especially when it is not organized properly. And the default structure of Laravel is definitely not very helpful for this scenario. But first, let’s revise how we can manage a Laravel application when does the problem appears.
There is nothing wrong with the structure. But when we work in a large application we used to divide our business logic into Repositories, Transformers etc.
The problem is not in navigating different folders but in maintaining the code and inter-communication among the services.
Lets analyze the code base and see what we can find –
- It is aMonolith application
- It is hard (for some developers) toMaintain
- Productivityis low (need to think about inter-connection all the time)
- Scalingis an issue
The solution is obvious- Microservice. Although we are using SOA (Service Oriented Architecture), we still will have to break our monolith application into smaller independent parts to scale them separately.
Awesome, we have a solution. Then why don’t we just do it? Break the code into smaller parts. It is obviously easier to say than doing it!
Usually separating a service requires two simple steps-
- Move the service children (Models, Repositories, Transformers etc.) into a new smaller PHP microservice application.
- Re-factor the service function calls to redirect the target to the microservice (eg. create HTTP request).
But now you need to find all the files related to that service. And surprisingly, you may find out that you have used its models or repositories somewhere else in the code by bypassing the service (I did this in the past). But this is not the only problem, there is more.