spring-boot-clean-architecture-demo icon indicating copy to clipboard operation
spring-boot-clean-architecture-demo copied to clipboard

A side note on the domain and use-cases layers

Open KostiaPerehuda opened this issue 1 year ago • 0 comments

Just wanted to leave a note about the two layers. As written in the description, domain layer only cares about business logic, it represents business entities as classes that encapsulate the entities' state and behavior on that state. And use-cases layer (also called application layer) is responsible for coordinating all that business logic, use-cases here are the public interface of that layer. My point here is that details like persisting something into a database or fetching some other data from some service are really concerns of the application layer, they are a part of the application logic. Domain doesn't care about them. Also note that entities that you persist into the database need not map one-to-one to the domain entities. So really the DummyRepository interface should not be the part of the domain layer, it should go into the use-case layer. Also note that you have a default constructor in Dummy with a comment that it is required for JPA, so in the example the domain layer is kind of aware of infrastructure layer, which should not be the case. The solution for this would be to disconnect the entities in the domain from the entities that you persist and map between them in the use-cases layer.

To the users of this template, not that in simple to medium size projects there is almost no domain logic at all, so it makes sense to combine the two layers into one (called "operation script" approach) an example might be a simple CRUD based application for storing online articles. And generally such "clean architecture approach" is suitable for big scale application, where you have separate teams working on different parts of it. But for simpler projects, don't be afraid to deviate here and there from this model.

KostiaPerehuda avatar Apr 11 '23 10:04 KostiaPerehuda