Giter VIP home page Giter VIP logo

mikemajesty / nestjs-microservice-boilerplate-api Goto Github PK

View Code? Open in Web Editor NEW
251.0 13.0 61.0 4.2 MB

Nestjs boilerplate microservice api | Mongodb CRUD - Postgres CRUD | Docker | Husky | Secrets service | HTTP service | Logs service | Authentication | Authorization | Error Handler | Swaggger Documentation | Mongo Generic Repository | Postgres Generic Repository

Shell 0.78% JavaScript 1.86% TypeScript 97.25% Dockerfile 0.10%
boilerplate microservice mongodb mongoose nestjs postgres typeorm typescript clean-arch clean-architecture

nestjs-microservice-boilerplate-api's Introduction

Nestjs boilerplate Microservice API

In this microservice I used the best architecture concepts: onion architecture, DDD and clean architecture.

Statements Branches Functions Lines
Statements Branches Functions Lines

Building and Running the application

  • install dependencies

    $ yarn
    
  • infra

     $ yarn infra
    
  • running

    • dev
      $ yarn start:dev
      
    • debug
      $ start:debug
      
    • production
      $ yarn start
      
  • build

    $ yarn build
    

CRUD Scaffolding

Creating a CRUD in Postgres and Mongo in seconds.

  • run
    $ yarn scaffold
    
  • Choose database for CRUD.
  • (x) POSTGRES:CRUD
  • ( ) MONGO:CRUD
  • ( ) LIB
  • ( ) INFRA
  • ( ) MODULE
  • type module name (use the singular name)
  • After generating the CRUD, follow the instructions on the generated link.
  • ✨Magic ✨

CRUD features

  • List
    • mongo
      • search
      • pagination
      • sort
      • entity validation
    • postgres
      • search
      • pagination
      • sort
      • entity validation
  • Delete
    • mongo
      • Logical deletion
      • entity validation
    • postgres
      • Logical deletion
      • entity validation
  • Update
    • mongo
      • Update Partial entity
      • entity validation
    • postgres
      • Update Partial entity
      • entity validation
  • Create
    • mongo
      • entity validation
      • Not allow creating duplicates
    • postgres
      • entity validation

Postgres migrations

  • create

    $ yarn migration-postgres:create
    
  • run

    $ yarn migration-postgres:run
    

Mongo migrations

  • create

    $ yarn migration-mongo:create
    
  • run

    $ yarn migration-mongo:run
    

Test

  • run
    $ yarn test
    
  • coverage
    $ yarn test:cov
    

Lint

  • lint
    $ yarn lint
    
  • prettier
    $ yarn prettier
    

Microservice architecture.

  • I18n
  • Docker
  • Observability
    • tracing
    • logs
    • metrics
  • Lint-staged + Husky
  • Commitlint
  • Secrets Service
  • HTTP Service
  • Logger Service
    • mongodb transport
  • Authentication
    • Login
    • Logout
  • Authorization
    • Role-based access
  • Error Handler
  • Libs Structure
  • Dependency Inversion Pattern
  • Usecase Pattern
  • Interface Adapter Pattern
  • Generic Repository Pattern
    • Mongo Repository (mongoose)
    • Postgres Repository (sequelize)
  • Swagger Documentation
  • Cache Service
    • Redis
    • NodeCache
  • Database
    • mongo
      • Migrations
      • Replica set
      • Transaction session
    • postgres
      • Migrations
      • Transaction session
  • Tests
    • unit
    • 100% coverage

-- App Skeleton

