Infrastructure Layer
This infrastructure layer deals with the APIs, databases and other infrastructure-related dependency integrations in the system.
Data Source
A Data Source
represents a remote or local data storage within the system, such as a Database, Rest API or local files. They accept and return data in the form of Models
which are specific to the Data Source
.
Models
A Model
, also referred to as a Data Transfer Object (DTO), is a data representation for a particular Data Source
. They are translated into Entities to make them comprehensible to the application. Alternatively, Entities
are converted into Models
when it needs to be processed by the target Data Source
.
Repository (Implementation)
The Repository Implementation
provides the logic implementation for the Repository Interface, which defines the functions and capabilities of a specific data repository. It is responsible for managing the data and ensuring that it is properly formatted and structured for use in the application.
Among its main tasks is to manage the in-flow and out-flow of data between Data Source
and the application, ensuring that the Data Source Models
are converted into Entities and vice-versa, and every exception encountered is converted into their respective Failure objects.
Why do we need to convert Models
into Entities
and Exceptions
into Failures
?
Essentially, this is to decouple the Presentation Layer from the Infrastructure Layer.
This helps to ensure that the Presentation Layer
is independent of the specifics of the Infrastructure Layer
, making the application more flexible and adaptable to change.
For example, if we need to make changes to the Infrastructure Layer
, such as switching from one database to another, the data models and exceptions provided by the new database may change. By converting these models and exceptions into Entities
and Failures
, respectively, we can ensure that these changes are contained within the Infrastructure Layer
and do not affect the Presentation Layer
.
Last updated