# jerwil445/capstone_project_flood_monitoring architecture

> Architecture diagram of the GitHub repository jerwil445/capstone_project_flood_monitoring, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jerwil445/capstone_project_flood_monitoring
- Repository: https://github.com/jerwil445/capstone_project_flood_monitoring

## Overview

This is a Flask-based campus flood and typhoon monitoring platform. Its central workflow captures and analyzes CCTV frames, publishes camera measurements, persists readings, evaluates flood alerts, and dispatches warning commands to an ESP32 siren controller. The web interface also supports monitoring and administration, while a separate bulletin-analysis capability assesses NDRRMC/PAGASA text. The excerpts establish the camera-to-alert-to-device path; some route-to-service wiring is inferred from documented capabilities and module roles, so uncertain links are omitted.

Main entry points: [`app.py`](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/app.py) (Flask runtime), [`models`](https://github.com/jerwil445/capstone_project_flood_monitoring/tree/main/models) (Domain records), [`services/esp32_service.py`](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/esp32_service.py) (ESP32 dispatcher), [`services/camera_manager.py`](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/camera_manager.py) (Camera manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_monitoring["Camera monitoring"]
  node_manager["Camera manager<br/>[camera_manager.py]"]
  node_vision["Frame detection<br/>[camera.py]"]
  node_water["Reading service"]
end

subgraph group_alerts["Alerts and bulletins"]
  node_alertroute["Flood alert routes<br/>[alerts.py]"]
  node_ndrrmcroute["Bulletin routes<br/>[ndrrmc.py]"]
  node_alert["Flood alert service<br/>[alert_service.py]"]
  node_bulletin["Bulletin analysis<br/>[ndrrmc_service.py]"]
end

subgraph group_device["Siren hardware"]
  node_sirenroute["Siren control routes<br/>[siren.py]"]
  node_espservice["ESP32 dispatcher<br/>[esp32_service.py]"]
end

subgraph group_web["Web application"]
  node_app["Flask runtime<br/>[app.py]"]
  node_ui["Dashboard client<br/>[dashboard.js]"]
  node_waterui["Water monitor client<br/>[water_level.js]"]
  node_waterroute["Water level routes<br/>[water_level.py]"]
  node_authroute["Authentication routes<br/>[auth.py]"]
  node_audit["Audit and system logs<br/>[audit_service.py]"]
end

subgraph group_data["Persistence"]
  node_db[("Relational database<br/>[db.py]")]
  node_models["Domain records"]
end

node_camera(("CCTV camera"))
node_browser(("Operator browser"))
node_esp{{"ESP32 controller<br/>[esp32_code.cpp]"}}
node_ndrrmc(("NDRRMC/PAGASA bulletin"))

node_camera -->|"streams frames"| node_vision
node_manager -->|"starts workers"| node_vision
node_vision -->|"publishes measurements"| node_manager
node_manager -->|"updates primary state"| node_app
node_app -->|"configures cameras"| node_manager
node_app -->|"records measurements"| node_water
node_water -->|"writes readings"| node_models
node_water -->|"evaluates readings"| node_alert
node_alert -->|"writes alerts and siren events"| node_models
node_alert -->|"logs alert events"| node_audit
node_app -->|"dispatches level commands"| node_espservice
node_app -->|"polls device status"| node_espservice
node_espservice -->|"sends HTTP commands"| node_esp
node_esp -->|"returns status"| node_espservice
node_esp -->|"controls siren and LEDs"| node_camera
node_browser -->|"opens dashboard"| node_ui
node_browser -->|"opens water monitor"| node_waterui
node_ui -->|"requests dashboard data"| node_app
node_waterui -->|"requests telemetry"| node_waterroute
node_waterroute -->|"queries readings"| node_water
node_browser -->|"submits credentials"| node_authroute
node_authroute -->|"reads and writes users"| node_models
node_browser -->|"views alerts"| node_alertroute
node_alertroute -->|"reads alerts"| node_models
node_ndrrmc -->|"submits bulletin text"| node_ndrrmcroute
node_ndrrmcroute -->|"analyzes bulletin"| node_bulletin
node_bulletin -->|"stores analyzed bulletin"| node_models
node_bulletin -->|"logs analysis"| node_audit
node_browser -->|"requests siren control"| node_sirenroute
node_sirenroute -->|"dispatches control command"| node_espservice
node_models -->|"persists records"| node_db

click node_manager "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/camera_manager.py"
click node_vision "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/camera/camera.py"
click node_app "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/app.py"
click node_ui "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/static/js/dashboard.js"
click node_waterui "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/static/js/pages/water_level.js"
click node_waterroute "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/water_level.py"
click node_authroute "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/auth.py"
click node_alertroute "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/alerts.py"
click node_ndrrmcroute "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/ndrrmc.py"
click node_sirenroute "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/siren.py"
click node_water "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/water_level_service.py"
click node_alert "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/alert_service.py"
click node_bulletin "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/ndrrmc_service.py"
click node_audit "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/audit_service.py"
click node_espservice "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/esp32_service.py"
click node_esp "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/esp32/esp32_code.cpp"
click node_db "https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/database/db.py"
click node_models "https://github.com/jerwil445/capstone_project_flood_monitoring/tree/main/models"

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_manager,node_vision,node_water,node_browser toneBlue
class node_alertroute,node_ndrrmcroute,node_alert,node_bulletin toneAmber
class node_sirenroute,node_espservice toneMint
class node_app,node_ui,node_waterui,node_waterroute,node_authroute,node_audit toneRose
class node_db,node_models,node_camera,node_ndrrmc toneIndigo
class node_esp toneTeal
```

## Components

### Camera monitoring

- [Camera manager](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/camera_manager.py): `services/camera_manager.py`
- [Frame detection](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/camera/camera.py): `camera/camera.py`
- [Reading service](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/water_level_service.py): `services/water_level_service.py`

### Alerts and bulletins

- [Flood alert routes](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/alerts.py): `routes/alerts.py`
- [Bulletin routes](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/ndrrmc.py): `routes/ndrrmc.py`
- [Flood alert service](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/alert_service.py): `services/alert_service.py`
- [Bulletin analysis](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/ndrrmc_service.py): `services/ndrrmc_service.py`

### Siren hardware

- [Siren control routes](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/siren.py): `routes/siren.py`
- [ESP32 dispatcher](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/esp32_service.py): `services/esp32_service.py`

### Web application

- [Flask runtime](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/app.py): `app.py`
- [Dashboard client](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/static/js/dashboard.js): `static/js/dashboard.js`
- [Water monitor client](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/static/js/pages/water_level.js): `static/js/pages/water_level.js`
- [Water level routes](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/water_level.py): `routes/water_level.py`
- [Authentication routes](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/routes/auth.py): `routes/auth.py`
- [Audit and system logs](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/services/audit_service.py): `services/audit_service.py`

### Persistence

- [Relational database](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/database/db.py): `database/db.py`
- [Domain records](https://github.com/jerwil445/capstone_project_flood_monitoring/tree/main/models): `models`

### Other components

- **CCTV camera**
- **Operator browser**
- [ESP32 controller](https://github.com/jerwil445/capstone_project_flood_monitoring/blob/main/esp32/esp32_code.cpp): `esp32/esp32_code.cpp`
- **NDRRMC/PAGASA bulletin**

## Connections

- CCTV camera → Frame detection: streams frames
- Camera manager → Frame detection: starts workers
- Frame detection → Camera manager: publishes measurements
- Camera manager → Flask runtime: updates primary state
- Flask runtime → Camera manager: configures cameras
- Flask runtime → Reading service: records measurements
- Reading service → Domain records: writes readings
- Reading service → Flood alert service: evaluates readings
- Flood alert service → Domain records: writes alerts and siren events
- Flood alert service → Audit and system logs: logs alert events
- Flask runtime → ESP32 dispatcher: dispatches level commands
- Flask runtime → ESP32 dispatcher: polls device status
- ESP32 dispatcher → ESP32 controller: sends HTTP commands
- ESP32 controller → ESP32 dispatcher: returns status
- ESP32 controller → CCTV camera: controls siren and LEDs
- Operator browser → Dashboard client: opens dashboard
- Operator browser → Water monitor client: opens water monitor
- Dashboard client → Flask runtime: requests dashboard data
- Water monitor client → Water level routes: requests telemetry
- Water level routes → Reading service: queries readings
- Operator browser → Authentication routes: submits credentials
- Authentication routes → Domain records: reads and writes users
- Operator browser → Flood alert routes: views alerts
- Flood alert routes → Domain records: reads alerts
- NDRRMC/PAGASA bulletin → Bulletin routes: submits bulletin text
- Bulletin routes → Bulletin analysis: analyzes bulletin
- Bulletin analysis → Domain records: stores analyzed bulletin
- Bulletin analysis → Audit and system logs: logs analysis
- Operator browser → Siren control routes: requests siren control
- Siren control routes → ESP32 dispatcher: dispatches control command
- Domain records → Relational database: persists records
