How sumitzanje/riverguardianai works
Purpose and Entry Points
RiverGuardianAI is an edge-first flood-access prediction system for Arduino UNO Q: STM32 firmware owns sensor/actuator interaction, while Linux-side Python performs local intelligence and resilient telemetry handling. The canonical device entry point is python/main_runtime.py, which launches python/riverguardian_runtime.py. Firmware is rooted at sketch/sketch.ino.
Device Runtime Orchestration
python/riverguardian_runtime.py coordinates recurring collection, inference, persistence, upload, and optional direct WhatsApp delivery. Runtime settings are loaded from a device-local settings file plus environment overrides through python/config_loader.py and python/runtime_config.py. Deployment installs this as a system service via deploy/riverguardian.service.
Sensor and Actuator Boundary
The MCU/firmware boundary is the rugged hardware interface: firmware reads and filters physical measurements and supports bench versus production filter profiles in sketch/sketch.ino. Python-side bridge modules isolate MCU/sensor communications from decision logic: python/bridge_interface.py, python/bridge_Int_Senor.py, and python/actuator_controller.py. Hardware-specific RS485 and cellular behavior remains deployment-dependent.
Intelligence Pipeline
The runtime transforms sensor observations and weather context into risk and action decisions. Weather acquisition and fusion are handled by python/weather_fetcher.py and python/weather_fusion_engine.py; prediction/assessment stages are represented by python/confidence_engine.py, python/risk_engine.py, and python/recommendation_engine.py. This separation preserves the distinction between measurement confidence, flood risk state, and recommended response.
State, Alerts, and Local Resilience
Each cycle persists locally before cloud dependence through python/local_database.py. python/alert_manager.py derives send eligibility from risk transitions and cooldowns, so notification failures do not halt sensing or risk processing. Standalone operational entry points include python/main_alert.py, python/main_database.py, and python/main_confidence.py.
Cloud Telemetry and Notifications
Telemetry can upload directly to Supabase through python/api_uploader.py; schema starts at supabase/001_riverguardian_events.sql and is extended by supabase/migrations/20260806120000_sensor_observability_fields.sql. Direct device WhatsApp delivery is encapsulated by python/whatsapp_sender.py. An optional trusted notifier worker, python/main_alert_notifier.py and python/supabase_alert_notifier.py, polls cloud alert events and checkpoints its progress locally.
Supabase Edge and Dashboard Surfaces
Supabase Edge Functions keep Telegram credentials and privileged data access off the device. supabase/functions/telegram-webhook/index.ts serves bot commands/webhooks, while supabase/functions/alert-dispatcher/index.ts processes inserted alert events for proactive delivery; subscriber/delivery state is defined in supabase/migrations/20260801171050_telegram_bot_platform.sql. A Next.js dashboard consumes RiverGuardian data through web-dashboard/src/app/page.tsx and its server-side API route web-dashboard/src/app/api/riverguardian/route.ts. The separate dashboard/dashboard_app.py is an additional Python dashboard entry point.
Infrastructure and Operations
Production device deployment is manually tag-approved, with service installation and layout migration under deploy/install-deployment.sh and deploy/riverguardian-migrate-layout. Connectivity resilience is supported by python/connectivity_manager.py plus the network failover systemd unit/timer files under deploy/. Supabase, Ambient Weather, Telegram, Twilio/webhook WhatsApp, and optionally Tailscale are the material external integrations.
Main entry points: riverguardian_runtime.py Runtime Orchestrator · 001_riverguardian_events.sql RiverGuardian Data & Events · risk_engine.py Flood Risk Engine · api_uploader.py Telemetry Uploader
Components 22
Edge Device
Arduino UNO Q firmware and local Linux runtime.
- STM32 Firmware · Reads, filters, and controls physical hardware.
sketch/sketch.ino - Hardware Bridge · Isolates MCU and sensor communication from decisions.
python/bridge_interface.py - Actuator Control
python/actuator_controller.py - Device Entry Point · Starts the canonical device runtime.
python/main_runtime.py - Runtime Orchestrator · Runs recurring collection, decisions, persistence, and delivery.
python/riverguardian_runtime.py - Runtime Configuration · Combines local settings with environment overrides.
python/config_loader.py - Weather Fusion · Acquires weather context and fuses it with observations.
python/weather_fusion_engine.py - Measurement Confidence
python/confidence_engine.py - Flood Risk Engine
python/risk_engine.py - Response Recommendations
python/recommendation_engine.py - Local State Store · Persists cycles before cloud dependence.
python/local_database.py - Alert Manager · Applies risk transitions and cooldown eligibility.
python/alert_manager.py - Telemetry Uploader
python/api_uploader.py - Device WhatsApp Sender
python/whatsapp_sender.py - Connectivity Manager · Supports resilient network connectivity.
python/connectivity_manager.py
Supabase Cloud
Telemetry, alert automation, and bot surfaces.
- RiverGuardian Data & Events · Stores telemetry and alert events.
supabase/001_riverguardian_events.sql - Alert Dispatcher · Processes inserted alert events for proactive delivery.
supabase/functions/alert-dispatcher/index.ts - Telegram Webhook · Handles bot commands without exposing credentials to devices.
supabase/functions/telegram-webhook/index.ts - Trusted Alert Notifier · Polls cloud alert events and checkpoints locally.
python/main_alert_notifier.py
Dashboard & Operations
Operator interfaces and deployment support.
- Next.js Dashboard · Displays RiverGuardian data to operators.
web-dashboard/src/app/page.tsx - Dashboard API Route
web-dashboard/src/app/api/riverguardian/route.ts - Device Deployment · Installs the tagged-approved runtime service.
deploy/install-deployment.sh
Connections 22
- STM32 Firmware → Hardware Bridge: sensor and MCU I/O
- Hardware Bridge → Runtime Orchestrator: observations
- Runtime Orchestrator → Actuator Control: action commands
- Device Entry Point → Runtime Orchestrator: launches
- Runtime Configuration → Runtime Orchestrator: settings
- Runtime Orchestrator → Weather Fusion: weather context
- Runtime Orchestrator → Measurement Confidence: measurements
- Weather Fusion → Flood Risk Engine: fused context
- Measurement Confidence → Flood Risk Engine: confidence
- Flood Risk Engine → Response Recommendations: risk state
- Runtime Orchestrator → Local State Store: persist cycle
- Flood Risk Engine → Alert Manager: risk transitions
- Alert Manager → Device WhatsApp Sender: eligible direct alerts
- Runtime Orchestrator → Telemetry Uploader: telemetry
- Connectivity Manager → Telemetry Uploader: network availability
- Telemetry Uploader → RiverGuardian Data & Events: upload events
- RiverGuardian Data & Events → Alert Dispatcher: inserted alert events
- RiverGuardian Data & Events → Trusted Alert Notifier: polled alerts
- Telegram Webhook → RiverGuardian Data & Events: subscriber and delivery state
- Next.js Dashboard → Dashboard API Route: data requests
- Dashboard API Route → RiverGuardian Data & Events: server-side data access
- Device Deployment → Device Entry Point: installs service for