This is a repository to start new TS projects quickly using Nest and following SOLID principles (Clean Architecture).
This project has only 3 layers:
- Entities: to define the simple entities and their repositories
- Use Cases: to define the actions of the system
- Externals: everything else that is not related to business rules like storage, frameworks, etc.
We compile every TS to JS and then we run JS. This is better because sometimes the app runs in TS, but there are a lot of errors when we compile to JS.
Running everything into JS already saves a lot of time.
# Build
yarn build
# Start (prod)
yarn start
# Start (dev)
yarn start-dev
# Tests
yarn test
This repository supports the following features:
- Absolute paths by
@/
This codebase has 3 main folders:
src/entities
: To define the entities and their repositories (what each Entity can do)
For example: There is an entity User
.
src/app/contracts
: It defines the contracts that should be followed especially by external items likeIUserRepository
:
- create()
- update()
- delete()
- getAll()
- getById()
src/app/use-cases
: To define the system actions. For example:
- create-user
- update-user
- delete-user
- get-user-by-id
- list-users
Each use case should have its automated tests.
-
src/app/errors
: To define the errors classes. -
src/externals
: To define the rest, things that are not important for the business rules like Database, Frameworks (Express, Nest, Stocket), Libraries, etc.
Nodemon
for starting services in development modeJest
for testsRimraf
for deleting/dist
folderCpy cli
for copying the.env
to thedist
folder onyarn start-dev
Nest Core
for the HTTP server
This is just a template following SOLID + Nest + Typescript. The goal here is to use Nest only as a HTTP server provider, in order to decouple the business rules from Nest.
Feel free to use the best practices for Nest in terms of ** routing and HTTP server **. Business rules should be reserverd to use cases
and entities
.