What should be the architecture of an application without ActiveRecord in Yii2?

Here we hastily created a project on the AR (ActeveRecord) requests through it, write, and update. To start a new project, I think this is quite the rules, if that project might not take off.

But the project lives model AR swell logic. Growing base, with it the volume of information being processed. And you have to wonder how the logic out of AR (behaviors, AfterSave, BeforeSave) in the first place, so it can be used with batchInsert and batchUpdate.

A slight digression, regarding logic, examples:
  • Changed the order status, to send notifications to a mail, telegram, etc. To record the history of changes in the amount of the order, status.
  • Update/delete the cache or update the index in elasticSearch
  • Send to moderation data
  • And everything


---
Any idea what all this must be put in handlers and events, such as what the class is engaged in processing of changed data (compare old data with new) and generates events, and perform actions on events have to be processed somewhere in the queue separately, so the current task batchInsert and batchUpdate in a few thousand records is not hindered.

But how it should look like architecturally, what are the nuances and pitfalls?

I think I'm not the first who asked this question, and there are already some architectural decisions.

I would like to see some examples, because it's all simply create a service, add the repository, in the same observers. But in practice, no experience is not just
March 23rd 20 at 19:25
2 answers
March 23rd 20 at 19:27
The application business logic in components that implement controllers and models should be as thin as possible. In the models only the logic of this behavior in the form of a timestamp, slug,...
But how it looks in practice, here is a direct example.
The user edits the data store or the customer canceled the order or administrative order repealed, the cost of ordering has changed. Each of these actions has its own logic, every action a few events for other objects. And as all this is taking architectural code?

That is, under every action necessary individual components/services to do or one service handles the editing of a single object. For admin and for user two services or one - as the logic may also vary.
If one POST request you are editing multiple objects, one can use the two services for different objects or from the controller is the management services or a single service works with other services.

When you add an item, you need to store, assign type and status, it is a separate service should do or this or that, which deals with the editing of the store.

I think it is clear, bunch of questions, just due to inexperience, and some sort of decent example on github would be very helpful. - Darien.Schamberger commented on March 23rd 20 at 19:30
@Darien.Schamberger, separate actions in the system, the process data change. Components BL can be independent, can even inherit from each other. Ideally, the controller is the entry point where the incoming request is filtered and, if successful, transformirovalsya in a format suitable for the components of BL. So you can reuse them.

Read about SOLID. It isn't just for code - Dasia.Powlowski commented on March 23rd 20 at 19:33
The stats for answer?
Your abstract answers are useless, in the question where you ask about the practice - Darien.Schamberger commented on March 23rd 20 at 19:36
@Darien.Schamberger, any normal practice based on theory. Can't believe what I ran and didn't appreciate) so, I corrected and recommend to others - Dasia.Powlowski commented on March 23rd 20 at 19:39
Anemic model anti-pattern. - Marshall_Koe commented on March 23rd 20 at 19:42
@Darien.Schamberger, Pathetic attempts to do something nice in practice, not by reading theory is also useless.
You are very naive to believe that someone in the toaster will teach you programming. - Marshall_Koe commented on March 23rd 20 at 19:45
@Marshall_Koe, an anemic model is not considered an anti-pattern, but actually this is a very interesting design pattern. Just does not work with all cases - Dasia.Powlowski commented on March 23rd 20 at 19:48
@Dasia.Powlowski, an Anemic model is not considered antipatterns mostly those who do not know how to design the model so that there are 20 fields did not appear.
Else if only in very specific cases, which the author does not need - Marshall_Koe commented on March 23rd 20 at 19:51
@Marshall_Koe, stay on your opinion. The number of fields does not apply to design patterns, and one or the other approach depends on the project - Dasia.Powlowski commented on March 23rd 20 at 19:54
March 23rd 20 at 19:29
The business logic better to make a services. Every service needs to do some its tasks. For example, one works with orders, the other sends notifications. How the service will be General or specific, on the contrary, you decide. Services can be linked inheritance, aggregation, composition (listed in order from strong ties to weak). Not to worry, you can apply a ready-made design templates.

Changed the order status, to send notifications to a mail, telegram, etc. To record the history of changes in the amount of the order, status.

This begs the application of the design pattern Observer. Status change an event is generated that get all the subscribers.

Update/delete the cache or update the index in elasticSearch

Here I would have thought of using the Decorator pattern

I think I'm not the first who asked this question, and there are already some architectural solutions

Yes, the generic solution is already there, you just need to study and practice for their tasks

I would like to see some examples, because it's all simply create a service, add the repository, in the same observers

On account of projects not know, you can probably just look on github are interested in. The use of patterns with examples well described here https://refactoring.guru/ru/design-patterns/catalog
Anemic model anti-pattern. - Marshall_Koe commented on March 23rd 20 at 19:32

Find more questions by tags Patterns of designingOOPPHP