Skip to content

Implements an authentication REST API using NestJS. Tests with Jest, Supertest and Testcontainers. CI/CD with GitHub Actions to automate testing and deployment process

Notifications You must be signed in to change notification settings

shimisnow/poc-nestjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

POC NestJS

Authentication API with NestJS

Unit Integration E2E Test Build and publish Docker Images Auth Service Docker image size Financial Service Docker image size

Project Overview

This project is a robust authentication REST API built using the NestJS framework. Key features include a modular, testable architecture; comprehensive unit and integration testing with Jest; end-to-end testing using Supertest and Testcontainers for application stack testing; and an integrated CI/CD pipeline with GitHub Actions to automate testing and deployment process.

Key features

Tech Stack

General organization

This project has two individual services:

  • Auth Service: implements an authentication process with JWT tokens
  • Financial Service: process and store financial data (used to demonstrate the authentication)
stateDiagram-v2
direction LR

state "Auth Consumer" as auth_consumer_group {
    state "API request" as auth_consumer_api_call
    [*] --> auth_consumer_api_call
}

state "Financial Consumer" as financial_consumer_group {
    state "API request" as financial_consumer_api_call
    [*] --> financial_consumer_api_call
}

state "Services" as service {
    state "Auth Service REST API" as auth
    state "Financial Service REST API" as financial
}

auth_consumer_api_call --> auth: login or refresh token
auth --> auth_consumer_api_call: access token
financial_consumer_api_call --> financial: request + access token
financial --> financial_consumer_api_call: financial data

state "Infrastructure" as storage {
    state "Auth Database" as auth_db
    state "Cache" as cache
    state "Financial Database" as financial_db
}

auth --> auth_db
auth --> cache
financial --> cache
financial --> financial_db
Loading

DevOps flow

  1. Development: lint, unit and integration tests (Jest), adds a coverage report as github pull request comment
  2. Staging: E2E test (Supertest) using Testcontainers to replicate external dependencies
  3. Production: build all services, create Docker images, and deploy them to Docker Hub
stateDiagram-v2
direction LR

classDef dev_style fill:#7f51ce
classDef staging_style fill:#e3942a
classDef prod_style fill:green

state "Development" as development_stage

[*] --> development_stage

state "GitHub Actions • Development" as github_dev_stage {
    state "Lint code" as lint
    state "Unit test" as unit
    state "Integration test" as integration
    state "Coverage report" as coverage
    [*] --> lint
    lint --> unit
    unit --> integration
    integration --> coverage
    coverage --> [*]
}
github_dev_stage:::dev_style

development_stage --> github_dev_stage

state "Staging" as staging_stage

github_dev_stage --> staging_stage

state "GitHub Actions • Staging" as github_staging_stage {
    state "Setup Testcontainers" as testcontainers
    state "e2e Tests" as e2e_tests
    [*] --> testcontainers
    testcontainers --> e2e_tests
    e2e_tests --> [*]
}
github_staging_stage:::staging_style

staging_stage --> github_staging_stage

state "Production" as prod_stage

github_staging_stage --> prod_stage

state "GitHub Actions • Production" as github_prod_stage {
    state "Build code" as build_code
	state "Create Docker images" as docker_images
	state "Deploy do DockerHub" as docker_hub
	[*] --> build_code
	build_code --> docker_images
	docker_images --> docker_hub
	docker_hub --> [*]
}
github_prod_stage:::prod_style

prod_stage --> github_prod_stage
github_prod_stage --> [*]
Loading

Documentation

About

Implements an authentication REST API using NestJS. Tests with Jest, Supertest and Testcontainers. CI/CD with GitHub Actions to automate testing and deployment process

Topics

Resources

Stars

Watchers

Forks