.
├── CHANGELOG.md
├── Dockerfile
├── README.md
├── TRACING.md
├── commitlint.config.js
├── docker
│   ├── collector
│   │   └── collector-config.yaml
│   ├── mongo
│   │   ├── rs-init.sh
│   │   └── start-replicaset.sh
│   ├── postgres
│   │   └── create-database.sql
│   └── prometheus
│       └── config.yml
├── docker-compose-infra.yml
├── docker-compose.yml
├── jest.config.ts
├── nest-cli.json
├── package-lock.json
├── package.json
├── scripts
│   └── npm-audit.sh
├── src
│   ├── app.module.ts
│   ├── common
│   │   ├── decorators
│   │   │   ├── database
│   │   │   │   ├── mongo
│   │   │   │   │   ├── convert-mongoose-filter.decorator.ts
│   │   │   │   │   └── validate-mongoose-filter.decorator.ts
│   │   │   │   ├── postgres
│   │   │   │   │   ├── convert-paginate-input-to-sequelize-filter.decorator.ts
│   │   │   │   │   └── convert-sequelize-filter.decorator.ts
│   │   │   │   └── validate-database-sort-allowed.decorator.ts
│   │   │   ├── index.ts
│   │   │   ├── request-timeout.decorator.ts
│   │   │   ├── role.decorator.ts
│   │   │   ├── types.ts
│   │   │   └── validate-schema.decorator.ts
│   │   ├── filters
│   │   │   ├── http-exception.filter.ts
│   │   │   └── index.ts
│   │   ├── interceptors
│   │   │   ├── auth-guard.interceptor.ts
│   │   │   ├── http-exception.interceptor.ts
│   │   │   ├── http-logger.interceptor.ts
│   │   │   ├── index.ts
│   │   │   ├── metrics.interceptor.ts
│   │   │   ├── request-timeout.interceptor.ts
│   │   │   └── tracing.interceptor.ts
│   │   └── middlewares
│   │       ├── index.ts
│   │       └── is-logged.middleware.ts
│   ├── core
│   │   ├── cats
│   │   │   ├── entity
│   │   │   │   └── cats.ts
│   │   │   ├── repository
│   │   │   │   └── cats.ts
│   │   │   └── use-cases
│   │   │       ├── __tests__
│   │   │       │   ├── cats-create.spec.ts
│   │   │       │   ├── cats-delete.spec.ts
│   │   │       │   ├── cats-list.spec.ts
│   │   │       │   ├── cats-update.spec.ts
│   │   │       │   └── user-get-by-id.spec.ts
│   │   │       ├── cats-create.ts
│   │   │       ├── cats-delete.ts
│   │   │       ├── cats-get-by-id.ts
│   │   │       ├── cats-list.ts
│   │   │       └── cats-update.ts
│   │   └── user
│   │       ├── entity
│   │       │   └── user.ts
│   │       ├── repository
│   │       │   └── user.ts
│   │       └── use-cases
│   │           ├── __tests__
│   │           │   ├── user-create.spec.ts
│   │           │   ├── user-delete.spec.ts
│   │           │   ├── user-get-by-id.spec.ts
│   │           │   ├── user-list.spec.ts
│   │           │   ├── user-login.spec.ts
│   │           │   ├── user-logout.spec.ts
│   │           │   └── user-update.spec.ts
│   │           ├── user-create.ts
│   │           ├── user-delete.ts
│   │           ├── user-get-by-id.ts
│   │           ├── user-list.ts
│   │           ├── user-login.ts
│   │           ├── user-logout.ts
│   │           └── user-update.ts
│   ├── infra
│   │   ├── cache
│   │   │   ├── adapter.ts
│   │   │   ├── index.ts
│   │   │   ├── memory
│   │   │   │   ├── index.ts
│   │   │   │   ├── module.ts
│   │   │   │   ├── service.ts
│   │   │   │   └── types.ts
│   │   │   ├── redis
│   │   │   │   ├── index.ts
│   │   │   │   ├── module.ts
│   │   │   │   ├── service.ts
│   │   │   │   └── types.ts
│   │   │   └── types.ts
│   │   ├── database
│   │   │   ├── adapter.ts
│   │   │   ├── enum.ts
│   │   │   ├── index.ts
│   │   │   ├── mongo
│   │   │   │   ├── config.ts
│   │   │   │   ├── index.ts
│   │   │   │   ├── migrations
│   │   │   │   │   ├── 1709943706267_create-user-collection.ts
│   │   │   │   │   └── 1709944044583_create-user-default.ts
│   │   │   │   ├── module.ts
│   │   │   │   ├── schemas
│   │   │   │   │   └── user.ts
│   │   │   │   └── service.ts
│   │   │   ├── postgres
│   │   │   │   ├── config.js
│   │   │   │   ├── index.ts
│   │   │   │   ├── migrations
│   │   │   │   │   └── 20230416174316-create-cats-table.js
│   │   │   │   ├── module.ts
│   │   │   │   ├── schemas
│   │   │   │   │   └── cats.ts
│   │   │   │   └── service.ts
│   │   │   └── types.ts
│   │   ├── http
│   │   │   ├── adapter.ts
│   │   │   ├── index.ts
│   │   │   ├── module.ts
│   │   │   └── service.ts
│   │   ├── logger
│   │   │   ├── adapter.ts
│   │   │   ├── index.ts
│   │   │   ├── module.ts
│   │   │   ├── service.ts
│   │   │   └── types.ts
│   │   ├── module.ts
│   │   ├── repository
│   │   │   ├── adapter.ts
│   │   │   ├── index.ts
│   │   │   ├── mongo
│   │   │   │   └── repository.ts
│   │   │   ├── postgres
│   │   │   │   └── repository.ts
│   │   │   ├── types.ts
│   │   │   └── util.ts
│   │   └── secrets
│   │       ├── adapter.ts
│   │       ├── index.ts
│   │       ├── module.ts
│   │       └── service.ts
│   ├── libs
│   │   ├── auth
│   │   │   ├── adapter.ts
│   │   │   ├── index.ts
│   │   │   ├── module.ts
│   │   │   └── service.ts
│   │   └── crypto
│   │       ├── adapter.ts
│   │       ├── index.ts
│   │       ├── module.ts
│   │       └── service.ts
│   ├── main.ts
│   ├── modules
│   │   ├── cats
│   │   │   ├── adapter.ts
│   │   │   ├── controller.ts
│   │   │   ├── module.ts
│   │   │   ├── repository.ts
│   │   │   └── swagger.ts
│   │   ├── health
│   │   │   ├── __tests__
│   │   │   │   └── controller.spec.ts
│   │   │   ├── controller.ts
│   │   │   └── module.ts
│   │   ├── login
│   │   │   ├── adapter.ts
│   │   │   ├── controller.ts
│   │   │   ├── module.ts
│   │   │   └── swagger.ts
│   │   ├── logout
│   │   │   ├── adapter.ts
│   │   │   ├── controller.ts
│   │   │   ├── module.ts
│   │   │   └── swagger.ts
│   │   └── user
│   │       ├── adapter.ts
│   │       ├── controller.ts
│   │       ├── module.ts
│   │       ├── repository.ts
│   │       └── swagger.ts
│   └── utils
│       ├── axios.ts
│       ├── collection.ts
│       ├── database
│       │   ├── mongoose.ts
│       │   └── sequelize.ts
│       ├── date.ts
│       ├── docs
│       │   ├── data
│       │   │   ├── cats
│       │   │   │   ├── request.ts
│       │   │   │   └── response.ts
│       │   │   └── user
│       │   │       ├── request.ts
│       │   │       └── response.ts
│       │   └── swagger.ts
│       ├── entity.ts
│       ├── exception.ts
│       ├── pagination.ts
│       ├── request.ts
│       ├── search.ts
│       ├── sort.ts
│       ├── static
│       │   └── http-status.json
│       ├── tests
│       │   └── tests.ts
│       └── tracing.ts
├── test
│   └── initialization.js
├── tsconfig.build.json
├── tsconfig.json
└── yarn.lock

