Nucleus boilerplate project.
Project include:
- DB Setup using Typeorm (You can easy change to other DB)
- Docker setup with Postgres
- Custom logger module with Morgan and Winston
- Swagger
- Class mapper
- Exception/Error handler
- Request middleware for tracking request id
- Ready enterprise file structure
- Tests for service layer using jest
This dir holds app modules that include controller and services. Each service has own interface. Only serices are covered with unit tests.
This dir includes all configuration modules for easier adding/removing configuration.
Application.config.ts reads .env file, and you can use those values to modify them before passing to other files.
This dir holds 3 type of class
- Request - Request objects for API layer
- Response - Response objects for API layer
- Internal - Object used for communication between services and modules
This dir includes DB entities
This dir includes exception handlers, global exceptions and logic-entity exceptions.
Error has own structure including ErrorCode
This dir includes interceptors (They are executed before returning response to client).
Default interceptor is returning to client requestId for easier tracking client action
This dir includes middlewares (They are executed before entering controller).
For now, we are using moran as middleware and one request filter where:
- If its request path '/auth/*' generating SESSION_ID
- If itsn't request path '/auth/*' if there is no SESSION_ID client will get 401
IMPORTANT: SessionID is generated inside interceptor after login endpoint!
IMPORTANT: Each request need SessionId as header with UUID value!
This project is using Repository Pattern.
This dir will hold migrations/seeds/emails...
This dir includes constants, enums, logger, mapper...All shared utilitis
Currently, we have sign up/in endpoints (including geenrated JWT), and two user endpoints (getAll/getById)
- Each external module import statement is separated with empty line with local modules
- Code format - Prettier
$ npm install
# Run migrations
$ npm run typeorm:migrate
# Create new migration
$ npm run typeorm:create NewMigration
Coverage will include only service files
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Docker only include setup for Postgres, in next iteration I will add app also inside.
How to start postgres via docker?
$ cd envivironment && docker-compose up
Setup env
$ cp .env.example .env
# Add your env values
$ cd environment && cp .env.docker.example .env.docker
# Add your env values
Install packages
$ npm install
# if you don't have postgres
$ cd envivironment && docker-compose up
$ npm run typeorm:migrate
Start app
npm run start:dev
Go to src/config/database/typeorm.config.ts and change postgresl to mysql
IMPORTANT: SessionID is generated inside interceptor after login endpoint!
IMPORTANT: Each request need SessionId as header with UUID value!
- Add security (ACL)
- Add app inside docker
- Add seeds
- Author - Nemanja Mudrinic