niceduang / Node_BackEnd_Boilerplate-TypeScript

Node.js Boilerplate for Back-End using TypeScript and Nest.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node Back-End Boilerplate 🔥

Description

Node.js Domain-Driven Design Boilerplate with TypeScript for Back-End.

Overview

What to do if the service goes down

  • Check the logs;
  • Test the dependencies and execution locally;
  • Run automated tests;
  • If necessary, merge with a hotfix on git;
  • Rebuild the project and restart the service;

Architecture

Back-End Architecture


Nest Modules Graph and Classes

Nest Modules Graph
Nest Classes

Main technologies

  • JavaScript: Web programming laguage;
  • TypeScript: JavaScript superset for typing;
  • Node.js: JavaScript runtime;
  • Nest.js: TypeScript Framework for Back-End;
  • Express: Robust tooling for HTTP servers;
  • Socket.io: WebSocket library;
  • AWS-SDK: A Node.js SDK to access AWS resources, such as:
    • SQS: Queue management service;
    • SNS: Topic notification service;
    • S3: Files storage service;
    • Cognito: Users authenticator service;
  • Sequelize: ORM for relational databases;
  • PostgreSQL: Relational (SQL) database;
  • MongoDB: Schematic and document-oriented NoSQL database;
  • Redis: Cache and in-memory key-value NoSQL database;
  • Docker: Services isolation and process resources management with containers;
  • SonarQube: Test coverage and code quality analyzer;
  • Winston: Custom logger with transports;
  • Joi: Schema validator library;
  • EsLint: JavaScript/TypeScript linter;
  • Prettier: JavaScript/TypeScript formatter;
  • Jest: Testing Framework;
  • Huksy: Git hook-listenner used to check tests, format the code and the commits;

Install dependencies

  1. Install project dependencies
yarn install
  1. Install AWS CLI
    AWS CLI

  2. Configure AWS CLI

$ aws configure
> AWS Access Key ID [****]: mock
> AWS Secret Access Key [****]: mock
> Default region name [us-east-1]: us-east-1
> Default output format [table]: json

Execution Steps

  1. Start Docker containers;
  2. Mock external services;
  3. Creat database entities and populat registers;
  4. Start HTTP REST API & GraphQl API;
  5. Start TCP WebSocket;
  6. Send message to Queue;
  7. Receive message from Queue;

Environment Preparation

  1. Copy dotenv file
cp env/.env.development.local ./.env # copy development local example
source ./.env # load envs on shell session
  1. Initialize the composefile (docker-compose.yml) available on project root folder.
docker-compose up -d cloud database data cache # create and run all docker containers in background

Running Locally

yarn run migrate && yarn run seed # create database entities and populate database registers
yarn run mock-dependencies # create message queue and storager and start external services mock
yarn run start:dev # start application in development mode
yarn run receive-messages # create websocket client and start connection to receive events
yarn run send-message # send event message to queue

Interface

  • localhost:3000 - Application Interface (API)
    • / - WebSocket Root Endpoint
    • /api - REST Root Endpoint
      • /api/docs - Swagger API Documentation (Page)
      • /api/docs.json - Swagger API Documentation (JSON)
      • /api/docs.yml - Swagger API Documentation (YAML)
    • /graphql - GraphQL Endpoint
  • localhost:4000 - Mocked Service Page
  • localhost:8000 - Nest.js DevTools Page
  • localhost:8080 - Adminer Page
  • localhost:8081 - Mongo Express Page
  • localhost:8082 - Redis Commander Page
  • localhost:8083 - Jenkins Page
  • localhost:9000 - SonarQube Page

TO DO

  • Packaging
    • Infra Utils Lib Package
  • SQL
    • UUID Fields
    • Manual Queries
    • Index
    • Transactions
  • Clustering
    • Clusters
      • Kubernetes
        • Load Balancing
  • CI/CD
    • Jenkins
    • GitHub Actions
  • Deployment
    • Heroku
  • Nest.js
  • Integrations
  • Tests
    • Integration
      • Configs
      • Modules
        • Core
          • Infra
            • Cron Tasks
            • Logging
        • API
          • Guards
          • Pipes
          • Schemas
        • Events
          • Queue Handler
            • Handlers Schemas
          • Websocket Guards
          • Websocket Server
          • Websocket Client
    • End-to-End
      • Modules
        • Core
          • Infra
            • Database
            • Data
            • Cache
            • Integration
              • AWS
              • REST
            • Cron Jobs
            • Start
        • API
          • Controllers
        • App
          • Repositories
        • Events
          • Queue Consumer
          • Queue Producer
          • Websocket Gateway
        • Reports
          • Services

About

Node.js Boilerplate for Back-End using TypeScript and Nest.js


Languages

Language:TypeScript 91.0%Language:JavaScript 8.2%Language:Shell 0.4%Language:Dockerfile 0.3%Language:Procfile 0.0%