# samuelcaaz/risco-zero-subterraneo architecture

> Architecture diagram of the GitHub repository samuelcaaz/risco-zero-subterraneo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samuelcaaz/risco-zero-subterraneo
- Repository: https://github.com/samuelcaaz/risco-zero-subterraneo

## Overview

Risco Zero Subterrâneo is a prototype for automatic drainage in underground electrical galleries. Its critical control loop runs locally on the Arduino: floats determine pump operation with hysteresis. The Flask server supervises over serial, publishes telemetry to a browser dashboard, accepts authorized manual commands, and provides event logs, management settings, Telegram alerts, weather forecasts, and an operational report. Several backend routes and templates are documented but not fully sampled, so those relationships rely on README evidence; unsampled implementation details are not inferred.

Main entry points: [`static/app.js`](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/static/app.js) (Dashboard interface), [`app.py`](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py) (Flask application), [`arduino/risco_zero_subterraneo/risco_zero_subterraneo.ino`](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/arduino/risco_zero_subterraneo/risco_zero_subterraneo.ino) (Arduino control), [`templates/index.html`](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/templates/index.html) (Dashboard page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["Local control"]
  node_floats(("Level floats"))
  node_controller["Arduino control"]
  node_relay["Pump relay"]
  node_pump["Drainage pump"]
end

subgraph group_web["Web supervision"]
  node_serial["Serial link"]
  node_backend["Flask application<br/>[app.py]"]
  node_telemetry["Telemetry parsing<br/>[app.py]"]
  node_api["Dashboard API<br/>[app.py]"]
  node_dashboard["Dashboard interface<br/>[app.js]"]
  node_dashboard_template["Dashboard page<br/>[index.html]"]
  node_styles["Dashboard styling<br/>[style.css]"]
end

subgraph group_ops["Operations"]
  node_history_logs[("History and logs<br/>[app.py]")]
  node_manual_ops["Manual operation<br/>[app.py]"]
  node_management["Management settings<br/>[app.py]"]
  node_report["Operational report<br/>[report.html]"]
  node_alert_monitor["Alert monitoring<br/>[app.py]"]
  node_weather_forecast["Weather forecast<br/>[app.py]"]
end

subgraph group_integrations["External services"]
  node_telegram["Telegram"]
  node_open_meteo["Open-Meteo"]
end

node_operator(("Operator"))

node_floats -->|"signal levels"| node_controller
node_controller -->|"switches"| node_relay
node_relay -->|"powers"| node_pump
node_controller -->|"sends telemetry"| node_serial
node_serial -->|"carries CSV"| node_telemetry
node_backend -->|"parses lines"| node_telemetry
node_telemetry -->|"updates state"| node_history_logs
node_dashboard -->|"polls data"| node_api
node_api -->|"returns state"| node_dashboard
node_backend -->|"renders page"| node_dashboard_template
node_dashboard -.->|"uses styles"| node_styles
node_operator -->|"views panel"| node_dashboard
node_operator -->|"requests control"| node_manual_ops
node_manual_ops -->|"sends commands"| node_serial
node_api -->|"serves history"| node_history_logs
node_operator -->|"configures alerts"| node_management
node_dashboard -->|"loads settings"| node_management
node_backend -->|"renders report"| node_report
node_backend -->|"monitors cycles"| node_alert_monitor
node_alert_monitor -->|"sends alerts"| node_telegram
node_operator -->|"requests forecast"| node_weather_forecast
node_weather_forecast -->|"fetches forecast"| node_open_meteo

click node_controller "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/arduino/risco_zero_subterraneo/risco_zero_subterraneo.ino"
click node_backend "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py"
click node_telemetry "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py"
click node_api "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py"
click node_dashboard "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/static/app.js"
click node_dashboard_template "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/templates/index.html"
click node_styles "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/static/style.css"
click node_history_logs "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py"
click node_manual_ops "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py"
click node_management "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py"
click node_report "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/templates/report.html"
click node_alert_monitor "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py"
click node_weather_forecast "https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_floats,node_controller,node_relay,node_pump toneBlue
class node_serial,node_backend,node_telemetry,node_api,node_dashboard,node_dashboard_template,node_styles toneAmber
class node_history_logs,node_manual_ops,node_management,node_report,node_alert_monitor,node_weather_forecast toneMint
class node_telegram,node_open_meteo toneRose
class node_operator toneIndigo
```

## Components

### Local control

- **Level floats**
- [Arduino control](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/arduino/risco_zero_subterraneo/risco_zero_subterraneo.ino): `arduino/risco_zero_subterraneo/risco_zero_subterraneo.ino`
- **Pump relay**
- **Drainage pump**

### Web supervision

- **Serial link**
- [Flask application](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py): `app.py`
- [Telemetry parsing](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py): `app.py`
- [Dashboard API](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py): `app.py`
- [Dashboard interface](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/static/app.js): `static/app.js`
- [Dashboard page](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/templates/index.html): `templates/index.html`
- [Dashboard styling](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/static/style.css): `static/style.css`

### Operations

- [History and logs](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py): `app.py`
- [Manual operation](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py): `app.py`
- [Management settings](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py): `app.py`
- [Operational report](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/templates/report.html): `templates/report.html`
- [Alert monitoring](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py): `app.py`
- [Weather forecast](https://github.com/samuelcaaz/risco-zero-subterraneo/blob/master/app.py): `app.py`

### External services

- **Telegram**
- **Open-Meteo**

### Other components

- **Operator**

## Connections

- Level floats → Arduino control: signal levels (evidence: `README.md`)
- Arduino control → Pump relay: switches (evidence: `README.md`)
- Pump relay → Drainage pump: powers (evidence: `README.md`)
- Arduino control → Serial link: sends telemetry (evidence: `README.md`)
- Serial link → Telemetry parsing: carries CSV (evidence: `README.md`)
- Flask application → Telemetry parsing: parses lines (evidence: `app.py`)
- Telemetry parsing → History and logs: updates state (evidence: `app.py`)
- Dashboard interface → Dashboard API: polls data (evidence: `README.md`)
- Dashboard API → Dashboard interface: returns state (evidence: `README.md`)
- Flask application → Dashboard page: renders page (evidence: `app.py`)
- Dashboard interface → Dashboard styling: uses styles
- Operator → Dashboard interface: views panel (evidence: `README.md`)
- Operator → Manual operation: requests control (evidence: `README.md`)
- Manual operation → Serial link: sends commands (evidence: `README.md`)
- Dashboard API → History and logs: serves history (evidence: `README.md`)
- Operator → Management settings: configures alerts (evidence: `README.md`)
- Dashboard interface → Management settings: loads settings (evidence: `static/app.js`)
- Flask application → Operational report: renders report (evidence: `README.md`)
- Flask application → Alert monitoring: monitors cycles (evidence: `README.md`)
- Alert monitoring → Telegram: sends alerts (evidence: `README.md`)
- Operator → Weather forecast: requests forecast (evidence: `README.md`)
- Weather forecast → Open-Meteo: fetches forecast (evidence: `README.md`)
