Beyond fat models

Fat models paradigm does not scale well, especially if a model is at the same time an ActiveRecord. I was planning to move domain logic to separate, well-defined and framework agnostic service classes, with all dependencies explicitly given in the constructor. What are your thoughts? How do you split up the MVC pattern?

Our project is a very big and old web application.

That is a good way to go. Add “services” to your application (often these are called components) and call these from within controller to perform parts of the the actions you do. Change arrays to value objects. Optionally introduce DTO and wrap getting data into repositories.

Views are OK as is. Controllers are OK as entry point but you should keep business logic out of them.

Thanks for the feedback! Right now I’ve put “services” folder inside models/, since business logic sometimes is considered “part of the model layer”, but yeah, each framework has its own definition of “model”.

Would love to use DTO and value object more, just have to convince the team. :wink:

Good luck with it.