Should our api-response-to-domain-entity transform functions be in the API/Infrastructure layer, or the Domain layer?
We have a react-native mobile application written in TypeScript. We have separated "layers" to, amongst other reasons, reduce dependency on outer layers by inner layers, inspired by various well-known software architectures e.g. "Onion". It does not comply exactly with above-mentioned architectures, but dependency between layers looks somewhat like this:
Infrastructure/API <- Services <- Domain/Entities -> Presenters -> UI Components
We are moving everything except UI to a shared library in a monorepo package, to share logic between the react-native application and a react web application. The UI component implementations are too different to be worth sharing.
In our domain layer, we have transformer functions that consume the response from the API/Infrastructure layer that satisfies an interface definition of what we expect from the API endpoint, and return a value that satisfies the interface definition of our Domain Entity.
The interface definition for the server API endpoint response is part of the API/Infrastructure layer's concern, so it is located there (infrastructure/
).
The interface definition for the Domain Entity is located in the Domain layer (domain/
).
I want to move the Domain layer modules and types to the shared library first, but the transform functions have to import the interface definitions from the API/Infrastructure layer. This feels like a tight coupling.
Should our api-response-to-domain-entity transform functions be in the API/Infrastructure layer, or the Domain layer?