# stepsisstuck/bed-lab5 architecture

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

- Interactive diagram: https://gitdiagram.com/stepsisstuck/bed-lab5
- Repository: https://github.com/stepsisstuck/bed-lab5

## Overview

##### Project type and purpose
- This is a Node.js backend RESTful API using Express.
- Its purpose is to expose CRUD endpoints for game-oriented entities (users, classes, quests, spells, questions, answers, customizations, and character progression).

##### File structure
- Top-level files:
- index.js – entry point, likely starts the Express server.
- package.json, package-lock.json – npm metadata.
- readme.md – minimal instructions.
- src/ directory follows an MVC-like organization:
- src/configs – setup scripts (e.g., database table initialization).
- src/services – low-level utilities (db.js handles DB connection).
- src/models – data models for each domain entity.
- src/controllers – business logic and request handling per entity.
- src/routes – Express route definitions, grouping endpoints by entity.
- src/app.js – Express app configuration: middleware, route mounting.

##### README
- Minimal content; no architecture details.
- Relies on folder structure to convey design.

##### Detailed breakdown of the components (to capture essential elements)
- index.js: boots Express, imports src/app.js.
- src/app.js: configures middleware (body-parser, CORS), mounts routes from src/routes/*.js.
- src/routes/*.js: defines REST endpoints, points to controller functions.
- src/controllers/*Controller.js: handles incoming data, calls src/models or src/services.
- src/services/db.js: establishes DB connection pool, exports query methods.
- src/configs/initTables.js: runs DDL on startup to ensure tables exist.
- src/models/*.js: define table schemas or model classes used by controllers or services.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Client
    Client["API Consumer"]:::external

    %% Entry and Startup
    Client --> Index
    subgraph "Startup & Entry"  
        Index["index.js"]:::config
        App["src/app.js"]:::http
        Init["src/configs/initTables.js"]:::config
    end
    Index -->|"imports"| App
    Index -->|"runs at startup"| Init
    Init -->|"initializes DB schema"| DBService

    %% Router Layer
    subgraph "Router Layer"  
        MainRoutes["mainRoutes.js"]:::http
        UserRoutes["userRoutes.js"]:::http
        ClassRoutes["classRoutes.js"]:::http
        QuestRoutes["questRoutes.js"]:::http
        SpellRoutes["spellRoutes.js"]:::http
        QuestionRoutes["questionsRoutes.js"]:::http
        CustomRoutes["customizationRoutes.js"]:::http
    end
    App -->|"mounts"| MainRoutes
    MainRoutes --> UserRoutes
    MainRoutes --> ClassRoutes
    MainRoutes --> QuestRoutes
    MainRoutes --> SpellRoutes
    MainRoutes --> QuestionRoutes
    MainRoutes --> CustomRoutes

    %% Controller Layer
    subgraph "Controller Layer"
        UserCtrl["userController.js"]:::http
        ClassCtrl["classController.js"]:::http
        QuestCtrl["questController.js"]:::http
        SpellCtrl["spellController.js"]:::http
        QuestionCtrl["questionController.js"]:::http
        AnswerCtrl["answerController.js"]:::http
        CustomCtrl["customizationController.js"]:::http
    end
    UserRoutes --> UserCtrl
    ClassRoutes --> ClassCtrl
    QuestRoutes --> QuestCtrl
    SpellRoutes --> SpellCtrl
    QuestionRoutes --> QuestionCtrl
    QuestionCtrl --> AnswerCtrl
    CustomRoutes --> CustomCtrl

    %% Service & DB Layer
    subgraph "Service & DB"
        DBService["src/services/db.js"]:::data
        Models["Data Models"]:::data
    end
    UserCtrl -->|"queries"| DBService
    ClassCtrl --> DBService
    QuestCtrl --> DBService
    SpellCtrl --> DBService
    QuestionCtrl --> DBService
    AnswerCtrl --> DBService
    CustomCtrl --> DBService

    %% Models
    subgraph "Models"
        UserModel["userModel.js"]:::data
        ClassModel["classModel.js"]:::data
        QuestModel["questModel.js"]:::data
        SpellModel["spellModel.js"]:::data
        QuestionModel["questionModel.js"]:::data
        AnswerModel["answerModel.js"]:::data
        CustomModel["customizationModel.js"]:::data
        ProgressModel["characterProgressionModel.js"]:::data
    end
    DBService -->|"maps to"| UserModel
    DBService --> ClassModel
    DBService --> QuestModel
    DBService --> SpellModel
    DBService --> QuestionModel
    DBService --> AnswerModel
    DBService --> CustomModel
    DBService --> ProgressModel
    DBService -->|"executes SQL"| Database

    %% External Database
    Database["Database"]:::external

    %% Click events
    click Index "https://github.com/stepsisstuck/bed-lab5/blob/main/index.js"
    click App "https://github.com/stepsisstuck/bed-lab5/blob/main/src/app.js"
    click Init "https://github.com/stepsisstuck/bed-lab5/blob/main/src/configs/initTables.js"
    click MainRoutes "https://github.com/stepsisstuck/bed-lab5/blob/main/src/routes/mainRoutes.js"
    click UserRoutes "https://github.com/stepsisstuck/bed-lab5/blob/main/src/routes/userRoutes.js"
    click ClassRoutes "https://github.com/stepsisstuck/bed-lab5/blob/main/src/routes/classRoutes.js"
    click QuestRoutes "https://github.com/stepsisstuck/bed-lab5/blob/main/src/routes/questRoutes.js"
    click SpellRoutes "https://github.com/stepsisstuck/bed-lab5/blob/main/src/routes/spellRoutes.js"
    click QuestionRoutes "https://github.com/stepsisstuck/bed-lab5/blob/main/src/routes/questionsRoutes.js"
    click CustomRoutes "https://github.com/stepsisstuck/bed-lab5/blob/main/src/routes/customizationRoutes.js"
    click UserCtrl "https://github.com/stepsisstuck/bed-lab5/blob/main/src/controllers/userController.js"
    click ClassCtrl "https://github.com/stepsisstuck/bed-lab5/blob/main/src/controllers/classController.js"
    click QuestCtrl "https://github.com/stepsisstuck/bed-lab5/blob/main/src/controllers/questController.js"
    click SpellCtrl "https://github.com/stepsisstuck/bed-lab5/blob/main/src/controllers/spellController.js"
    click QuestionCtrl "https://github.com/stepsisstuck/bed-lab5/blob/main/src/controllers/questionController.js"
    click AnswerCtrl "https://github.com/stepsisstuck/bed-lab5/blob/main/src/controllers/answerController.js"
    click CustomCtrl "https://github.com/stepsisstuck/bed-lab5/blob/main/src/controllers/customizationController.js"
    click DBService "https://github.com/stepsisstuck/bed-lab5/blob/main/src/services/db.js"
    click UserModel "https://github.com/stepsisstuck/bed-lab5/blob/main/src/models/userModel.js"
    click ClassModel "https://github.com/stepsisstuck/bed-lab5/blob/main/src/models/classModel.js"
    click QuestModel "https://github.com/stepsisstuck/bed-lab5/blob/main/src/models/questModel.js"
    click SpellModel "https://github.com/stepsisstuck/bed-lab5/blob/main/src/models/spellModel.js"
    click QuestionModel "https://github.com/stepsisstuck/bed-lab5/blob/main/src/models/questionModel.js"
    click AnswerModel "https://github.com/stepsisstuck/bed-lab5/blob/main/src/models/answerModel.js"
    click CustomModel "https://github.com/stepsisstuck/bed-lab5/blob/main/src/models/customizationModel.js"
    click ProgressModel "https://github.com/stepsisstuck/bed-lab5/blob/main/src/models/characterProgressionModel.js"

    %% Styling
    classDef http fill:#E3F2FD,stroke:#1976D2,color:#0D47A1
    classDef data fill:#FFF3E0,stroke:#EF6C00,color:#E65100
    classDef config fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
    classDef external fill:#FFEBEE,stroke:#C62828,color:#B71C1C
```
