Giter Club home page Giter Club logo

ack-nestjs-mongoose's Introduction

Contributors Forks Stargazers Issues MIT License

NestJs NodeJs Typescript MongoDB JWT Jest Yarn Docker

ACK NestJs Boilerplate Mongoose ๐Ÿ”ฅ ๐Ÿš€

ack-nestjs-mongoose is a Http NestJs Boilerplate.

You can Request Feature or Report Bug with following this link

Important

ack-nestjs-mongoose still on trial and error phase and the test will base on real projects or cases. So there will be (always) have new update and new features.

If you change env value of APP_ENV to production that will trigger

  1. CorsMiddleware will implement src/configs/middleware.config.ts, else default is *.
  2. Documentation will disable

Next Todo

Next development

  • Implement Repository Design Pattern / Data Access Object Design Pattern
  • Swagger for API Documentation
  • Support Serverless
  • Mongo Repository soft delete
  • Make it simple
  • Optimize Swagger
  • Add Relational Database Repository, ex: mysql, postgres
  • Update Documentation, include an diagram for easier comprehension
  • Export to excel and Import from excel add options to background process
  • AuthApi Controller
  • OAuth2 Client Credentials
  • Maybe will adopt CQRS

Build with

Describes which version .

Name Version
NestJs v9.x
NodeJs v18.x
Typescript v4.x
Mongoose v6.x
MongoDB v6.x
Yarn v1.x
NPM v8.x
Docker v20.x
Docker Compose v2.x
Swagger v6.x
Aws CLI v2.x

Objective

  • Easy to maintenance
  • NestJs Habit
  • Component based folder structure
  • Repository Design Pattern or Data Access Layer Design Pattern
  • Support Microservice Architecture, Clean Architecture, and/or Hexagonal Architecture
  • Follow The Twelve-Factor App
  • Adopt SOLID and KISS principle

Features

  • NestJs v9.x ๐Ÿฅณ
  • Typescript ๐Ÿš€
  • Production ready ๐Ÿ”ฅ
  • Support serverless
  • Swagger included
  • Authentication and authorization (JWT, API Key) ๐Ÿ’ช
  • Role management system
  • MongoDB integrate by using mongoose ๐ŸŽ‰
  • Support MongoDB Transaction
  • Support MongoDB Soft Delete
  • Database Migration with NestJs-Command
  • Storage integration with AwsS3
  • Upload file single and multipart to AwsS3
  • Support multi-language i18n ๐Ÿ—ฃ
  • Request validation with class-validation
  • Serialization with class-transformer
  • Url Versioning
  • Server Side Pagination, there have 3 of types
  • Import and export data with excel by using decorator

Logger and Debugger

  • Logger Morgan and Debugger Winston ๐Ÿ“

Security

  • Apply helmet, cors, and rate-limit
  • Timeout awareness and can override โŒ›๏ธ
  • User agent awareness, and can whitelist user agent

Setting

  • Support environment file
  • Centralize configuration ๐Ÿค–
  • Centralize response
  • Centralize exception filter
  • Setting from database ๐Ÿ—ฟ
  • Maintenance mode on / off from database ๐Ÿค

Others

  • Support Docker Installation
  • Support CI/CD with Github Action or Jenkins
  • Husky GitHook For Check Source Code, and Run Test Before Commit ๐Ÿถ
  • Linter with EsLint for Typescript

Prerequisites

We assume that everyone who comes here is programmer with intermediate knowledge and we also need to understand more before we begin in order to reduce the knowledge gap.

  1. Understand NestJs Fundamental, Main Framework. NodeJs Framework with support fully TypeScript.
  2. UnderstandTypescript Fundamental, Programming Language. It will help us to write and read the code.
  3. Understand ExpressJs Fundamental, NodeJs Base Framework. It will help us in understanding how the NestJs Framework works.
  4. Understand what NoSql is and how it works as a database, especially MongoDB.
  5. Understand Repository Design Pattern or Data Access Object Design Pattern. It will help us to read the source code
  6. Understand The SOLID Principle and KISS Principle for better write the code.
  7. Optional. Understand Microservice Architecture Clean Architecture, and/or Hexagonal Architecture.
  8. Optional. Understand The Twelve Factor Apps
  9. Optional. Understand Docker that can help you to run the project

Getting Started

Before we start, we need to install some packages and tools. Recommend version is LTS Version for every tool and package.

Make sure check that tools has been installed successfully.

  1. NodeJs
  2. MongoDB as Replication
  3. Yarn
  4. Git
  5. Docker
  6. Docker-Compose
  7. Serverless

Clone Repo

Clone ack-nestjs-mongoose with git.

