I am asking you who know well and have experience in building a software using any layered architecture (onion, hexagonal, clean, etc.). Whenever I google about the software architecture, people have different perspectives and explain the same architecture in a different way.
TERMS
Before you read the question, some terms might confuse you, so I am defining them below. I am not sure if I have the 'right' definitions for them, but I gathered these information from the internet. Let me know if I am misunderstanding.
Domain Layer: contains enterprise/business logic and uses domain model. located at the center and does not depend on any other layers except the domain model.
Application Layer: contains application logic, accepts DTO from the infrastructure layer, and transfer View Model
DTO (Data Transfer Object): a class, JSON string, etc. used for transferring data between layers in and out. may be a pure data container.
VM (View Model): a DTO that is passed to the presentation layer from the application layer.
DO (Domain Model): a class, JSON string, etc. used in domain layer. may be a pure data container.
VO (Value Object): database entity (a database row), or a data format that the database uses. can be transferred to the application layer from the database layer.
SUMMARY
In onion, hexagonal, or clean architecture, the domain layer is in the center (i.e. the domain layer does not depend on any layers other than the domain model which is used for transferring data to other layer or accepting data from the higher layer).
This means the domain model (DTO, POJO, VO, or whatever) that the domain uses might be different from the model that the database(s) use for saving persistent data.
I drew a diagram so that I can give you better explanation.
Q1:
Please look at the red parts of the second image.
If the domain layer is in the center unlike the traditional layered or n-tier architecture, can the domain model have more properties (or different properties) than the database entity (row)?
For example, assume that the domain layer uses a class called Person. The user requests the pictures of all people registered in the server. Let us assume that the database contains only the names of all people. However, we may use other web server to request a picture of a person by the name. So the application layer will read all the names from the database, and with those names, it will get all the pictures from the other web server through a HTTP request. After that, the list of the Person with a name and a picture will be sent to the user as a view model (DTO).
Q2:
The persistence layer may be consisted of a database, file system, other web API, etc.
The presentation layer layer may be a website, desktop app, mobile app, web API, etc.
Both of the layers are part of infrastructure layer and depends on the application layer, but the application layer only depends on the domain layer.
When the application layer is accepting a request from the presentation layer, there is no problem because the presentation layer calls the application layer and the presentation layer knows the application layer.
In most of the time, the application layer needs to get a data from the persistence layer.
There is no way that the application layer can call the persistence layer without having any dependency, because it does not know any classes in the persistence layer.
This is how I am understanding so far, can someone give me a clear explanation how the data should flow and how the communication is done from the lower layer to the higher layer?
For those who want to write code, I prefer C#.