DEV Community

Discussion on: Layered Architecture Clarification

Collapse
 
amrelmohamady profile image
Amr Elmohamady

I would also add a validation layer before the controller to validate the request body. But I don't get why the repo layer when you are using an orm it just adds extra complexity, why not services just deal with the orm directly

Collapse
 
lazypro profile image
ChunTing Wu

For a simple application, it is feasible to use ORM instead of Repository. However, in an enterprise application, the domain object is not one-to-one mapping to a table or some rows. A domain object is composed of many data, and there are rich constraints between the data. This is also called Impedance Mismatch.

In order to solve the mismatch, we usually introduce a Repository between the domain layer and storage layer. Repository is not only responsible for accessing the data but also ensure the data constraints.