Skip to content

Latest commit

 

History

History
172 lines (135 loc) · 6.99 KB

README.md

File metadata and controls

172 lines (135 loc) · 6.99 KB

POC NestJS

REST 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, designed for scalability and maintainability. Key features include a modular, testable architecture; comprehensive unit and integration testing with Jest to ensure code quality; 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

Technology 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 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 {
    state "Code" as dev_code
    state "Commit" as dev_commit
    state "Pull Request" as dev_pr
    [*] --> dev_code
    dev_code --> dev_commit
    dev_commit --> dev_pr
    dev_pr --> [*]
}
development_stage:::dev_style

[*] --> 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 {
    state "Pull Request" as staging_pr
    [*] --> staging_pr
    staging_pr --> [*]
}
staging_stage:::staging_style

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 {
    state "Pull Request" as prod_pr
    [*] --> prod_pr
    prod_pr --> [*]
}
prod_stage:::prod_style

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