How ifbars/gmod-report-database works
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