# erdhyernando/flask-auth architecture

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

- Interactive diagram: https://gitdiagram.com/erdhyernando/flask-auth
- Repository: https://github.com/erdhyernando/flask-auth

## Overview

##### Project type and purpose
- This is a full-stack, Flask‐SocketIO web application running on a Raspberry Pi.
- Purpose: Provide a GUI for user authentication, file management, real-time execution and monitoring of “orthosis” control scripts, data logging, and chart-based visualization.

##### Main components to include as distinct blocks
a. Client / Browser Layer
- Static assets (CSS, JS) and HTML templates (under templates/)
- Chart.js for data visualization
- GUI pages: login/signup, script browser, real-time output console
b. Web Server / Application Layer
- Flask app (app.py + run.py)
- Flask-SocketIO event handlers (routes.py)
- Utility module (utils.py) for argument parsing, admin checks, directory pointers
- Script management subsystem (“orthosis-scripts” directory)
c. Database Layer
- SQLAlchemy models (models.py)
- Alembic migrations (migrations/…)
- User table, script_labels table, data logging tables
d. Script Execution Engine & Hardware Interface
- Python subprocess or direct module import to launch scripts from the orthosis-scripts folder
- Real-time stdout/stderr forwarded over WebSocket
- Optional Shellinabox CLI for advanced command-line interactions
- Interaction with orthosis hardware (GPIO or external API calls)
e. External Services & Host
- Raspberry Pi OS startup (bashrc entry → run.py)
- Possible external IP link / sudo commands for hardware networking

##### Relationships and data flows
- HTTP(S) requests (GET/POST) from Client → Flask routes (login, signup, page loads)
- WebSocket (Socket.IO) bidirectional channel:
- Client emits “run_script” → Server spawns script → streams real-time output events back
- Server pushes data-logging updates and chart points to Client
- ORM/SQL queries: application CRUD on User, ScriptLabels, Logs → Database file (e.g., SQLite or other URI)
- Server invokes system calls (Shellinabox, sudo IP link) to prepare hardware or open CLI

##### Architectural patterns and design principles
- MVC-style separation:
- Models: models.py + migrations
- Views: HTML templates + static JS/CSS
- Controllers: Flask routes + SocketIO handlers
- Event-driven, real-time pipeline via WebSockets
- Modular script plug-in structure under orthosis-scripts for extensibility
- Configuration-driven startup (utils.py / bashrc)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client / Browser Layer"
        direction TB
        StaticAssets["Static Assets (CSS/JS)"]:::frontend
        StaticCSS["CSS Files"]:::frontend
        StaticJS["JS Files"]:::frontend
        Templates["HTML Templates"]:::frontend
        ChartJS["Chart.js"]:::frontend
    end

    %% Server Layer
    subgraph "Web Server / Application Layer"
        direction TB
        FlaskApp["Flask App (app.py, run.py)"]:::server
        Routes["Routes & SocketIO Handlers (routes.py)"]:::server
        Utils["Utility Module (utils.py)"]:::server
        Scripts["Script Management (orthosis-scripts/)"]:::server
    end

    %% Database Layer
    subgraph "Database Layer"
        direction TB
        Models["ORM Models (models.py)"]:::database
        Migrations["Alembic Migrations (migrations/)"]:::database
        DB["Database File"]:::database
    end

    %% Hardware Layer
    subgraph "Hardware / Host Layer"
        direction TB
        ScriptEngine["Script Execution Engine"]:::hardware
        Shellinabox["Shellinabox CLI"]:::hardware
        Host["Raspberry Pi Host (bashrc startup)"]:::hardware
    end

    %% External/docs
    subgraph "Documentation & Config"
        direction TB
        Requirements["requirements.txt"]:::server
        README["README.md"]:::server
    end

    %% Connections
    StaticAssets -->|"serves"| FlaskApp
    Templates -->|"renders"| FlaskApp
    ChartJS -->|loads charts| Templates
    StaticCSS --> StaticAssets
    StaticJS --> StaticAssets

    FlaskApp -->|"imports"| Routes
    Routes -->|"uses"| Utils
    Routes -->|"spawns"| ScriptEngine
    ScriptEngine ==> Host
    ScriptEngine -->|forwards stdout/stderr| Routes
    Routes -.->|"WebSocket"| StaticJS
    StaticJS -.->|"WebSocket"| Routes
    Routes ...->|CRUD| Models
    Migrations ...->|migrates| Models
    Models ...->|stores data| DB

    Host -->|invokes run.py| FlaskApp
    Host -->|auto-start via bashrc| Host

    Requirements --> FlaskApp
    README --> FlaskApp

    %% Click Events
    click StaticAssets "https://github.com/erdhyernando/flask-auth/tree/main/static/css/"
    click StaticCSS "https://github.com/erdhyernando/flask-auth/tree/main/static/css/"
    click StaticJS "https://github.com/erdhyernando/flask-auth/tree/main/static/js/"
    click Templates "https://github.com/erdhyernando/flask-auth/tree/main/templates/"
    click FlaskApp "https://github.com/erdhyernando/flask-auth/blob/main/app.py"
    click FlaskApp "https://github.com/erdhyernando/flask-auth/blob/main/run.py"
    click Routes "https://github.com/erdhyernando/flask-auth/blob/main/routes.py"
    click Utils "https://github.com/erdhyernando/flask-auth/blob/main/utils.py"
    click Scripts "https://github.com/erdhyernando/flask-auth/tree/main/orthosis-scripts/"
    click Models "https://github.com/erdhyernando/flask-auth/blob/main/models.py"
    click Migrations "https://github.com/erdhyernando/flask-auth/tree/main/migrations/"
    click Requirements "https://github.com/erdhyernando/flask-auth/blob/main/requirements.txt"
    click README "https://github.com/erdhyernando/flask-auth/blob/main/README.md"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef server fill:#d4edda,stroke:#155724,color:#155724
    classDef database fill:#fff3cd,stroke:#856404,color:#856404
    classDef hardware fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
