DEV Community

loading...

Where to put the business logic ?

Rami Gamal
A Self-Taught programmer that interested in web development ( front-end AND back-end)
・1 min read

I am writing a web application using PHP without using any framework 'just for learning'.
My app consists of a small routing system, MVC components, some entities that represents the database tables and repository classes that deals with the database.
The controller crate a repository object and that object load its entities from the database then return it as an array to the controller and the controller render the data.
What is the right place to put the domain or business logic,
in the models or repositories

View > Controller > Model > Repository > Database
View < Controller < Model < Repository < Database

Discussion (3)

Collapse
steelwolf180 profile image
Max Ong Zong Bao • Edited

If you follow the MVC model and it is a small app. You could go for fat models and thin views approach by putting your business logic into the model.

Collapse
ramigaml84 profile image
Rami Gamal Author

That's not my intent, my intent to put every thing in the right place.
It's not a real application it's just for learning.
Thank you :)

Collapse
steelwolf180 profile image
Max Ong Zong Bao

There's not right or not it just depends on what is the use case you are solving.