M
M
motomac2021-08-19 15:41:50
Software design
motomac, 2021-08-19 15:41:50

How to organize code reuse in two Laravel projects?

The task is to write a backend for a site that works in two different countries. 90% of them are identical, but 10% are some regional specifics. Now the backends work as two independent repositories (one fork of the other). There is no code reuse, and they spread farther and farther apart, or you have to do double work each time to roll out the same functionality.

I don’t want to fall from one hole to another in the process of rewriting, so I ask for advice on how best to organize code reuse, while maintaining the overall architecture and rules, but leaving room for local maneuvers.

Several options come to mind:

  1. One repository - one server, one database. There is a problem with the potential impossibility of customization. The code must 100% meet the requirements of both businesses;
  2. One repository - two servers. There is some customization with configs, but in general the same;
  3. Two repositories - two servers. Take out the total in packages.

The last option seems to be the most promising. But it is easy in words, harder in practice. What to put in packages and by what criteria? The main models, controllers, routes, events, listeners, and locally inherited from them? What about migrations?

Then, since the main work is common for both projects, then these common packages will be updated mainly. Those. every push to this shared repository should trigger a deploy of both sites followed by a `composer update`?

Share experience who did something similar.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vism, 2021-08-19
@vism

With other unknowns, I think the optimal is usually

One repository - two servers. There is some customization with configs, but in general the same;

It's stupid in the right places to check through if. Cheap and cheerful, and maybe more will not be needed.
But of course, the specifics can also be taken into account in the database, formulas.
Because conditionally, the tax is not calculated through if, but to have a rate in the database or configs, but substitute it as a variable.
update
https://tenancyforlaravel.com/
here, I use this thing.

K
Konstantin B., 2021-08-19
@Kostik_1993

No one will advise you anything, because no one has before their eyes what you have. The choice is yours to make based on your experience with the project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question