# jniet11/kata-personnel-management-api-mngr architecture

> Architecture diagram of the GitHub repository jniet11/kata-personnel-management-api-mngr, 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/jniet11/kata-personnel-management-api-mngr
- Repository: https://github.com/jniet11/kata-personnel-management-api-mngr

## Overview

##### Project type and purpose
- This is a backend RESTful API service (no UI) built with Node.js, Express and TypeScript.
- Its purpose is to manage personnel data, access-request workflows, and computing-equipment assignments, persisting data in MySQL.
- It exposes CRUD endpoints secured via JWT authentication.

##### File structure
- Top-level:
– src/: TypeScript source
- config/db.ts – DB connection & initialization
- app.ts – Express app setup & middleware mounting
- server.ts – Entry point (starts HTTP server)
- controllers/: Business logic per resource (users, auth, access-requests, assignments)
- routes/: HTTP route definitions pointing to controllers
- middleware/authMiddleware.ts – JWT verification
- scripts/hash.ts – Password hashing utility
– dist/: Compiled JavaScript with equivalent structure
– tsconfig.json, package.json, README, .gitignore, LICENSE
- The layout follows a simple MVC/flavored-layered pattern:
Routes → Controllers (business logic) → Config (DB) → MySQL

##### README for additional insights
- Describes entities: Users, AccessRequests, Assignments, Computers
- Explains JWT authentication (login flow, middleware protection)
- Notes use of MySQL2 with pooling & transactions for data integrity

##### Final recommendations
- Be granular: include each controller or group them by domain (Users, AccessRequests, Assignments).
- External dependencies: environment variables (.env) feeding the DB config and JWT secret.
- Keep it up-to-date: regenerate when new modules/controllers are added.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Components
    client["API Client"]:::component
    gateway["API Gateway/Load Balancer"]:::component
    server["Server Entry Point (src/server.ts)"]:::component
    app["Express Application Setup (src/app.ts)"]:::component

    %% Express API Server Layers
    subgraph "Express API Server"
        direction TB
        routes["Personnel Management Routes"]:::layer
        authMiddleware["Authentication Middleware"]:::layer
        createUserCtrl["Create User Controller"]:::layer
        authCtrl["Authentication Controller"]:::layer
        accessReqCtrl["Access Requests Controller"]:::layer
        assignCtrl["Assignments Controller"]:::layer
        dbConfig["Database Configuration"]:::layer
        hashScript["Password Hashing Utility"]:::layer
    end

    %% Environment Variables
    env[".env Variables"]:::infrastructure

    %% Database
    db["MySQL Database"]:::db

    %% Connections
    client -->|HTTP/JSON| gateway
    gateway -->|HTTP/JSON| server
    server --> app
    app --> routes
    routes --> authMiddleware
    authMiddleware --> createUserCtrl
    authMiddleware --> authCtrl
    authMiddleware --> accessReqCtrl
    authMiddleware --> assignCtrl

    routes --> createUserCtrl
    routes --> authCtrl
    routes --> accessReqCtrl
    routes --> assignCtrl

    createUserCtrl -->|SQL Queries| dbConfig
    authCtrl -->|SQL Queries| dbConfig
    accessReqCtrl -->|SQL Queries| dbConfig
    assignCtrl -->|Transactional SQL| dbConfig

    dbConfig -->|Connection Pool| db

    createUserCtrl -->|bcryptjs| hashScript
    authCtrl -->|bcryptjs & JWT| hashScript

    authCtrl -->|issues JWT| client
    client -->|Bearer Token| routes

    env --> dbConfig
    env --> authMiddleware

    %% Click Events
    click dbConfig "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/config/db.ts"
    click app "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/app.ts"
    click server "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/server.ts"
    click authMiddleware "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/middleware/authMiddleware.ts"
    click hashScript "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/scripts/hash.ts"
    click createUserCtrl "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/controllers/createUserController.ts"
    click authCtrl "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/controllers/authController.ts"
    click accessReqCtrl "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/controllers/accessRequestController.ts"
    click assignCtrl "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/controllers/assignmentController.ts"
    click routes "https://github.com/jniet11/kata-personnel-management-api-mngr/blob/main/src/routes/personnelManagementRoutes.ts"

    %% Legend and Technologies
    subgraph Legend
        direction TB
        A["Blue: External Components"]:::component
        B["Green: Server Layers"]:::layer
        C["Orange: Database"]:::db
        tech["Technologies: Node.js, TypeScript, Express.js, MySQL2, jsonwebtoken, bcryptjs, dotenv"]:::note
    end

    %% Styles
    classDef component fill:#bbdefb,stroke:#1e88e5;
    classDef layer fill:#c8e6c9,stroke:#388e3c;
    classDef db fill:#ffe0b2,stroke:#f57c00;
    classDef infrastructure fill:#f3e5f5,stroke:#8e24aa;
    classDef note fill:#e0e0e0,stroke:#9e9e9e;
```
