This is an example of vertical slicing architecture for rest api using nodejs and typescript https://markhneedham.com/blog/2012/02/20/coding-packaging-by-vertical-slice/. Comparing to horizontal slicing (layered architecture) it has less model code gap - easy to understand modeled domain. Implementation also aligned with rules of Clean Architecture by Uncle Bob https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
Application provides API for user to view, create todos with image attachments,
todo-api
├─ package.json
├─ src
│ ├─modules (components)
│ │ ├─ todos
│ │ │ ├─ tests
│ │ │ ├─ repository
│ │ │ ├─ routes
│ │ │ ├─ controllers
│ │ │ ├─ *.service (business logic implementation)
│ ├─ users
│ ├─ ...
│ │
├─ infra (generic cross-component functionality)
│ ├─ data (migrations, seeds)
│ ├─ integrations (services responsible for integrations with 3rd party services - belong to repository layer)
│ ├─ loaders
│ ├─ middlewares
Please make sure that you have docker installed https://docs.docker.com/engine/install/
How to run locally (in dev mode):
- Copy
.env.sample
and rename it to.env
, providing appropriate env var values. Part of the vars are defined in docker-compose file - Install dependencies locally
npm i
- To start app
npm run docker:run
- By default API server is available on
http://localhost:8080/
Migrations and seed runs automatically
How to run tests in separate docker locally:
- Install dependencies locally
npm i
- Run api tests in separate docker
npm run docker:test
Here is Postman collection to work with API locally: