How niloydebbarma-code/aquaflow-cloud works
Purpose and entry points
AquaFlow Cloud is a simulated municipal water-network operations platform: it detects leaks/anomalies from hydraulic telemetry, supports incident response, and presents role-scoped views for admins, operators, and consumers. Backend entry point: backend/app/main.py; frontend bootstrap: frontend/src/main.tsx and frontend/src/App.tsx. Local deployment runs FastAPI and the Vite React client; container definitions are Dockerfile and docker-compose.yml.
API, authentication, and access boundaries
FastAPI route modules expose domain APIs for telemetry, simulations, incidents, rerouting, energy, EPANET, maintenance, water quality, and real-time updates. Authentication and role/area authorization are central boundaries: admin has grid-wide access, operators are area-limited, and end users are limited to their own property state.
• backend/app/api/routes/auth.py
• backend/app/api/deps.py
• backend/app/core/security.py
Persistence and domain model
SQLite is the system of record, accessed through SQLAlchemy. The unified model layer represents users, network assets/nodes, telemetry, incidents, and operational/audit entities; seed data establishes the demonstrable municipal network and accounts.
• backend/app/db/database.py
• backend/app/models/models.py
• backend/app/db/seed.py
Simulation-to-telemetry pipeline
Deterministic scenarios advance a modeled network state and generate node-level telemetry. The simulation route is the operational control plane for normal, demand, leak/burst, sensor-failure, and reset conditions. Generated readings feed persistence and downstream detection rather than relying on physical field sensors.
• backend/app/simulator/simulator.py
• backend/app/simulator/state.py
• backend/app/api/routes/simulation.py
Hydraulic and analytical detection
The detection boundary combines physical plausibility with statistical and ML evidence. Hydraulic modules calculate flow/pressure/head-loss behavior and estimate leaks; analytics derive rolling, derivative, EWMA, spatial/localization, and fused indicators; Isolation Forest provides anomaly scoring. This separation allows demand spikes and sensor faults to be differentiated from pipe leaks.
• backend/app/physics/leak_estimation.py
• backend/app/analytics/fusion.py
• backend/app/ml/isolation_forest.py
Operational services and incident response
Service modules turn telemetry and model outputs into incidents, acoustic evidence, dispatch recommendations, flow rerouting, pump-energy actions, maintenance/lifecycle records, financial audit data, and water-quality results. Route handlers should remain API-facing adapters while these services own domain orchestration.
• backend/app/services/telemetry_service.py
• backend/app/services/incident_service.py
• backend/app/services/dispatch_service.py
Frontend and live updates
The React/TypeScript client is a role-oriented operational dashboard: portals render network maps, sensor/telemetry displays, incident cards, simulation controls, and modal workflows. REST integration is centralized in the API client; WebSockets carry critical/live state to the UI, including burst alerts.
• frontend/src/services/api.ts
• frontend/src/services/websocket.ts
• frontend/src/pages/OperatorPortal.tsx
• frontend/src/components/NetworkMap.tsx
Material runtime dependencies
Backend runtime is Python 3.12/FastAPI/Uvicorn with SQLite/SQLAlchemy and scientific libraries including NumPy, Pandas, SciPy, and scikit-learn. The browser client uses React 18, Vite, Tailwind, Leaflet/React-Leaflet, and OpenStreetMap. EPANET integration is encapsulated behind backend/app/services/epanet_service.py; it is an external hydraulic-engine boundary rather than the primary simulation path.
Main entry points: auth.py Domain route modules · fusion.py Fusion detection · main.py FastAPI application · incident_service.py Operational services
Components 22
Backend API & Operations
- FastAPI application · Backend entry point and route host.
backend/app/main.py - Auth & access policy · Enforces role and service-area boundaries.
backend/app/api/deps.py - Security primitives
backend/app/core/security.py - Domain route modules · Telemetry, incidents, rerouting, energy, EPANET, maintenance, quality, and live APIs.
backend/app/api/routes/auth.py - Operational services · Creates incidents and dispatch recommendations from telemetry.
backend/app/services/incident_service.py - Telemetry service
backend/app/services/telemetry_service.py - Dispatch service
backend/app/services/dispatch_service.py
Simulation & Detection
- Simulation control API · Selects scenarios and reset operations.
backend/app/api/routes/simulation.py - Network simulator · Generates modeled node-level telemetry.
backend/app/simulator/simulator.py - Modeled network state
backend/app/simulator/state.py - Fusion detection · Combines hydraulic and statistical evidence.
backend/app/analytics/fusion.py - Leak estimation
backend/app/physics/leak_estimation.py - Isolation Forest
backend/app/ml/isolation_forest.py - EPANET adapter · Optional external hydraulic-engine integration.
backend/app/services/epanet_service.py
System of Record
- SQLite / SQLAlchemy
backend/app/db/database.py - Unified domain models · Users, assets, telemetry, incidents, and audit entities.
backend/app/models/models.py - Municipal seed data
backend/app/db/seed.py
Browser Client
- React dashboard · Role-oriented operations portals and workflows.
frontend/src/App.tsx - REST API client
frontend/src/services/api.ts - Live updates client · Receives critical state and burst alerts.
frontend/src/services/websocket.ts - Operator portal
frontend/src/pages/OperatorPortal.tsx - Network map
frontend/src/components/NetworkMap.tsx
Connections 25
- FastAPI application → Domain route modules: mounts
- FastAPI application → Simulation control API: mounts
- Domain route modules → Auth & access policy: authorizes requests
- Auth & access policy → Security primitives: uses
- Domain route modules → Operational services: invokes
- Domain route modules → Telemetry service: invokes
- Operational services → Dispatch service: plans response
- Simulation control API → Network simulator: controls
- Network simulator → Modeled network state: advances
- Network simulator → Telemetry service: generates readings
- Telemetry service → Fusion detection: analyzes
- Fusion detection → Leak estimation: uses
- Fusion detection → Isolation Forest: uses
- Fusion detection → Operational services: raises evidence
- Operational services → SQLite / SQLAlchemy: persists
- Telemetry service → SQLite / SQLAlchemy: stores readings
- SQLite / SQLAlchemy → Unified domain models: maps through
- Municipal seed data → SQLite / SQLAlchemy: initializes
- Domain route modules → EPANET adapter: invokes optionally
- React dashboard → REST API client: uses
- REST API client → FastAPI application: REST
- React dashboard → Live updates client: uses
- Live updates client → FastAPI application: live state
- React dashboard → Operator portal: renders
- Operator portal → Network map: displays