Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikemajesty/nestjs-microservice-boilerplate-api

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
https://github.com/mikemajesty/nestjs-microservice-boilerplate-api

authentication authorization boilerplate clean-arch clean-architecture ddd-architecture docker microservice migrations mongodb mongoose mongoose-crud mongoosejs nestjs postgres postgres-crud redis typeorm typescript

Last synced: about 24 hours ago
JSON representation

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

Awesome Lists containing this project

README

        

# Nestjs boilerplate Microservice API

[![node version][node-image]][node-url]

[node-image]: https://img.shields.io/badge/node.js-%3E=_18.0-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/

In this microservice I used the best architecture concepts: Onion Architecture, DDD and Ports and Adapters.

| Statements | Branches | Functions | Lines |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| ![Statements](https://img.shields.io/badge/statements-100%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-100%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-100%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-100%25-brightgreen.svg?style=flat) |

### 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
```

### Architecture diagram

## ![alt text](OnionGraph.jpg)

[Architecture documentation](https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/)

### User diagram

![alt text](diagram.png)

### Microservice architecture.

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

-- App Skeleton

```
.
├── CHANGELOG.md
├── commitlint.config.js
├── diagram.png
├── 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
├── Dockerfile
├── jest.config.ts
├── nest-cli.json
├── package.json
├── README.md
├── scripts
│ └── npm-audit.sh
├── src
│ ├── app.module.ts
│ ├── core
│ │ ├── cat
│ │ │ ├── entity
│ │ │ │ └── cats.ts
│ │ │ ├── repository
│ │ │ │ └── cats.ts
│ │ │ └── use-cases
│ │ │ ├── cats-create.ts
│ │ │ ├── cats-delete.ts
│ │ │ ├── cats-get-by-id.ts
│ │ │ ├── cats-list.ts
│ │ │ ├── cats-update.ts
│ │ │ └── __tests__
│ │ │ ├── cats-create.spec.ts
│ │ │ ├── cats-delete.spec.ts
│ │ │ ├── cats-list.spec.ts
│ │ │ ├── cats-update.spec.ts
│ │ │ └── user-get-by-id.spec.ts
│ │ ├── permission
│ │ │ ├── entity
│ │ │ │ └── permission.ts
│ │ │ ├── repository
│ │ │ │ └── permission.ts
│ │ │ └── use-cases
│ │ │ ├── permission-create.ts
│ │ │ ├── permission-delete.ts
│ │ │ ├── permission-get-by-id.ts
│ │ │ ├── permission-list.ts
│ │ │ ├── permission-update.ts
│ │ │ └── __tests__
│ │ │ ├── permission-create.spec.ts
│ │ │ ├── permission-delete.spec.ts
│ │ │ ├── permission-get-by-id.spec.ts
│ │ │ ├── permission-list.spec.ts
│ │ │ └── permission-update.spec.ts
│ │ ├── reset-password
│ │ │ ├── entity
│ │ │ │ └── reset-password.ts
│ │ │ ├── repository
│ │ │ │ └── reset-password.ts
│ │ │ └── use-cases
│ │ │ ├── confirm.ts
│ │ │ ├── send-email.ts
│ │ │ └── __tests__
│ │ │ ├── confirm.spec.ts
│ │ │ └── send-email.spec.ts
│ │ ├── role
│ │ │ ├── entity
│ │ │ │ └── role.ts
│ │ │ ├── repository
│ │ │ │ └── role.ts
│ │ │ └── use-cases
│ │ │ ├── role-add-permission.ts
│ │ │ ├── role-create.ts
│ │ │ ├── role-delete-permission.ts
│ │ │ ├── role-delete.ts
│ │ │ ├── role-get-by-id.ts
│ │ │ ├── role-list.ts
│ │ │ ├── role-update.ts
│ │ │ └── __tests__
│ │ │ ├── role-add-permission.spec.ts
│ │ │ ├── role-create.spec.ts
│ │ │ ├── role-delete-permission.spec.ts
│ │ │ ├── role-delete.spec.ts
│ │ │ ├── role-get-by-id.spec.ts
│ │ │ ├── role-list.spec.ts
│ │ │ └── role-update.spec.ts
│ │ └── user
│ │ ├── entity
│ │ │ ├── user-password.ts
│ │ │ └── user.ts
│ │ ├── repository
│ │ │ └── user.ts
│ │ └── use-cases
│ │ ├── __tests__
│ │ │ ├── user-change-password.spec.ts
│ │ │ ├── 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-change-password.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_createCatsCollection.ts
│ │ │ │ ├── module.ts
│ │ │ │ ├── schemas
│ │ │ │ │ └── cat.ts
│ │ │ │ └── service.ts
│ │ │ ├── postgres
│ │ │ │ ├── config.ts
│ │ │ │ ├── index.ts
│ │ │ │ ├── migrations
│ │ │ │ │ ├── 1717769593555-createPermissionTable.ts
│ │ │ │ │ ├── 1717769593666-createRoleTable.ts
│ │ │ │ │ ├── 1717769593777-createRolesPermissionsTable.ts
│ │ │ │ │ ├── 1717769593778-createUsersPasswordTable.ts
│ │ │ │ │ ├── 1717773444116-createUserTable.ts
│ │ │ │ │ ├── 1717773444118-addRoleIdToUserTable.ts
│ │ │ │ │ ├── 1717773889333-insertPermissions.ts
│ │ │ │ │ ├── 1717773889351-insertDefaultUser.ts
│ │ │ │ │ ├── 1717976911236-createResetPasswordTable.ts
│ │ │ │ │ ├── 1718133311187-changeResetPasswordCascadeOptions.ts
│ │ │ │ │ ├── 1718138151111-addUniqueToRoleAndPermissionName.ts
│ │ │ │ │ └── 1718294246477-addCOntraintsToPermissionsRole.ts
│ │ │ │ ├── module.ts
│ │ │ │ ├── schemas
│ │ │ │ │ ├── permission.ts
│ │ │ │ │ ├── resetPassword.ts
│ │ │ │ │ ├── role.ts
│ │ │ │ │ ├── userPassword.ts
│ │ │ │ │ └── user.ts
│ │ │ │ └── service.ts
│ │ │ └── types.ts
│ │ ├── email
│ │ │ ├── adapter.ts
│ │ │ ├── index.ts
│ │ │ ├── module.ts
│ │ │ ├── service.ts
│ │ │ └── templates
│ │ │ ├── reque-reset-password.handlebars
│ │ │ ├── reset-password.handlebars
│ │ │ └── welcome.handlebars
│ │ ├── 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
│ │ └── types.ts
│ ├── libs
│ │ ├── crypto
│ │ │ ├── adapter.ts
│ │ │ ├── index.ts
│ │ │ ├── module.ts
│ │ │ └── service.ts
│ │ ├── event
│ │ │ ├── adapter.ts
│ │ │ ├── index.ts
│ │ │ ├── module.ts
│ │ │ ├── service.ts
│ │ │ └── types.ts
│ │ ├── i18n
│ │ │ ├── adapter.ts
│ │ │ ├── index.ts
│ │ │ ├── languages
│ │ │ │ ├── en
│ │ │ │ │ └── info.json
│ │ │ │ └── pt
│ │ │ │ └── info.json
│ │ │ ├── module.ts
│ │ │ ├── service.ts
│ │ │ └── types.ts
│ │ ├── module.ts
│ │ └── token
│ │ ├── adapter.ts
│ │ ├── index.ts
│ │ ├── module.ts
│ │ └── service.ts
│ ├── main.ts
│ ├── modules
│ │ ├── cat
│ │ │ ├── adapter.ts
│ │ │ ├── controller.ts
│ │ │ ├── module.ts
│ │ │ ├── repository.ts
│ │ │ └── swagger.ts
│ │ ├── health
│ │ │ ├── controller.ts
│ │ │ ├── module.ts
│ │ │ └── __tests__
│ │ │ └── controller.spec.ts
│ │ ├── login
│ │ │ ├── adapter.ts
│ │ │ ├── controller.ts
│ │ │ ├── module.ts
│ │ │ └── swagger.ts
│ │ ├── logout
│ │ │ ├── adapter.ts
│ │ │ ├── controller.ts
│ │ │ ├── module.ts
│ │ │ └── swagger.ts
│ │ ├── permission
│ │ │ ├── adapter.ts
│ │ │ ├── controller.ts
│ │ │ ├── module.ts
│ │ │ ├── repository.ts
│ │ │ └── swagger.ts
│ │ ├── reset-password
│ │ │ ├── adapter.ts
│ │ │ ├── controller.ts
│ │ │ ├── module.ts
│ │ │ ├── repository.ts
│ │ │ └── swagger.ts
│ │ ├── role
│ │ │ ├── adapter.ts
│ │ │ ├── controller.ts
│ │ │ ├── module.ts
│ │ │ ├── repository.ts
│ │ │ └── swagger.ts
│ │ └── user
│ │ ├── adapter.ts
│ │ ├── controller.ts
│ │ ├── module.ts
│ │ ├── repository.ts
│ │ └── swagger.ts
│ ├── observables
│ │ ├── filters
│ │ │ ├── http-exception.filter.ts
│ │ │ └── index.ts
│ │ ├── guards
│ │ │ ├── auth.guard.ts
│ │ │ └── index.ts
│ │ ├── interceptors
│ │ │ ├── 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
│ └── utils
│ ├── axios.ts
│ ├── collection.ts
│ ├── database
│ │ └── mongoose.ts
│ ├── date.ts
│ ├── decorators
│ │ ├── database
│ │ │ ├── mongo
│ │ │ │ ├── convert-mongoose-filter.decorator.ts
│ │ │ │ └── validate-mongoose-filter.decorator.ts
│ │ │ ├── postgres
│ │ │ │ └── convert-paginate-input-to-typeorm-filter.decorator.ts
│ │ │ └── validate-database-sort-allowed.decorator.ts
│ │ ├── index.ts
│ │ ├── request-timeout.decorator.ts
│ │ ├── role.decorator.ts
│ │ ├── types.ts
│ │ └── validate-schema.decorator.ts
│ ├── docs
│ │ ├── data
│ │ │ ├── cat
│ │ │ │ ├── request.ts
│ │ │ │ └── response.ts
│ │ │ ├── permission
│ │ │ │ ├── request.ts
│ │ │ │ └── response.ts
│ │ │ ├── role
│ │ │ │ ├── request.ts
│ │ │ │ └── response.ts
│ │ │ └── user
│ │ │ ├── request.ts
│ │ │ └── response.ts
│ │ └── swagger.ts
│ ├── entity.ts
│ ├── excel.ts
│ ├── exception.ts
│ ├── pagination.ts
│ ├── request.ts
│ ├── search.ts
│ ├── sort.ts
│ ├── static
│ │ └── http-status.json
│ ├── tests.ts
│ ├── text.ts
│ ├── tracing.ts
│ ├── usecase.ts
│ └── zod.ts
├── test
│ └── initialization.ts
├── TRACING.md
├── tsconfig.build.json
└── tsconfig.json
```

---

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

[mikemajesty](https://github.com/mikemajesty)

## License

It is available under the MIT license.
[License](https://opensource.org/licenses/mit-license.php)