API layered architecture
Hi, I'm trying to apply the concepts of a layered architecture on a file upload API. Currently I have a folder structure that resembles this:
Inside
file.repository.ts
will be all functionality related to talking to the database. However, I intend to save the uploaded files on the server instead of using a 3rd party service for this, mainly for practice purposes. The question then is, where would this functionality (reading from and writing to disk) live? Inside services? Repository? Or should I create a whole new domain (maybe called io
or something) just for this?
Cheers!2 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Thanks for the suggestion, I've finally decided to do something very close to that. I decoupled the repositories from all domains, so that they are accessible throughout the app. I'll have one repository to talk to the database and store information about the file: location, size, etc., and another for the file system responsible for actually reading/writing as needed. Then a services folder where each service represents a unique action, or use case: create a file, delete it, etc, managing it's own controller, validation, etc.
It seems to be coming together rather nicely this way, but I appreciate any feedback on this