# tigranbs/nestjs-cookie-jwt-example architecture

> Architecture diagram of the GitHub repository tigranbs/nestjs-cookie-jwt-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tigranbs/nestjs-cookie-jwt-example
- Repository: https://github.com/tigranbs/nestjs-cookie-jwt-example

## Overview

##### Project type and purpose
- This is a Node.js/TypeScript server-side application built on the NestJS framework.
- It serves as a starter backend API with built-in modules for authentication (JWT), controllers, and services.

##### File structure
- Top-level config files:
- nest-cli.json (Nest CLI configuration)
- tsconfig.json / tsconfig.build.json (TypeScript compiler settings)
- package.json / package-lock.json (dependencies and scripts)
- .eslintrc.js, .prettierrc (linting and formatting)
- src/ (application source)
- main.ts – bootstraps the Nest application
- app.module.ts – root module that aggregates sub-modules and providers
- app.controller.ts & app.service.ts – example controller and business-logic provider
- auth/
– auth.module.ts – encapsulates authentication concerns
– auth.controller.ts – authentication endpoints (e.g., login)
– jwt.strategy.ts – Passport strategy for JWT validation
– guards.ts – route guards for protecting endpoints
- test/
- e2e-spec.ts – end-to-end tests
- jest-e2e.json – test framework configuration

##### Extract insights from the README
- Confirms it’s a NestJS TypeScript starter repo.

a. Main components
1. Client (e.g., REST client, Postman, frontend UI)
2. NestJS HTTP Server
– Controllers layer (app.controller, auth.controller)
– Services/providers layer (app.service, AuthService, JWT strategy)
– Guards (authorization logic)
3. (Optional) Persistence layer – e.g., TypeORM/Mongoose module you’d add
5. CI/CD pipeline (CircleCI badge indicates integration potential)
b. Relationships & data flow
- Client → HTTP request → Controller
- Controller → calls Service (business logic)
- Service ↔ (optional) Database adapter/repository
- AuthController / Guards ↔ JWT Strategy → validate token against secret or user store
- Service returns data → Controller → HTTP response → Client
c. Architectural patterns & principles
- Modular design: each domain (Auth, App) in its own Nest module
- Dependency injection: modules declare providers that NestDI injects
- Layered architecture: Controllers (API layer) → Services (business layer) → Persistence (data layer)
- Guard/Strategy pattern for pluggable authentication
d. Key technologies/frameworks
- NestJS core: Modules, Controllers, Providers
- Passport.js JWT strategy (jwt.strategy.ts)
- TypeScript for static types
- Jest for unit and e2e testing
- Optional: ORM (TypeORM/Mongoose) if added later

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Entities
    Client("Client (REST UI / Postman)"):::external
    DB["Database Module (placeholder)"]:::external
    Identity["External Identity Provider"]:::external

    %% Bootstrap
    Main["Bootstrap (main.ts)"]:::service

    %% NestJS Application
    subgraph "NestJS Application"
        subgraph "App Module"
            AController["App Controller"]:::api
            AService["App Service"]:::service
        end
        subgraph "Auth Module"
            AuthController["Auth Controller"]:::api
            AuthService["Auth Service"]:::service
            JWTStrategy["JWT Strategy"]:::auth
            Guards["Route Guards"]:::auth
        end
    end

    %% Test Harness
    Test["E2E Tests (jest)"]:::tool

    %% Tooling & Configurations
    subgraph "Tooling & Config"
        NestCLI["nest-cli.json"]:::tool
        TSConfig1["tsconfig.json"]:::tool
        TSConfig2["tsconfig.build.json"]:::tool
        ESLint[".eslintrc.js"]:::tool
        Prettier[".prettierrc"]:::tool
        Package1["package.json"]:::tool
        Package2["package-lock.json"]:::tool
        JestConfig["test/jest-e2e.json"]:::tool
    end

    %% Relationships
    Client -->|"HTTP Request"| AController
    Client -->|"HTTP Request"| AuthController
    AController -->|"calls"| AService
    AuthController -->|"calls"| AuthService
    AuthService -->|"validateToken via"| JWTStrategy
    Guards -->|"uses"| JWTStrategy
    AuthController -->|"protected by"| Guards
    AService -->|"queries"| DB
    Main -->|"bootstraps"| AController
    Main -->|"bootstraps"| AuthController
    Main -->|"initializes"| AService
    Main -->|"initializes"| AuthService
    Test -->|"runs E2E against"| Main

    %% Click Events
    click Main "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/src/main.ts"
    click AController "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/src/app.controller.ts"
    click AService "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/src/app.service.ts"
    click NestCLI "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/nest-cli.json"
    click TSConfig1 "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/tsconfig.json"
    click TSConfig2 "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/tsconfig.build.json"
    click ESLint "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/.eslintrc.js"
    click Prettier "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/.prettierrc"
    click Package1 "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/package.json"
    click Package2 "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/package-lock.json"
    click AuthController "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/src/auth/auth.controller.ts"
    click JWTStrategy "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/src/auth/jwt.strategy.ts"
    click Guards "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/src/auth/guards.ts"
    click Test "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/test/app.e2e-spec.ts"
    click JestConfig "https://github.com/tigranbs/nestjs-cookie-jwt-example/blob/main/test/jest-e2e.json"

    %% Styles
    classDef external fill:#D3D3F5,stroke:#666,stroke-width:1px
    classDef api fill:#B3D9FF,stroke:#666,stroke-width:1px
    classDef service fill:#CCFFCC,stroke:#666,stroke-width:1px
    classDef auth fill:#FFD9B3,stroke:#666,stroke-width:1px
    classDef tool fill:#E0E0E0,stroke:#666,stroke-width:1px
```
