# xhxhkxh/lfm architecture

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

- Interactive diagram: https://gitdiagram.com/xhxhkxh/lfm
- Repository: https://github.com/xhxhkxh/lfm

## Overview

##### Project Type & Purpose
- This is a monolithic full-stack web application: a lightweight, responsive forum built with Flask (Python) and MySQL.
- The “app.py” file contains all route handlers and the SQL class (Model), while the “templates/” folder holds the view layer (HTML + inline CSS/JS), and “static/” holds supporting assets (robots.txt, fonts).

a. Client (Browser/Mobile)
- Sends HTTP(s) requests and renders HTML/CSS/JS.
- Interacts with both desktop templates and mobile-specific templates (e.g., forum-m.htm).

b. Reverse Proxy / Load Balancer (optional in production)
- Nginx or similar that fronts your Gunicorn WSGI server.

c. WSGI Application Server
- Gunicorn (for production) or Flask’s built-in development server.
- Hosts the Flask app (app.py).

d. Flask Application (“app.py”)
- Router / Controller layer: defines endpoints (/forum, /home/login, /post/comment/<id>, etc.).
- Business logic: session management, Argon2 hashing, hCaptcha validation, Markdown processing.
- SQL class: encapsulates MySQL connection parameters and query execution.

e. Templates & Static Assets
- templates/: HTML view layer (Jinja2 templates).
- templates/scripts/crypto.js: client-side crypto routines.
- static/: CSS, robots.txt, optional images.
- fonts/: HarmonyOS Sans TTF.

f. MySQL Database
- Tables: users, posts, reply.
- Data persistence for forum content, user credentials, comments.

g. External Services
- hCaptcha API: spam/bot protection.
- (Future) Email provider for verification.

- User → HTTP Request → Nginx → Gunicorn → Flask Routes
- Flask Route → (reads/writes) → MySQL
- Flask Route → selects Jinja template → renders HTML → Response → Browser
- Browser → loads CSS/JS/Fonts from static/ and fonts/
- During signup/login → Flask → hCaptcha service (verify token) → hCaptcha API → Flask
- Session cookies set in HTTP response and returned on subsequent requests

##### Architectural Patterns & Design Principles
- MVC-inspired separation:
- Model: SQL class + MySQL
- View: Jinja2 templates + static assets
- Controller: Flask route handlers in app.py
- Modular design: clearly separated folders for templates and static.
- Security best practices: parameterized queries, Argon2 hashing, XSS prevention via automatic escaping, session timeouts.
- Mobile-first design: dedicated mobile templates under templates/

- Python 3.7+ / Flask
- MySQL
- Gunicorn + Nginx (production)
- Jinja2 templating
- Argon2 (password hashing)
- hCaptcha API
- Markdown parser (if used)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Browser / Mobile"]:::frontend

    %% Proxy Layer
    Nginx["Nginx Reverse Proxy"]:::backend

    %% Application Server Layer
    Gunicorn["Gunicorn WSGI Server"]:::backend
    Flask["Flask App<br/>(app.py)"]:::backend

    %% Web Assets Layer
    subgraph "Web Assets"
        Templates["Jinja2 Templates"]:::frontend
        CryptoScript["crypto.js"]:::frontend
        Static["Static Assets"]:::frontend
        Robots["robots.txt"]:::frontend
        Fonts["Fonts"]:::frontend
    end

    %% Database and External
    Database[(MySQL<br/>users/posts/reply)]:::database
    External["hCaptcha Service"]:::external

    %% Data Flows
    Browser -->|"HTTP GET /forum"| Nginx
    Nginx -->|"WSGI HTTP"| Gunicorn
    Gunicorn -->|"calls routes"| Flask
    Flask -->|"SQL SELECT/INSERT"| Database
    Flask -->|"render"| Templates
    Templates -->|"HTML/CSS/JS"| Browser
    Browser -->|"GET CSS/JS"| Static
    Browser -->|"GET fonts"| Fonts
    Flask -->|"verify token"| External
    Flask -->|"uses crypto"| CryptoScript
    Browser -->|"robots.txt"| Robots

    %% Click Events
    click Flask "https://github.com/xhxhkxh/lfm/blob/main/app.py"
    click Database "https://github.com/xhxhkxh/lfm/blob/main/db-backup_clean.sql"
    click Dependencies "https://github.com/xhxhkxh/lfm/blob/main/requirements.txt"
    click Templates "https://github.com/xhxhkxh/lfm/tree/main/templates/"
    click CryptoScript "https://github.com/xhxhkxh/lfm/blob/main/templates/scripts/crypto.js"
    click Static "https://github.com/xhxhkxh/lfm/blob/main/static/robots.txt"
    click Robots "https://github.com/xhxhkxh/lfm/blob/main/static/robots.txt"
    click Fonts "https://github.com/xhxhkxh/lfm/tree/main/fonts/"
    click README "https://github.com/xhxhkxh/lfm/blob/main/README.md"
    click LICENSE "https://github.com/xhxhkxh/lfm/tree/main/LICENSE"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1;
    classDef backend fill:#E8F5E9,stroke:#A5D6A7,color:#1B5E20;
    classDef database fill:#FFF3E0,stroke:#FFCC80,color:#E65100;
    classDef external fill:#FFE0B2,stroke:#FFB74D,color:#EF6C00;
```
