# stepsisstuck/sb architecture

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

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

## Overview

##### Project type and purpose
- This is a Node.js backend REST API (Express) that follows an MVC-style separation.
- It exposes endpoints for managing Users, GameUsers, Quests, Reports, and Vulnerabilities.
- There is no frontend here—this service is meant to be consumed by external clients (web/mobile).

##### File structure
- index.js: entry point that starts the Express server.
- src/app.js: configures Express, middleware, and mounts mainRoutes.
- src/routes: each file (GameUsersRoutes, QuestsRoutes, etc.) defines HTTP endpoints; mainRoutes.js aggregates and “routes to others.”
- src/controllers: business-logic handlers invoked by routes.
- src/models: database access for each domain object (User, GameUsers, etc.)—likely raw SQL or a query builder.
- src/services/db.js: central database connection manager.
- src/configs: scripts to create schema, initialize tables, and define lookup data (levels).

##### Key architectural patterns and design principles
- Layered architecture (Route → Controller → Model → DB).
- Single responsibility per layer and per module: routes only parse the request, controllers orchestrate logic, models handle persistence.
- Config scripts initialize and seed the database before the service runs.
- mainRoutes.js serves as the “router of routers,” forwarding traffic to each feature’s router.

##### Elements
- Clear labels: “Express Server,” “mainRoutes,” “UserRoutes,” “UserController,” “UserModel,” “DB Connection,” “Database.”
- Orange for Models
- Purple for Config scripts

##### Detailed callouts
- Call out that mainRoutes.js simply aggregates and delegates to GameUsersRoutes, QuestsRoutes, reportRoutes, userRoutes, vulnerabilityRoutes.
- A note that levels.js populates reference data (lookup table) in the Database at init time.

## Diagram (Mermaid)

