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:
src
├── api
│   └── files
│   ├── file.controller.ts
│   ├── file.repository.ts
│   ├── file.router.ts
│   └── file.service.ts
└── index.ts
src
├── api
│   └── files
│   ├── file.controller.ts
│   ├── file.repository.ts
│   ├── file.router.ts
│   └── file.service.ts
└── index.ts
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Joao
Joao2y ago
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.
src
├── entities
│ └── file.entity.ts
├── index.ts
├── repositories
│ ├── file.repository.ts
│ └── fs.repository.ts
└── services
└── createFile
│ ├── createFile.controller.ts
│ ├── createFile.dto.ts
│ ├── createFile.service.ts
│ ├── createFile.validators.ts
│ └── index.ts
├── readFile
├── updateFile
└── ...
src
├── entities
│ └── file.entity.ts
├── index.ts
├── repositories
│ ├── file.repository.ts
│ └── fs.repository.ts
└── services
└── createFile
│ ├── createFile.controller.ts
│ ├── createFile.dto.ts
│ ├── createFile.service.ts
│ ├── createFile.validators.ts
│ └── index.ts
├── readFile
├── updateFile
└── ...
It seems to be coming together rather nicely this way, but I appreciate any feedback on this