I want to create an Express REST API and want to try following the clean architecture ideas. I was reading about it but didn't get the idea of the communication between the abstraction layers.
Let's say I have this structure
routes => controllers (sending the response) => use cases (bundling all the logic) => repositories (fetching data from the database) => database queries
I read about object mappers creating models to communicate between the layers. But when I'm thinking about complex objects with many optional fields I might come up with this case:
I want to create a new user when calling POST /users
and have to pass in a username and a password and might pass in multiple optional fields. When creating a UserEntity
/ UserModel
, should I setup nullable fields for every optional field? And when I want to return the created database user I have to create a model again by mapping all those properties.
I think this might get really messy if your models expect many constructor parameters. And things might get even more messy if your database model differs from the response model being sent to the client.
Would you mind explaining a clean communication flow when passing in data from the controller all the way down to the database and returning it all the way up back to the controller to send the response to the client?