# legbabe/access-key-management- architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack Node.js web application (“Access Key Manager”) built to allow school IT personnel and Micro-Focus admins to manage license/access keys via a web UI and an HTTP endpoint.
- It follows an MVC–style structure: Express.js backend (controllers, routes, middleware, models), EJS templates for server-side rendering, and a public folder for static assets (CSS, JS, images).
- It exposes both browser-driven UI flows (signup, login, key management, password reset) and a machine-to-machine endpoint (/getActiveKey/:email) for external integration.

##### File structure
- Top level
– app.js (Express application entry point)
– package.json / package-lock.json
– vercel.json (deployment config)
- backend/
– controllers/ (auth_controller.js, key_controller.js)
– routes/ (auth_routes.js, key_routes.js)
– middleware/ (authMiddleware.js)
– models/ (user_model.js, token_model.js)
- public/ (static CSS, JS, images)
- views/ (EJS templates by role and function: signup, login, admin_home, key views, password reset)
- tests/ (Jest or Mocha tests for authentication flows)

##### README for additional insights
- Customer requirements for two personas: School IT Personnel and Micro-Focus Admin.
- Key features: signup/login, single-active-key constraint, view/revoke keys, reset password, machine endpoint.

##### Main components & their relationships
a. Client web browser
- Requests static HTML/CSS/JS (public/) and server-rendered pages (views/).
b. Web Server (app.js + Express)
- Routes incoming HTTP requests via auth_routes and key_routes.
- Runs middleware (authMiddleware) to protect routes.
- Invokes controller logic (signup/login/reset in auth_controller; generate/list/revoke in key_controller).
c. Data layer
- Models (user_model, token_model) abstract persistence with the database (e.g., Postgres, MySQL, Mongo).
d. External dependencies
- Email service (for account verification and password reset).
- Third-party integration via /getActiveKey/:email endpoint used by the school platform.

##### Architectural patterns & design principles
- MVC / Layered Architecture:
Presentation (views, public) → Application/Business Logic (controllers, services) → Data (models, database).
- Single Responsibility: each controller or middleware handles one concern.
- RESTful endpoints for key operations.
- Separation of concerns: static assets vs. dynamic views vs. API endpoints.
- Security: middleware for authentication, token-based sessions or JWT (implied by token_model).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Client Browser"]:::client
    end

    %% Express Server Layer
    subgraph "Express Server"
        direction TB
        App["app.js"]:::server
        subgraph "Routes Layer"
            direction TB
            AuthRoutes["auth_routes.js"]:::server
            KeyRoutes["key_routes.js"]:::server
        end
        subgraph "Middleware Layer"
            direction TB
            AuthMiddleware["authMiddleware.js"]:::server
        end
        subgraph "Controllers Layer"
            direction TB
            AuthController["auth_controller.js"]:::server
            KeyController["key_controller.js"]:::server
        end
    end

    %% Persistence Layer
    subgraph "Database"
        direction TB
        Users[(Users)]:::db
        Tokens[(Tokens)]:::db
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        EmailService["Email Service"]:::external
        ExternalClient["External Client"]:::external
    end

    %% Connections
    Browser -->|"/signup, /login, /reset_password, /home, /admin_home, /generate_key"| AuthRoutes
    Browser -->|"/getActiveKey/:email"| KeyRoutes
    AuthRoutes -->|calls| AuthMiddleware
    KeyRoutes -->|calls| AuthMiddleware
    AuthMiddleware -->|auth check| AuthController
    AuthMiddleware -->|auth check| KeyController
    AuthController -->|CRUD Users| Users
    AuthController -->|CRUD Tokens| Tokens
    KeyController -->|CRUD Tokens| Tokens
    AuthController -->|send email| EmailService
    ExternalClient -->|"GET /getActiveKey/:email"| KeyController
    AuthController -->|render views| Browser
    KeyController -->|render views| Browser

    %% Click Events
    click App "https://github.com/legbabe/access-key-management-/blob/main/app.js"
    click AuthRoutes "https://github.com/legbabe/access-key-management-/blob/main/backend/routes/auth_routes.js"
    click KeyRoutes "https://github.com/legbabe/access-key-management-/blob/main/backend/routes/key_routes.js"
    click AuthMiddleware "https://github.com/legbabe/access-key-management-/blob/main/backend/middleware/authMiddleware.js"
    click AuthController "https://github.com/legbabe/access-key-management-/blob/main/backend/controllers/auth_controller.js"
    click KeyController "https://github.com/legbabe/access-key-management-/blob/main/backend/controllers/key_controller.js"
    click UserModel "https://github.com/legbabe/access-key-management-/blob/main/backend/models/user_model.js"
    click TokenModel "https://github.com/legbabe/access-key-management-/blob/main/backend/models/token_model.js"
    click StaticAssets "https://github.com/legbabe/access-key-management-/tree/main/public/"
    click Views "https://github.com/legbabe/access-key-management-/tree/main/views/"
    click AuthTests "https://github.com/legbabe/access-key-management-/blob/main/tests/auth.test.js"
    click Vercel "https://github.com/legbabe/access-key-management-/blob/main/vercel.json"
    click PackageJSON "https://github.com/legbabe/access-key-management-/blob/main/package.json"
    click PackageLock "https://github.com/legbabe/access-key-management-/blob/main/package-lock.json"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,color:#004085
    classDef server fill:#d4edda,stroke:#155724,color:#155724
    classDef db fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24
```
