# one0one2552/mgb architecture

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

- Interactive diagram: https://gitdiagram.com/one0one2552/mgb
- Repository: https://github.com/one0one2552/mgb

## Overview

##### File Structure Analysis
- top-level:
- config/config.yaml – runtime settings for sensors, actuators, PID, web server
- src/main.py – application entry point
- install_service.sh, mgb.service – systemd service for auto-start on Pi
- requirements.txt – Python dependencies
- src/:
- sensors/ – hardware or mock sensor drivers (scd30_sensor.py)
- controllers/ – PID logic (pid_controller.py)
- actuators/ – relay control for pump, heater, fan (relay_actuator.py)
- utils/ – logger, data logger, wifi management, translations
- web/ – Flask app (app.py), wifi setup endpoint, static assets (JS/CSS), templates (HTML)
- tests at root – unit tests for sensors and actuators.

##### README Insights
- Core architectural layers described: hardware interface → control logic → persistence → web API/UI.
- Technology stack: Python3, Flask + SocketIO, SQLite, Chart.js, Raspberry Pi GPIO.
- Hardware wiring details and GPIO assignments indicate direct integration with physical world.
- Deployment uses systemd service on Pi; development mode supports mock sensors.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "System Startup"
        A["install_service.sh"]:::service --> B["mgb.service"]:::service --> C["src/main.py"]:::service
    end

    subgraph "Configuration"
        cfg["config/config.yaml"]:::configclass
    end

    subgraph "Hardware Abstraction"
        direction TB
        S1["base_sensor.py"]:::hardware
        S2["scd30_sensor.py"]:::hardware
        A1["base_actuator.py"]:::hardware
        A2["relay_actuator.py"]:::hardware
    end

    subgraph "Control Layer"
        PID["pid_controller.py"]:::control
    end

    subgraph "Persistence Layer"
        DL["data_logger.py"]:::persistence
        DB["SQLite DB"]:::persistence
    end

    subgraph "Utilities"
        U1["logger.py"]:::utility
        U2["wifi_manager.py"]:::utility
        U3["translations.py"]:::utility
    end

    subgraph "Web/API Layer"
        WS["app.py"]:::webapi
        WSU["wifi_setup.py"]:::webapi
    end

    subgraph "Web UI"
        direction TB
        CSS1["style.css"]:::ui
        CSS2["switchers.css"]:::ui
        CSS3["theme-dark.css"]:::ui
        JS1["main.js"]:::ui
        JS2["i18n.js"]:::ui
        JS3["theme-switcher.js"]:::ui
        T1["index.html"]:::ui
        T2["settings.html"]:::ui
        T3["wifi_setup.html"]:::ui
    end

    subgraph "Other Scripts & Files"
        Req["requirements.txt"]:::configclass
        AW["install_wifi_ap.sh"]:::service
        Cal["calibrate_scd30.py"]:::service
        TS1["test_scd30.py"]:::service
        TS2["test_relay.py"]:::service
    end

    %% Data and Control Flows
    cfg --> S1
    cfg --> S2
    cfg --> PID
    cfg --> WS

    S1 -->|reads data| PID
    S2 -->|reads data| PID
    PID -->|commands| A1
    PID -->|commands| A2

    S1 -->|events| DL
    S2 -->|events| DL
    A1 -->|events| DL
    A2 -->|events| DL
    PID -->|logs| DL
    DL -->|stores| DB

    WS -->|queries| DB
    WS -->|invokes| PID
    WS -->|controls| A2
    WS -->|controls| A1

    U2 --> WSU
    U1 --> DL

    %% Web Socket and HTTP
    Browser[(Client Browser)]:::ui
    Browser -->|HTTP/WS| WS
    WS -->|push updates| Browser

    %% Service startup invokes main
    C --> S1
    C --> S2
    C --> PID
    C --> DL
    C --> WS
    C --> U2

    %% Click Events
    click cfg "https://github.com/one0one2552/mgb/blob/main/config/config.yaml"
    click C "https://github.com/one0one2552/mgb/blob/main/src/main.py"
    click A "https://github.com/one0one2552/mgb/blob/main/install_service.sh"
    click B "https://github.com/one0one2552/mgb/blob/main/mgb.service"
    click S1 "https://github.com/one0one2552/mgb/blob/main/src/sensors/base_sensor.py"
    click S2 "https://github.com/one0one2552/mgb/blob/main/src/sensors/scd30_sensor.py"
    click A1 "https://github.com/one0one2552/mgb/blob/main/src/actuators/base_actuator.py"
    click A2 "https://github.com/one0one2552/mgb/blob/main/src/actuators/relay_actuator.py"
    click PID "https://github.com/one0one2552/mgb/blob/main/src/controllers/pid_controller.py"
    click DL "https://github.com/one0one2552/mgb/blob/main/src/utils/data_logger.py"
    click U1 "https://github.com/one0one2552/mgb/blob/main/src/utils/logger.py"
    click U2 "https://github.com/one0one2552/mgb/blob/main/src/utils/wifi_manager.py"
    click U3 "https://github.com/one0one2552/mgb/blob/main/src/utils/translations.py"
    click WS "https://github.com/one0one2552/mgb/blob/main/src/web/app.py"
    click WSU "https://github.com/one0one2552/mgb/blob/main/src/web/wifi_setup.py"
    click CSS1 "https://github.com/one0one2552/mgb/blob/main/src/web/static/css/style.css"
    click CSS2 "https://github.com/one0one2552/mgb/blob/main/src/web/static/css/switchers.css"
    click CSS3 "https://github.com/one0one2552/mgb/blob/main/src/web/static/css/theme-dark.css"
    click JS1 "https://github.com/one0one2552/mgb/blob/main/src/web/static/js/main.js"
    click JS2 "https://github.com/one0one2552/mgb/blob/main/src/web/static/js/i18n.js"
    click JS3 "https://github.com/one0one2552/mgb/blob/main/src/web/static/js/theme-switcher.js"
    click T1 "https://github.com/one0one2552/mgb/blob/main/src/web/templates/index.html"
    click T2 "https://github.com/one0one2552/mgb/blob/main/src/web/templates/settings.html"
    click T3 "https://github.com/one0one2552/mgb/blob/main/src/web/templates/wifi_setup.html"
    click Req "https://github.com/one0one2552/mgb/blob/main/requirements.txt"
    click AW "https://github.com/one0one2552/mgb/blob/main/install_wifi_ap.sh"
    click Cal "https://github.com/one0one2552/mgb/blob/main/calibrate_scd30.py"
    click TS1 "https://github.com/one0one2552/mgb/blob/main/test_scd30.py"
    click TS2 "https://github.com/one0one2552/mgb/blob/main/test_relay.py"

    %% Styles
    classDef hardware fill:#a2d5a2,stroke:#333,stroke-width:1px
    classDef control fill:#a2c4fc,stroke:#333,stroke-width:1px
    classDef persistence fill:#f4b183,stroke:#333,stroke-width:1px
    classDef webapi fill:#c9c0ff,stroke:#333,stroke-width:1px
    classDef ui fill:#fff2cc,stroke:#333,stroke-width:1px
    classDef utility fill:#d9d9d9,stroke:#333,stroke-width:1px
    classDef configclass fill:#cfe2f3,stroke:#333,stroke-width:1px
    classDef service fill:#f8cbad,stroke:#333,stroke-width:1px
```
