Answer the question
In order to leave comments, you need to log in
A project with complex logic in Symfony - how to design? Examples?
Hello!
NOTE: I immediately apologize for the long post .
I'm starting to design a new project that will:
* A lot of weird/complicated logic (like "when the fifth planet is in the Sirian phase on the sixth day from the seventh Wednesday after the 42nd week of a leap year, but only if that post is not older than weeks"), in which there can be more than one level of criteria for the state of something. However, the External API is a bit more complex than typical CRUD.
* Access levels for user groups (which can be created through the admin panel) down to every parameter of some business models. For example: "On this table, that column can only be seen by such and such groups of users."
* Many additional automatic actions when performing any action like "when changing the value in this cell of this table, do this, that, fifth, tenth and compote." Chains can be long and deep enough not to remember them without arming yourself with TK. Many of them should be deferred or asynchronous because they can be heavy.
* The main work is with external services via API, with duplication of some services at the level of business logic such as "If service1 fell off when performing an action, try services 2,3,...,100500 until it works, in such and such an order for such- then the criterion.
* Longevity of the project - and support, and finishing the logic, which cannot be foreseen now. For years.
* The project will be an API - no templates / layout / front are supposed to be there. More precisely, it will be, but a separate project, perhaps in Angular.
As a framework, I'm going to take Symfony - I haven't had a chance to work with it yet, but judging by their book, it seems that I won't need to struggle with it in this type of project.
More to the questions.
So that everything does not turn into very fat models - the repository is separate, the models are separate (Doctrine, I read it, it can - you don’t need to reinvent the wheel). How to store business logic so that models do not turn into monsters of tens of thousands of lines? I read about the Command Bus where, if I understood correctly, each action in the system has its own class? How do you organize them (there will be hundreds of them then)?
Does it make sense to take each domain model into a module/microservice , store all the related logic somewhere inside, and communicate with the rest via an external API? For answers to the client side - a separate front-end service? What is an overhead? Is this used in practice? What are the pitfalls?
Previously, for additional actions, it was enough for me to use something like beforeUpdate / afterCreatemodels. Now these methods run the risk of becoming gigantic and very complex, even if the logical pieces are taken out into separate methods. In addition, many of them will be placed in the task queue (in rabbitmq, for example) and processed asynchronously. But some don't, and in some cases the order in which the hooks are executed will be very important. How not to turn throwing/receiving events like PostBeforeEdit/PostBeforeEditHandler into "callback hell" ? In one similar project, I saw this (however, on js) - with each click, you never know how many dozens of actions will occur, even armed with a debugger. It would be nice to keep the config of such logic human-readable and in one place - how do you solve it?
ACL. Where do you store the specified logic? The grid is supposed to be stored in the database and cached. What are the structures for the above - best practice? In my understanding, it looks like a bunch of three-dimensional "crud - group - entity - field" access cubes, how to make it flatter so far only one idea is to make a bunch of many-to-many tables. But it seems to me that working with these "joins" on each request will be the second bottleneck after external api.
Versioning . How do you version projects like this? And if you need "N-1" working version in production? Now I store them in different git branches and deploy them separately. Does it make sense to separate versions within a single project codebase and how (namespaces, config, module, something else)?
And most importantly– how to combine all this? Separately, the above has already been applied in practice. But it doesn't fit in my head all at once. What projects (more precisely, on the code) can you advise to look at for a better understanding? Links to repositories ?
Thanks in advance to those who will master the long post, share their experience and, perhaps, send an example to the code of such a project.
Answer the question
In order to leave comments, you need to log in
How to store business logic so that models do not turn into monsters of tens of thousands of lines?
> a way to flatten the inheritance of groups like "manager can do everything that customer can do, but also this and that"? Is it more reasonable and more supported to duplicate all rights?
IMHO, all these troubles with the inheritance of groups are needed only for ease of administration. And their place is in the admin panel, not in groups. Make convenient editing of groups, with comparison with another group. Or templates that allow the user to apply several groups at once. Even more complex things like the fact that a group of managers cannot be applied in isolation from the customers.
But all this is not in groups, but in this section of the admin panel. Groups are assigned not as often as they are used. But for use they should be as simple as possible.
https://github.com/akeneo/pim-community-dev
https://github.com/Sylius/Sylius
https://github.com/orocrm
https://github.com/orocommerce
In order not to smear ACLs and not to increase the sizes of controllers to insane size, take a look at the aspects. https://github.com/goaop/goaop-symfony-bundle. Regarding the fact that you constantly have to pull some data and constantly recalculate them, etc., I advise you to look in the direction of the tarantula. Highly loaded services like Badoo and Mail.ru store user sessions and other hot information in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question