```mermaid
flowchart TB
    ExternalClient["External Client"]:::external

    subgraph "Server Layer"
        ExIndex["index.js"]:::server
        App["src/app.js\n(Express App)"]:::server
    end

    ExternalClient --> ExIndex
    ExIndex --> App

    subgraph "Routing Layer"
        MainRoutes["mainRoutes.js"]:::routing
        UserRoutes["userRoutes.js"]:::routing
        GameUsersRoutes["GameUsersRoutes.js"]:::routing
        QuestsRoutes["QuestsRoutes.js"]:::routing
        ReportRoutes["reportRoutes.js"]:::routing
        VulnerabilityRoutes["vulnerabilityRoutes.js"]:::routing
    end

    App --> MainRoutes
    MainRoutes -->|"routes to"| UserRoutes
    MainRoutes -->|"routes to"| GameUsersRoutes
    MainRoutes -->|"routes to"| QuestsRoutes
    MainRoutes -->|"routes to"| ReportRoutes
    MainRoutes -->|"routes to"| VulnerabilityRoutes

    subgraph "Controller Layer"
        UserController["userController.js"]:::controller
        GameUsersController["GameUsersController.js"]:::controller
        QuestsController["questsController.js"]:::controller
        ReportController["reportController.js"]:::controller
        VulnerabilityController["vulnerabilityController.js"]:::controller
    end

    UserRoutes --> UserController
    GameUsersRoutes --> GameUsersController
    QuestsRoutes --> QuestsController
    ReportRoutes --> ReportController
    VulnerabilityRoutes --> VulnerabilityController

    subgraph "Model Layer"
        UserModel["userModel.js"]:::model
        GameUsersModel["GameUsersModel.js"]:::model
        QuestsModel["questsModel.js"]:::model
        ReportModel["reportModel.js"]:::model
        VulnerabilityModel["vulnerabilityModel.js"]:::model
    end

    UserController --> UserModel
    GameUsersController --> GameUsersModel
    QuestsController --> QuestsModel
    ReportController --> ReportModel
    VulnerabilityController --> VulnerabilityModel

    DBConn["src/services/db.js\n(Database Connection)"]:::dbsvc
    UserModel --> DBConn
    GameUsersModel --> DBConn
    QuestsModel --> DBConn
    ReportModel --> DBConn
    VulnerabilityModel --> DBConn

    Database["Database\n(PostgreSQL/MySQL)"]:::database
    DBConn --> Database

    subgraph "Config & Initialization"
        Schema["createSchema.js"]:::config
        InitTables["initTables.js"]:::config
        Levels["levels.js"]:::config
        Env[".env"]:::config
    end

    Schema --> DBConn
    InitTables --> DBConn
    Levels --> DBConn
    Env --> DBConn

    subgraph "Legend"
        direction LR
        R["Routing Layer"]:::routing
        C["Controller Layer"]:::controller
        M["Model Layer"]:::model
        S["Server Layer"]:::server
        DBC["DB Connection"]:::dbsvc
        DBL["Database"]:::database
        CF["Config Scripts"]:::config
        EX["External Client"]:::external
    end

    click ExIndex "https://github.com/stepsisstuck/sb/blob/main/index.js"
    click App "https://github.com/stepsisstuck/sb/blob/main/src/app.js"
    click MainRoutes "https://github.com/stepsisstuck/sb/blob/main/src/routes/mainRoutes.js"
    click UserRoutes "https://github.com/stepsisstuck/sb/blob/main/src/routes/userRoutes.js"
    click GameUsersRoutes "https://github.com/stepsisstuck/sb/blob/main/src/routes/GameUsersRoutes.js"
    click QuestsRoutes "https://github.com/stepsisstuck/sb/blob/main/src/routes/QuestsRoutes.js"
    click ReportRoutes "https://github.com/stepsisstuck/sb/blob/main/src/routes/reportRoutes.js"
    click VulnerabilityRoutes "https://github.com/stepsisstuck/sb/blob/main/src/routes/vulnerabilityRoutes.js"
    click UserController "https://github.com/stepsisstuck/sb/blob/main/src/controllers/userController.js"
    click GameUsersController "https://github.com/stepsisstuck/sb/blob/main/src/controllers/GameUsersController.js"
    click QuestsController "https://github.com/stepsisstuck/sb/blob/main/src/controllers/questsController.js"
    click ReportController "https://github.com/stepsisstuck/sb/blob/main/src/controllers/reportController.js"
    click VulnerabilityController "https://github.com/stepsisstuck/sb/blob/main/src/controllers/vulnerabilityController.js"
    click UserModel "https://github.com/stepsisstuck/sb/blob/main/src/models/userModel.js"
    click GameUsersModel "https://github.com/stepsisstuck/sb/blob/main/src/models/GameUsersModel.js"
    click QuestsModel "https://github.com/stepsisstuck/sb/blob/main/src/models/questsModel.js"
    click ReportModel "https://github.com/stepsisstuck/sb/blob/main/src/models/reportModel.js"
    click VulnerabilityModel "https://github.com/stepsisstuck/sb/blob/main/src/models/vulnerabilityModel.js"
    click DBConn "https://github.com/stepsisstuck/sb/blob/main/src/services/db.js"
    click Schema "https://github.com/stepsisstuck/sb/blob/main/src/configs/createSchema.js"
    click InitTables "https://github.com/stepsisstuck/sb/blob/main/src/configs/initTables.js"
    click Levels "https://github.com/stepsisstuck/sb/blob/main/src/configs/levels.js"
    click Env "https://github.com/stepsisstuck/sb/blob/main/.env"

    classDef routing fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1
    classDef controller fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20
    classDef model fill:#FFE0B2,stroke:#E65100,color:#E65100
    classDef database fill:#FFCDD2,stroke:#B71C1C,color:#B71C1C
    classDef dbsvc fill:#D1C4E9,stroke:#4A148C,color:#4A148C
    classDef config fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A
    classDef server fill:#E0F7FA,stroke:#006064,color:#006064
    classDef external fill:#ECEFF1,stroke:#37474F,color:#37474F
```
