# adityagaddhyan/access-key-management-repo architecture

> Architecture diagram of the GitHub repository adityagaddhyan/access-key-management-repo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adityagaddhyan/access-key-management-repo
- Repository: https://github.com/adityagaddhyan/access-key-management-repo

## Overview

##### Project type and purpose
- From the file tree and README we see a single codebase built with NestJS (TypeScript), exposing a JSON/REST API documented via Swagger/Postman.
- There is no “frontend” folder; this is a backend service (a modular monolith or microservice) whose job is to manage “keys” (CRUD operations) and secure endpoints via JWT-based authentication.

##### File structure
- src/main.ts: application bootstrap
- src/app.module.ts: root NestJS module
- src/auth: JWT‐based AuthModule with controller, service, guard and strategy
- src/entity: key.entity.ts (data model definition)
- src/key-service: KeyServiceModule, subdivided into
- key.controller.ts (HTTP endpoints)
- key.service.ts (business logic)
- repo/key.repo.ts (data access layer)
- database/database.module.ts + database.ts (database provider/connection)
- setup.sql: initial schema
- swagger-spec.json & Postman link: API docs

##### Key insights from the README
- The only guidance is how to view the auto‐generated docs (via Swagger or Postman)

- Client(s) (Swagger UI, Postman, any HTTP client)
- NestJS Application (single process)
– API Gateway (mapped 1:1 to app.controller or can be omitted if unused)
– AuthModule
– KeyServiceModule
· KeyController
· KeyService (business layer)
· KeyRepository (data layer)
– DatabaseModule (shared DB connection provider)
- Relational Database (PostgreSQL or other SQL RDB)

b. Relationships & interactions
- Clients → HTTP REST endpoints on KeyController & AuthController
- AuthController calls AuthService → JWT strategy → issues/verifies tokens
- KeyController methods are protected by AuthGuard → KeyService → KeyRepository
- KeyRepository performs SQL queries via the DatabaseModule pool

c. Architectural patterns/principles
- Layered architecture:
· Presentation layer (Controllers)
· Application/Service layer (Services)
· Data access layer (Repositories)
- Modular design: each feature (auth, key-service) in its own NestJS module
- Declarative security using Guards & Strategies
- DTOs for input validation & output shaping

d. Relevant technologies/frameworks
- NestJS (Module / Controller / Service)
- TypeScript
- JWT (passport-jwt strategy)
- SQL database driver (via DatabaseModule)
- Swagger (auto‐generated from decorators)

##### Final remarks
- This will give any reader a clear, accurate view of how requests traverse from the client through NestJS layers down to the database.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global Entities
    Clients["Clients\n(Swagger UI, Postman, HTTP Client)"]:::external
    Database["Relational Database\n(PostgreSQL)"]:::external
    SwaggerSpec["Swagger Spec\nswagger-spec.json"]:::external
    PostmanColl["Postman Collection\nREADME.md"]:::external

    %% Bootstrap & Root Module
    main["Application Bootstrap\n(src/main.ts)"]:::bootstrap
    app["App Module\n(src/app.module.ts)"]:::module

    main -->|boots| app

    %% Auth Module
    subgraph "Auth Module"
        direction TB
        authCtrl["Auth Controller\n(src/auth/auth.controller.ts)"]:::controller
        authService["Auth Service\n(src/auth/auth.service.ts)"]:::service
        authGuard["Auth Guard\n(src/auth/auth.guard.ts)"]:::guard
        jwtStrat["JWT Strategy\n(src/auth/jwt.strategy.ts)"]:::strategy
    end

    app -->|imports| authCtrl
    authCtrl -->|calls| authService
    authService -->|uses| jwtStrat
    authGuard -->|protects| authCtrl

    %% Key-Service Module
    subgraph "Key-Service Module"
        direction TB
        keyCtrl["Key Controller\n(src/key-service/key.controller.ts)"]:::controller
        keyService["Key Service\n(src/key-service/key.service.ts)"]:::service
        keyRepo["Key Repository\n(src/key-service/repo/key.repo.ts)"]:::repository
        subgraph "DTOs"
            direction LR
            dto1["create-key.dto.ts"]:::dto
            dto2["key-details.dto.ts"]:::dto
            dto3["update-key.dto.ts"]:::dto
        end
        keyEntity["Key Entity\n(src/entity/key.entity.ts)"]:::entity
    end

    app -->|imports| keyCtrl
    keyCtrl -->|calls| keyService
    keyService -->|calls| keyRepo
    keyRepo -->|maps to| keyEntity
    keyRepo -->|executes SQL| dbModule

    %% Database Module
    subgraph "Database Module"
        direction TB
        dbModule["Database Module\n(src/key-service/database/database.module.ts)"]:::module
        dbProvider["Database Provider\n(src/key-service/database/database.ts)"]:::provider
    end

    app -->|imports| dbModule
    dbModule -->|provides| dbProvider
    dbProvider -->|connects to| Database

    %% Client interactions
    Clients -->|HTTP /auth/*| authCtrl
    Clients -->|HTTP /key/*| keyCtrl

    %% Docs links
    Clients -->|views docs| SwaggerSpec
    Clients -->|views collection| PostmanColl

    %% Click Events
    click main "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/main.ts"
    click app "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/app.module.ts"
    click authCtrl "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/auth/auth.controller.ts"
    click authService "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/auth/auth.service.ts"
    click authGuard "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/auth/auth.guard.ts"
    click jwtStrat "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/auth/jwt.strategy.ts"
    click keyCtrl "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/key-service/key.controller.ts"
    click keyService "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/key-service/key.service.ts"
    click keyRepo "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/key-service/repo/key.repo.ts"
    click keyEntity "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/entity/key.entity.ts"
    click dto1 "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/key-service/dto/create-key.dto.ts"
    click dto2 "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/key-service/dto/key-details.dto.ts"
    click dto3 "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/key-service/dto/update-key.dto.ts"
    click dbModule "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/key-service/database/database.module.ts"
    click dbProvider "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/src/key-service/database/database.ts"
    click SwaggerSpec "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/swagger-spec.json"
    click PostmanColl "https://github.com/adityagaddhyan/access-key-management-repo/blob/main/README.md"

    %% Styles
    classDef external fill:#E8F1F2,stroke:#333,stroke-width:1px
    classDef bootstrap fill:#D6E9C6,stroke:#333,stroke-width:1px
    classDef module fill:#BEE5EB,stroke:#333,stroke-width:1px
    classDef controller fill:#FFD59E,stroke:#333,stroke-width:1px
    classDef service fill:#FFE8A1,stroke:#333,stroke-width:1px
    classDef guard fill:#FFDDC1,stroke:#333,stroke-width:1px
    classDef strategy fill:#F6CED8,stroke:#333,stroke-width:1px
    classDef repository fill:#C3D9E0,stroke:#333,stroke-width:1px
    classDef provider fill:#D1E7DD,stroke:#333,stroke-width:1px
    classDef entity fill:#E2D1F9,stroke:#333,stroke-width:1px
    classDef dto fill:#F5E1A4,stroke:#333,stroke-width:1px
```