The following is a list of all the people that have contributed Nestjs monorepo boilerplate. Thanks for your contributions!

mikemajesty

License

It is available under the MIT license. License

nestjs-microservice-boilerplate-api's People

Contributors

mike-lima-gaivota avatar mikemajesty avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nestjs-microservice-boilerplate-api's Issues

Implementação do Tracing

Olá Mike, primeiramente parabéns pelo excelente projeto. Estou fazendo alguns testes com o objetivo de entender o funcionamento e percebi, durante os testes, que não está sendo feito o registro do tracing no Zipkin. Essa implementação está funcional?

Issue while running yarn start after yarn build

{"stack":"AggregateError\n at internalConnectMultiple (node:net:1114:18)\n at afterConnectMultiple (node:net:1667:5)\n at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)","errors":"Error: connect ECONNREFUSED ::1:4318,Error: connect ECONNREFUSED 127.0.0.1:4318","code":"ECONNREFUSED","name":"AggregateError"}
{"stack":"Error: PeriodicExportingMetricReader: metrics export failed (error AggregateError)\n at doExport (/Users/niteshrajkhanal/Desktop/nestjs-microservice-boilerplate-api/node_modules/@opentelemetry/sdk-metrics/build/src/export/PeriodicExportingMetricReader.js:76:23)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async PeriodicExportingMetricReader._doRun (/Users/niteshrajkhanal/Desktop/nestjs-microservice-boilerplate-api/node_modules/@opentelemetry/sdk-metrics/build/src/export/PeriodicExportingMetricReader.js:84:13)\n at async PeriodicExportingMetricReader._runOnce (/Users/niteshrajkhanal/Desktop/nestjs-microservice-boilerplate-api/node_modules/@opentelemetry/sdk-metrics/build/src/export/PeriodicExportingMetricReader.js:55:13)","message":"PeriodicExportingMetricReader: metrics export failed (error AggregateError)","name":"Error"}

Issue while starting the application.

I am running on Ubuntu 23. I have cloned the project and then ran
yarn infra
the docker containers are up and running successfully. But while trying to run the command
yarn start:dev i am getting connection error in mongo db.

Help me

Here is the error
[6:41:36 PM] File change detected. Starting incremental compilation...

[6:41:36 PM] Found 0 errors. Watching for file changes.

Tracing terminated
(node:53467) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
TRACE [16/11/2023 09:56:38]: CacheMemory connected!
TRACE [16/11/2023 09:56:38]: Redis connected!

[sequelize] Executed (default): SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'cats' 4ms
[sequelize] Executed (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'cats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname; 3ms
TRACE [16/11/2023 09:56:38]: Sequelize connected!
(node:53467) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)

/home/nitesh-raj-khanal/Development/nestjs-microservice-boilerplate-api/node_modules/pino-mongodb/node_modules/mongodb/src/sdam/topology.ts:591
const timeoutError = new MongoServerSelectionError(
^
MongoServerSelectionError: Server selection timed out after 5000 ms
at Timeout._onTimeout (/home/nitesh-raj-khanal/Development/nestjs-microservice-boilerplate-api/node_modules/pino-mongodb/node_modules/mongodb/src/sdam/topology.ts:591:30)
at listOnTimeout (node:internal/timers:573:17)
at processTimers (node:internal/timers:514:7)

Screenshot from 2023-11-16 18-47-45

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.