Clean Architecture: Use different model classes for different data sources?

The overriding principle you should follow is separation of concerns.

The persistence layer should have classes that only deal with the storing and retrieval of data, in this case the Realm classes.

The network layer should have classes that deal with the data from the server, in this case the Retrofit classes.

Moving data from any of those layers to your business layers requires you to map the persistence and network objects to your domain.

To answer your first question, the mapping insulates goes around the different concerns, separating the domain from the data layers. The data layer should not know the domain models. The domain requests data from the data layer, the data layer gets the data and passes it through a mapper and thus returns the domain model.

To answer your second question, it would be a violation of the separation of concerns to have a generic model for your data layers if you get the data from different sources. The persistence models and the network models represent different parts of the system, and therefore should be represented by different models. The domain does not need to know this, so and data requested should therefore be mapped to domain objects before crossing the boundary back to the domain.


Adding to @Brian answer, probably you can add or encapsulate the Data layer as in the Clean Boilerplate suggests:

data layer with remote and local

This way you have a common Data model which is mapped to the domain model. I'm not really sure if this adds unnecessary code and layers, because then the data and domain models will probably look pretty much the same.