Nestjs Monorepo Boilerplate
Check
Statements | Branches | Functions | Lines |
---|---|---|---|
Monorepo with nestjs
-
Docker
-
Secrets Service
-
Logs Service
- Pinojs
- Elastic
-
Observability
- Jeager
- Opentracing
-
Authentication
-
Error Handler
-
Libs Structure
-
Dependency Inversion Pattern
-
Anti Corruption Layer Pattern
-
Interface Adapter Pattern
-
Generic Repository Pattern
-
Swaggger Documentation
-
Redis
-
Mongodb
- mongoose
- multiples databases
-
Tests
- unit
- e2e
- 90% coverage
Prerequisite
- Node: 14 => <= 16
- Docker
- npm install -g commitizen
- npm install -g changelog
- https://stedolan.github.io/jq/download/
Instalation
- install monorepo dependencies
$ yarn monorepo:install
- install project dependencies
$ yarn workspace <workspaceName> install
- install lib on project
$ yarn workspace <workspaceName> add <libName>
Running local mongodb/redis/kibana/jeager
$ yarn infra:local
# http://0.0.0.0:8082/ to access mongo
# http://0.0.0.0:8081/ to access redis
# http://0.0.0.0:5601/app/home to access kibana
# http://0.0.0.0:16686/search to access jeager
Running the app
-
local
$ yarn start:auth-api:dev $ yarn start:cats-api:dev
-
dev/hml/prd environment
$ docker-compose up --build
Create Access User
- http://0.0.0.0:8082/db/monorepo_auth/users
- Click [New Document]
{ "_id": ObjectID(), "login": "<user>", "pass": "<pass>" }
- now use this curl to get your access token
curl -X 'POST' 'http://0.0.0.0:4000/api/login' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{ "login": "<user>", "pass": "<pass>" }'
- use this token to access all monorepo internal APIs
workspace list
$ yarn workspaces info
- @app/cats.api
- @app/auth.api
- @tools/eslint.config
- @libs/utils
- @libs/modules
- @libs/core
Add new features
$ npm i -g @mikemajesty/monorepo-nestjs-cli
-
# type and choose your template $ monorepo-nestjs-cli
- see doc
Tests
-
unit
# Run monorepo tests $ yarn test
# Run project tests $ yarn test main.api $ yarn test auth.api $ yarn test libs
-
e2e
$ yarn test:e2e
- coverage
$ yarn test:coverage
Lint
-
Run monorepo lint
$ yarn lint
-
Run project lint
$ yarn workspace <workspaceName> lint
Build
- Run project build
$ yarn build <workspaceName>
-- App Skeleton
.
βββ apps
β βββ auth-api
β β βββ Dockerfile
β β βββ jest.config.js
β β βββ package.json
β β βββ src
β β β βββ main.ts
β β β βββ modules
β β β βββ health
β β β β βββ adapter.ts
β β β β βββ controller.ts
β β β β βββ module.ts
β β β β βββ service.ts
β β β β βββ swagger.ts
β β β β βββ __tests__
β β β β βββ controller.e2e.spec.ts
β β β β βββ module.spec.ts
β β β β βββ service.spec.ts
β β β βββ login
β β β β βββ adapter.ts
β β β β βββ controller.ts
β β β β βββ module.ts
β β β β βββ service.ts
β β β β βββ swagger.ts
β β β β βββ __tests__
β β β β βββ controller.e2e.spec.ts
β β β β βββ service.spec.ts
β β β βββ module.ts
β β β βββ __tests__
β β β β βββ module.spec.ts
β β β βββ user
β β β βββ adapter.ts
β β β βββ entity.ts
β β β βββ module.ts
β β β βββ repository.ts
β β β βββ schema.ts
β β β βββ __tests__
β β β βββ repository.spec.ts
β β βββ tests
β β β βββ initialization.js
β β βββ tsconfig.build.json
β β βββ tsconfig.json
β β βββ yarn.lock
β βββ cats-api
β βββ Dockerfile
β βββ jest.config.js
β βββ node_modules
β βββ package.json
β βββ src
β β βββ main.ts
β β βββ modules
β β βββ cats
β β β βββ adapter.ts
β β β βββ controller.ts
β β β βββ entity.ts
β β β βββ module.ts
β β β βββ repository.ts
β β β βββ schema.ts
β β β βββ swagger.ts
β β β βββ __tests__
β β β βββ controller.e2e.spec.ts
β β β βββ repository.spec.ts
β β βββ health
β β β βββ adapter.ts
β β β βββ controller.ts
β β β βββ module.ts
β β β βββ service.ts
β β β βββ swagger.ts
β β β βββ __tests__
β β β βββ controller.e2e.spec.ts
β β β βββ module.spec.ts
β β β βββ service.spec.ts
β β βββ module.ts
β β βββ __tests__
β β βββ module.spec.ts
β βββ tests
β β βββ initialization.js
β βββ tsconfig.build.json
β βββ tsconfig.json
βββ CHANGELOG.md
βββ commitlint.config.ts
βββ CONTRIBUTING.md
βββ deploy
β βββ production-version.sh
βββ docker-compose-local.yml
βββ docker-compose.yml
βββ jest.config.e2e.ts
βββ jest.config.ts
βββ libs
β βββ core
β β βββ index.ts
β β βββ jest.config.js
β β βββ package.json
β β βββ tests
β β β βββ initialization.js
β β βββ tsconfig.json
β βββ modules
β β βββ auth
β β β βββ token
β β β βββ adapter.ts
β β β βββ module.ts
β β β βββ service.ts
β β β βββ __tests__
β β β β βββ service.spec.ts
β β β βββ types.ts
β β βββ common
β β β βββ http
β β β β βββ adapter.ts
β β β β βββ module.ts
β β β β βββ service.ts
β β β β βββ __tests__
β β β β βββ module.spec.ts
β β β β βββ service.spec.ts
β β β βββ module.ts
β β β βββ __tests__
β β β βββ module.spec.ts
β β βββ database
β β β βββ adapter.ts
β β β βββ connection
β β β β βββ auth.ts
β β β β βββ cats.ts
β β β βββ entity.ts
β β β βββ enum.ts
β β β βββ repository.ts
β β β βββ service.ts
β β β βββ __tests__
β β β βββ repository.spec.ts
β β β βββ service.spec.ts
β β βββ global
β β β βββ logger
β β β β βββ adapter.ts
β β β β βββ module.ts
β β β β βββ service.ts
β β β β βββ __tests__
β β β β β βββ module.spec.ts
β β β β β βββ service.spec.ts
β β β β βββ type.ts
β β β βββ module.ts
β β β βββ secrets
β β β β βββ adapter.ts
β β β β βββ enum.ts
β β β β βββ module.ts
β β β β βββ service.ts
β β β β βββ __tests__
β β β β βββ module.spec.ts
β β β β βββ service.spec.ts
β β β βββ __tests__
β β β βββ module.spec.ts
β β βββ index.ts
β β βββ jest.config.js
β β βββ package.json
β β βββ redis
β β β βββ adapter.ts
β β β βββ module.ts
β β β βββ service.ts
β β β βββ __tests__
β β β β βββ service.spec.ts
β β β βββ types.ts
β β βββ __tests__
β β β βββ module.spec.ts
β β βββ tests
β β β βββ initialization.js
β β βββ tsconfig.json
β βββ utils
β βββ documentation
β β βββ constants.ts
β β βββ swagger.ts
β βββ exception.ts
β βββ filters
β β βββ http-exception.filter.ts
β β βββ __tests__
β β βββ http-exception.filter.spec.ts
β βββ index.ts
β βββ interceptors
β β βββ exception
β β β βββ http-exception.interceptor.ts
β β β βββ __tests__
β β β βββ http-exception.interceptor.spec.ts
β β βββ logger
β β βββ http-logger.interceptor.ts
β β βββ http-tracing.interceptor.ts
β β βββ __tests__
β β βββ http-logger.interceptor.spec.ts
β βββ jest.config.js
β βββ middleware
β β βββ auth
β β βββ is-logged.middleware.ts
β β βββ __tests__
β β βββ is-logged.middleware.spec.ts
β βββ package.json
β βββ request.ts
β βββ static
β β βββ htttp-status.json
β βββ __tests__
β β βββ exception.spec.ts
β βββ tests
β β βββ initialization.js
β β βββ mock-utils.ts
β β βββ __tests__
β β βββ mock-utils.spec.ts
β βββ tsconfig.json
βββ nest-cli.json
βββ package.json
βββ README.md
βββ tests
β βββ common-initialization.js
βββ tools
β βββ eslint
β βββ package.json
βββ tsconfig.build.json
βββ tsconfig.json
βββ update-version.sh
Architecture
-
βββ tools
: Project tools like: eslint, prettier and etc. -
βββ tests
: Monorepo tests initializer like: env, mocks and configs. -
βββ apps
: Monorepo Applications. -
βββ apps βββ auth-api
: Authentication api, use to getting token to navigate between other projects. -
βββ apps βββ cats-api
: Use this API like an example to create other APIs. -
βββ libs
: Application shared libs. -
βββ libs βββ core
: Core business rules, don't use nestjs dependecies here, only class and rules that will be shared with other projects -
βββ libs βββ modules
: Application modules, use only nestjs modules here, you can add modules like: http, databse etc. -
βββ libs βββ utils
: Application utils, utilities that will shared with your monorepo. -
βββ libs βββ modules βββ global βββ secrets
: Monorepo secrets.
The following is a list of all the people that have contributed Nestjs monorepo boilerplate. Thanks for your contributions!
License
It is available under the MIT license. License