# mwanzia-simon/reaction-time-game architecture

> Architecture diagram of the GitHub repository mwanzia-simon/reaction-time-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mwanzia-simon/reaction-time-game
- Repository: https://github.com/mwanzia-simon/reaction-time-game

## Overview

##### Project type & purpose (from README + tree)
This is a **full-stack web application**: a **Reaction Time Game** with:
- A **browser-based frontend** (HTML/CSS/vanilla JS) that runs the game, plays sounds, and shows pages (login/signup/game/leaderboard).
- A **Node.js backend** (`Backend/app.js`) that likely exposes HTTP endpoints for authentication and leaderboard/score persistence.
- A simple **JSON file database** (`Backend/db.json`) acting as the persistence layer (common patterns: direct file reads/writes, or a `json-server`-style storage).

##### Frontend (`Frontend/`)
- **Pages (routing is page-based, not SPA routing)**:
- `index.html` (landing)
- `login.html`, `signup.html` (auth UI)
- `game.html` (main game UI)
- `leaderboard.html` (score display)
- **Client logic**:
- `main.js` (likely core game + navigation + API calls)
- `leaderboard.js` (fetch/render leaderboard)
- **Static assets**:
- `assets/*.wav` (sound effects)
- `style.css`
This suggests: **static file hosting** + **client-side JS calling backend APIs**.

##### Backend (`Backend/`)
- `app.js` indicates a **single Node server entrypoint** (often Express).
- `db.json` indicates persistence via **local JSON** (no separate DB service like Postgres).

##### Browser (Frontend)
- Loads `*.html`, `style.css`, `*.js`, `assets/*.wav`
- Runs reaction-time logic locally
##### Node.js Backend Server
- Serves API (and possibly serves static frontend too—unclear from tree; represent as either a separate static host or “Node serves static + API” with a note/assumption)
##### Persistence: `db.json`
- File-based datastore (scores/users/leaderboard)
##### (Optional but useful) Local/Deployed Environment
- If this runs locally: “Developer machine”

##### Important architectural patterns to highlight (based on repo)
- **Classic 3-tier-ish split**:
- Presentation: static HTML/CSS/JS
- Application/API: Node server (`app.js`)
- Data: JSON file (`db.json`)
- **Page-based frontend** rather than a framework SPA:
- Each HTML file is a “view”; JS files attach behavior and call APIs.