git clone https://github.com/andrechristikan/ack-nestjs-mongoose.git

Install Dependencies

This project need some dependencies. Let's go install it.

yarn install

Create environment

Make your own environment with copy from .env.example and edit some value.

cp .env.example .env

Jump to details

Database Migration

If you want to to implement transaction, you must to install Mongodb Replication Set.

Database migration ack-nestjs-mongoose used NestJs-Command

For migrate

yarn migrate

For rollback

yarn rollback

Test

ack-nestjs-mongoose provide 3 automation testing unit testing, integration testing, and e2e testing.

yarn test

Specific test

For unit testing

yarn test:unit

For integration testing

yarn test:integration

For E2E testing

yarn test:e2e

Run Project

If mongodb version < 5, Read this section for adjust mongoose setting.

Finally, Cheers ๐Ÿป๐Ÿป !!! we passed all steps.

Now we can run ack-nestjs-mongoose and use all of features.

yarn start:dev

Run Project with Docker

docker-compose up -d

Environment

Detail information about the environment

APP Environment

Key Type Description
APP_NAME string Application name and will be subject for jwt
APP_ENV string
  • production
  • development
APP_LANGUAGE string Enum languages, separator ,

HTTP Environment

Key Type Description
HTTP_HTTP_ENABLE boolean Application Http on/off
HTTP_HOST string Application host serve
HTTP_PORT number Application port serve
HTTP_VERSIONING_ENABLE boolean Application url versioning on/off
HTTP_VERSION number Application version number

Debugger Environment

Key Type Description
DEBUGGER_HTTP_WRITE_INTO_FILE boolean Http debugger write into file
DEBUGGER_SYSTEM_WRITE_INTO_FILE boolean System debugger write into file

Middleware Environment

Key Type Description
MIDDLEWARE_TIMESTAMP_TOLERANCE string Tolerance timestamp ApiKey. ms package value
MIDDLEWARE_TIMEOUT string Request timeout. ms package value

Documentation Environment

Key Type Description
DOC_NAME string Documentation tittle
DOC_VERSION number Documentation version

Job Environment

Key Type Description
JOB_ENABLE boolean Application Job turn on/off

Database Environment

Key Type Description
DATABASE_HOST string Mongodb URL. Support standard url, replication, or srv
DATABASE_NAME string Database name
DATABASE_USER string Database user
DATABASE_PASSWORD string Database user password
DATABASE_DEBUG boolean Trigger database mongoose DEBUG
DATABASE_OPTIONS string Mongodb connect options

Auth Environment

Key Type Description
AUTH_JWT_SUBJECT setting Jwt subject
AUTH_JWT_AUDIENCE string Jwt audience
AUTH_JWT_ISSUER string JWT issuer
AUTH_JWT_ACCESS_TOKEN_SECRET_KEY string Secret access token, free text.
AUTH_JWT_ACCESS_TOKEN_EXPIRED string Expiration time for access token. ms package value
AUTH_JWT_REFRESH_TOKEN_SECRET_KEY string Secret refresh token, free text.
AUTH_JWT_REFRESH_TOKEN_EXPIRED string Expiration time for refresh token. ms package value
AUTH_JWT_REFRESH_TOKEN_REMEMBER_ME_EXPIRED string Expiration time for refresh token when remember me is checked. ms package value
AUTH_JWT_REFRESH_TOKEN_NOT_BEFORE_EXPIRATION string Token active for refresh token before x time. ms package value

Serverless

Key Type Description
SERVERLESS_AWS_API_GATEWAY string AWS api gateway for server the aws lamda
SERVERLESS_AWS_PROFILE string AWS profile for deployment
SERVERLESS_AWS_S3_BUCKET string AWS s3 bucket for save the development asset

AWS Environment

Key Type Description
AWS_CREDENTIAL_KEY string AWS account credential key
AWS_CREDENTIAL_SECRET string AWS account credential secret
AWS_S3_REGION string AWS S3 Region
AWS_S3_BUCKET string AWS S3 Name of Bucket

Adjust Mongoose Setting

Just is case, if your mongodb version is < 5

Go to file src/common/database/services/database.options.service.ts and remove comment useMongoClient then set value to true.

const mongooseOptions: MongooseModuleOptions = {
    uri,
    useNewUrlParser: true,
    useUnifiedTopology: true,
    serverSelectionTimeoutMS: 5000,
    useMongoClient: true
};

License

Distributed under MIT licensed.

Contact

Andre Christi kan

Github LinkedIn Instagram

ack-nestjs-mongoose's People

Contributors

aallithioo avatar andrechristikan avatar bipinparajuli avatar dependabot[bot] avatar psheon avatar

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.