# ifbars/gmod-report-database architecture

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

- Interactive diagram: https://gitdiagram.com/ifbars/gmod-report-database
- Repository: https://github.com/ifbars/gmod-report-database

## Overview

##### Project Type & Purpose
- This is a desktop “full-stack” application: a Python/Flask web server wrapped in an Electron shell.
- Purpose: let Gmod DarkRP staff run a self-contained executable that hosts a local web UI for tracking player reports and bans.

##### File Structure
- Root files:
- app.py, bans.py, config.py → Flask application entrypoint and modules
- schema.sql → SQL schema to initialize the database
- config.json → theme & application settings
- loading.html, start.bat → developer UX & startup helper
- Frontend/Electron:
- main.js, package.json, node_modules → Electron’s main process & packaging config
- package-lock.json → locked Node dependencies
- Web assets served by Flask:
- templates/*.html → Jinja2 HTML templates for each view (index, reports, bans, settings, stats, etc.)
- static/css/styles.css, theme_template.css → CSS files for theming
- main.js (if used in renderer), static JS as needed
- Dependency files:
- requirements.txt → Python libraries (Flask, etc.)
- package.json → Electron & frontend dependencies

##### README Insights
- Confirms tech stack: Python 3.x + Flask for backend, Node/Electron for desktop wrapper.
- Packaging: PyInstaller builds a server.exe, electron-packager bundles that with the Electron frontend into a single executable.
- Usage flow: user launches the exe → Electron spins up the Flask server → UI loads in embedded browser.

##### Main Components
a. Electron Host
- Node.js main process (main.js)
- Loading window (loading.html) → Main UI window (index.html served by Flask)
b. Renderer (BrowserWindow)
- Renders Jinja2 templates & static assets
- Executes frontend JS/CSS for theming
c. Flask Backend
- app.py defines routes (/add_report, /bans, /settings, etc.)
- bans.py contains ban‐specific business logic
- config.py reads config.json for themes/settings
- Serves HTTP endpoints on localhost (e.g. http://127.0.0.1:5000)
d. Database
- SQLite (or similar) initialized via schema.sql
- Stores reports, bans, users
e. Packaging Tools (External)
- PyInstaller → packs app.py into server.exe
- electron-packager → bundles Electron + server.exe

##### Relationships & Interactions
- Startup Sequence: User → Electron main → spawn server.exe (Flask)
- HTTP Flow: BrowserWindow ↔ HTTP GET/POST ↔ Flask server
- Data Flow: Flask server ↔ SQL read/write ↔ Database file
- Asset Delivery: Flask serves HTML/CSS/JS → BrowserWindow

##### Architectural Patterns & Principles
- Client-Server (local): Desktop UI as HTTP client, Flask as HTTP server
- MVC-ish separation: Templates (View), route handlers & modules (Controller), SQLite (Model)
- Theming via external CSS files and config.json

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User launches application
    User["User"]:::external -->|launch exe| ElectronMain

    %% Electron Host
    subgraph "Electron Host (Frontend)" 
        ElectronMain["Electron Main Process"]:::frontend
        NodeConfig["Node Modules & Config"]:::frontend
        LoadingWin["Loading Window"]:::frontend
        StartScript["Startup Helper Script"]:::frontend
        Renderer["BrowserWindow (Renderer)"]:::frontend
    end

    %% Flask Backend
    subgraph "Flask Backend (Local Server)"
        FlaskApp["Flask Server (app.py)"]:::backend
        BansMod["Ban Logic Module (bans.py)"]:::backend
        ConfigPy["Config Loader (config.py)"]:::backend
        ConfigJson["App Settings (config.json)"]:::backend
        Templates["Templates Directory"]:::backend
        StaticCSS["Static CSS Files"]:::backend
        ThemeCSS["Theme Template CSS"]:::backend
        SchemaSql["DB Schema (schema.sql)"]:::backend
    end

    %% Database
    DB[(Local SQLite DB)]:::db

    %% Packaging Tools
    subgraph "Packaging Tools (Pre-deployment)" 
        PyInstaller["PyInstaller"]:::build
        ElectronPack["electron-packager"]:::build
    end

    %% Relationships
    ElectronMain -->|uses| NodeConfig
    ElectronMain -->|loads| LoadingWin
    ElectronMain -->|executes| StartScript
    ElectronMain -->|creates| Renderer
    ElectronMain -->|spawn server.exe| FlaskApp
    Renderer -->|HTTP GET/POST| FlaskApp
    FlaskApp -->|imports| BansMod
    FlaskApp -->|uses| ConfigPy
    FlaskApp -->|reads| ConfigJson
    FlaskApp -->|serves| Templates
    FlaskApp -->|serves| StaticCSS
    FlaskApp -->|serves| ThemeCSS
    FlaskApp -->|initializes| SchemaSql
    FlaskApp -->|read/write| DB

    %% Click Events
    click ElectronMain "https://github.com/ifbars/gmod-report-database/blob/main/main.js"
    click NodeConfig "https://github.com/ifbars/gmod-report-database/blob/main/package.json"
    click NodeConfig "https://github.com/ifbars/gmod-report-database/blob/main/package-lock.json"
    click NodeConfig "https://github.com/ifbars/gmod-report-database/tree/main/node_modules/"
    click LoadingWin "https://github.com/ifbars/gmod-report-database/blob/main/loading.html"
    click StartScript "https://github.com/ifbars/gmod-report-database/blob/main/start.bat"
    click FlaskApp "https://github.com/ifbars/gmod-report-database/blob/main/app.py"
    click BansMod "https://github.com/ifbars/gmod-report-database/blob/main/bans.py"
    click ConfigPy "https://github.com/ifbars/gmod-report-database/blob/main/config.py"
    click ConfigJson "https://github.com/ifbars/gmod-report-database/blob/main/config.json"
    click SchemaSql "https://github.com/ifbars/gmod-report-database/blob/main/schema.sql"
    click Templates "https://github.com/ifbars/gmod-report-database/tree/main/templates/"
    click StaticCSS "https://github.com/ifbars/gmod-report-database/blob/main/static/css/styles.css"
    click ThemeCSS "https://github.com/ifbars/gmod-report-database/blob/main/static/css/theme_template.css"
    click PyInstaller "https://github.com/ifbars/gmod-report-database/tree/main/README"
    click ElectronPack "https://github.com/ifbars/gmod-report-database/tree/main/README"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0066CC,color:#000;
    classDef backend fill:#DFF2D8,stroke:#2E8B57,color:#000;
    classDef db fill:#FFE5B4,stroke:#CC8400,color:#000;
    classDef build fill:#EEEEEE,stroke:#666666,color:#000;
    classDef external fill:#F5F5F5,stroke:#999999,color:#333;
```