##### Open `Backend/app.js` and confirm
- Are static frontend files served by Node (`express.static`) or is frontend expected to be opened directly / hosted separately?
- The actual route names for login/signup/leaderboard/score.
- Any middleware (CORS, sessions, JWT).
##### Inspect `db.json`
- What are the top-level collections? (`users`, `scores`, etc.)
- If tokens exist: include “JWT in Authorization header”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External actor
    U["User"]:::external

    %% Client / Frontend
    subgraph "Client (Browser)"
        B["Web Browser"]:::client

        subgraph "Frontend (Static HTML/CSS/JS)"
            FE_ROOT["Frontend/ (static files)"]:::frontend

            subgraph "Pages (Page-based routing)"
                FE_INDEX["index.html (Landing)"]:::page
                FE_LOGIN["login.html (Login)"]:::page
                FE_SIGNUP["signup.html (Signup)"]:::page
                FE_GAME["game.html (Game)"]:::page
                FE_LEADERBOARD["leaderboard.html (Leaderboard)"]:::page
            end

            subgraph "Scripts"
                FE_MAIN["main.js (Game logic + API calls)"]:::script
                FE_LBJS["leaderboard.js (Fetch + render leaderboard)"]:::script
            end

            subgraph "Styling"
                FE_CSS["style.css"]:::asset
            end

            subgraph "Assets (Sound Effects)"
                FE_ASSETS["assets/"]:::asset
                FE_WAV_CLICK["click.wav"]:::asset
                FE_WAV_DONE["doneSound.wav"]:::asset
                FE_WAV_FAIL["failSound.wav"]:::asset
            end
        end
    end

    %% Backend / API
    subgraph "Server (Node.js Backend)"
        BE_APP["Backend API Server (Node.js)"]:::backend

        subgraph "Backend Components"
            BE_AUTH["Auth handler (signup/login)"]:::component
            BE_SCORE["Score submission handler"]:::component
            BE_LB["Leaderboard handler"]:::component
            BE_PERSIST["Persistence (read/write JSON)"]:::component
        end

        subgraph "Persistence (File datastore)"
            DB_JSON[("db.json (users + scores)")]:::datastore
        end

        BE_PKG["package.json (deps/scripts)"]:::meta
        BE_LOCK["package-lock.json"]:::meta
    end

    %% High-level flows
    U -->|"interacts"| B

    %% Static file loading (hosted as static files; may be served by backend or separate static host)
    B -->|"HTTP GET static (HTML/CSS/JS/assets)"| FE_ROOT
    FE_ROOT -->|"loads"| FE_INDEX
    FE_ROOT -->|"loads"| FE_LOGIN
    FE_ROOT -->|"loads"| FE_SIGNUP
    FE_ROOT -->|"loads"| FE_GAME
    FE_ROOT -->|"loads"| FE_LEADERBOARD
    FE_ROOT -->|"serves"| FE_MAIN
    FE_ROOT -->|"serves"| FE_LBJS
    FE_ROOT -->|"serves"| FE_CSS
    FE_ROOT -->|"serves"| FE_ASSETS
    FE_ASSETS -->|"serves"| FE_WAV_CLICK
    FE_ASSETS -->|"serves"| FE_WAV_DONE
    FE_ASSETS -->|"serves"| FE_WAV_FAIL

    %% API calls from browser
    B -->|"HTTP JSON API (POST /signup, POST /login)"| BE_AUTH
    B -->|"HTTP JSON API (POST /score)"| BE_SCORE
    B -->|"HTTP JSON API (GET /leaderboard)"| BE_LB

    %% Backend internal wiring
    BE_APP -->|"routes to"| BE_AUTH
    BE_APP -->|"routes to"| BE_SCORE
    BE_APP -->|"routes to"| BE_LB

    BE_AUTH -->|"read/write users"| BE_PERSIST
    BE_SCORE -->|"write score"| BE_PERSIST
    BE_LB -->|"read + sort scores"| BE_PERSIST

    BE_PERSIST -->|"file I/O"| DB_JSON

    %% Responses back to browser (implicit, but shown)
    BE_AUTH -->|"JSON response (success/failure)"| B
    BE_SCORE -->|"JSON response (ack)"| B
    BE_LB -->|"JSON response (leaderboard list)"| B

    %% Click events (component_mapping)
    click FE_ROOT "https://github.com/mwanzia-simon/reaction-time-game/tree/main/Frontend/"
    click FE_INDEX "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/index.html"
    click FE_LOGIN "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/login.html"
    click FE_SIGNUP "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/signup.html"
    click FE_GAME "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/game.html"
    click FE_LEADERBOARD "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/leaderboard.html"
    click FE_MAIN "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/main.js"
    click FE_LBJS "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/leaderboard.js"
    click FE_CSS "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/style.css"
    click FE_ASSETS "https://github.com/mwanzia-simon/reaction-time-game/tree/main/Frontend/assets/"
    click FE_WAV_CLICK "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/assets/click.wav"
    click FE_WAV_DONE "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/assets/doneSound.wav"
    click FE_WAV_FAIL "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Frontend/assets/failSound.wav"
    click BE_APP "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Backend/app.js"
    click DB_JSON "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Backend/db.json"
    click BE_PKG "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Backend/package.json"
    click BE_LOCK "https://github.com/mwanzia-simon/reaction-time-game/blob/main/Backend/package-lock.json"

    %% Styles
    classDef external fill:#E5E7EB,stroke:#6B7280,stroke-width:1px,color:#111827
    classDef client fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#0F172A
    classDef frontend fill:#BFDBFE,stroke:#1D4ED8,stroke-width:1px,color:#0F172A
    classDef page fill:#93C5FD,stroke:#1D4ED8,stroke-width:1px,color:#0F172A
    classDef script fill:#60A5FA,stroke:#1D4ED8,stroke-width:1px,color:#0F172A
    classDef asset fill:#A5B4FC,stroke:#4338CA,stroke-width:1px,color:#0F172A
    classDef backend fill:#BBF7D0,stroke:#16A34A,stroke-width:1px,color:#052E16
    classDef component fill:#86EFAC,stroke:#16A34A,stroke-width:1px,color:#052E16
    classDef datastore fill:#FED7AA,stroke:#C2410C,stroke-width:1px,color:#431407
    classDef meta fill:#DCFCE7,stroke:#15803D,stroke-width:1px,color:#052E16

    class U external
    class B client
    class FE_ROOT frontend
    class FE_INDEX,FE_LOGIN,FE_SIGNUP,FE_GAME,FE_LEADERBOARD page
    class FE_MAIN,FE_LBJS script
    class FE_CSS,FE_ASSETS,FE_WAV_CLICK,FE_WAV_DONE,FE_WAV_FAIL asset
    class BE_APP backend
    class BE_AUTH,BE_SCORE,BE_LB,BE_PERSIST component
    class DB_JSON datastore
    class BE_PKG,BE_LOCK meta
```
