# niloydebbarma-code/aquaflow-cloud architecture

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

- Interactive diagram: https://gitdiagram.com/niloydebbarma-code/aquaflow-cloud
- Repository: https://github.com/niloydebbarma-code/aquaflow-cloud

## Overview

#### 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: [`backend/app/api/routes/auth.py`](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/api/routes/auth.py) (Domain route modules), [`backend/app/analytics/fusion.py`](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/analytics/fusion.py) (Fusion detection), [`backend/app/main.py`](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/services/incident_service.py`](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/incident_service.py) (Operational services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend API &amp; Operations"]
  node_api["FastAPI application<br/>Python/FastAPI<br/>[main.py]"]
  node_auth{{"Auth &amp; access policy<br/>authorization<br/>[deps.py]"}}
  node_security["Security primitives<br/>authentication<br/>[security.py]"]
  node_domain_routes["Domain route modules<br/>API adapters<br/>[auth.py]"]
  node_operations["Operational services<br/>domain orchestration"]
  node_telemetry_service["Telemetry service<br/>domain service"]
  node_dispatch["Dispatch service<br/>response planning"]
end

subgraph group_simulation["Simulation &amp; Detection"]
  node_simulation_route["Simulation control API<br/>control plane<br/>[simulation.py]"]
  node_simulator["Network simulator<br/>scenario engine<br/>[simulator.py]"]
  node_network_state["Modeled network state<br/>simulation state<br/>[state.py]"]
  node_detection["Fusion detection<br/>analytics<br/>[fusion.py]"]
  node_leak_physics["Leak estimation<br/>hydraulic analysis<br/>[leak_estimation.py]"]
  node_anomaly_ml["Isolation Forest<br/>ML scoring"]
  node_epanet{{"EPANET adapter<br/>external engine boundary<br/>[epanet_service.py]"}}
end

subgraph group_data["System of Record"]
  node_database[("SQLite / SQLAlchemy<br/>system of record<br/>[database.py]")]
  node_models["Unified domain models<br/>SQLAlchemy models<br/>[models.py]"]
  node_seed["Municipal seed data<br/>bootstrap data<br/>[seed.py]"]
end

subgraph group_frontend["Browser Client"]
  node_react_app["React dashboard<br/>React/Vite client<br/>[App.tsx]"]
  node_api_client["REST API client<br/>frontend integration<br/>[api.ts]"]
  node_websocket_client["Live updates client<br/>WebSocket integration<br/>[websocket.ts]"]
  node_operator_portal["Operator portal<br/>role view<br/>[OperatorPortal.tsx]"]
  node_network_map["Network map<br/>map component<br/>[NetworkMap.tsx]"]
end

node_api -->|"mounts"| node_domain_routes
node_api -->|"mounts"| node_simulation_route
node_domain_routes -->|"authorizes requests"| node_auth
node_auth -->|"uses"| node_security
node_domain_routes -->|"invokes"| node_operations
node_domain_routes -->|"invokes"| node_telemetry_service
node_operations -->|"plans response"| node_dispatch
node_simulation_route -->|"controls"| node_simulator
node_simulator -->|"advances"| node_network_state
node_simulator -->|"generates readings"| node_telemetry_service
node_telemetry_service -->|"analyzes"| node_detection
node_detection -->|"uses"| node_leak_physics
node_detection -->|"uses"| node_anomaly_ml
node_detection -->|"raises evidence"| node_operations
node_operations -->|"persists"| node_database
node_telemetry_service -->|"stores readings"| node_database
node_database -->|"maps through"| node_models
node_seed -->|"initializes"| node_database
node_domain_routes -.->|"invokes optionally"| node_epanet
node_react_app -->|"uses"| node_api_client
node_api_client -->|"REST"| node_api
node_react_app -->|"uses"| node_websocket_client
node_websocket_client -->|"live state"| node_api
node_react_app -->|"renders"| node_operator_portal
node_operator_portal -->|"displays"| node_network_map

click node_api "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/main.py"
click node_auth "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/api/deps.py"
click node_security "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/core/security.py"
click node_domain_routes "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/api/routes/auth.py"
click node_operations "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/incident_service.py"
click node_telemetry_service "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/telemetry_service.py"
click node_dispatch "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/dispatch_service.py"
click node_simulation_route "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/api/routes/simulation.py"
click node_simulator "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/simulator/simulator.py"
click node_network_state "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/simulator/state.py"
click node_detection "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/analytics/fusion.py"
click node_leak_physics "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/physics/leak_estimation.py"
click node_anomaly_ml "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/ml/isolation_forest.py"
click node_epanet "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/epanet_service.py"
click node_database "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/db/database.py"
click node_models "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/models/models.py"
click node_seed "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/db/seed.py"
click node_react_app "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/App.tsx"
click node_api_client "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/services/api.ts"
click node_websocket_client "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/services/websocket.ts"
click node_operator_portal "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/pages/OperatorPortal.tsx"
click node_network_map "https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/components/NetworkMap.tsx"

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_api,node_auth,node_security,node_domain_routes,node_operations,node_telemetry_service,node_dispatch toneBlue
class node_simulation_route,node_simulator,node_network_state,node_detection,node_leak_physics,node_anomaly_ml,node_epanet toneAmber
class node_database,node_models,node_seed toneMint
class node_react_app,node_api_client,node_websocket_client,node_operator_portal,node_network_map toneRose
```

## Components

### Backend API & Operations

- [FastAPI application](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/main.py): Python/FastAPI · Backend entry point and route host. · `backend/app/main.py`
- [Auth & access policy](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/api/deps.py): authorization · Enforces role and service-area boundaries. · `backend/app/api/deps.py`
- [Security primitives](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/core/security.py): authentication · `backend/app/core/security.py`
- [Domain route modules](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/api/routes/auth.py): API adapters · Telemetry, incidents, rerouting, energy, EPANET, maintenance, quality, and live APIs. · `backend/app/api/routes/auth.py`
- [Operational services](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/incident_service.py): domain orchestration · Creates incidents and dispatch recommendations from telemetry. · `backend/app/services/incident_service.py`
- [Telemetry service](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/telemetry_service.py): domain service · `backend/app/services/telemetry_service.py`
- [Dispatch service](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/dispatch_service.py): response planning · `backend/app/services/dispatch_service.py`

### Simulation & Detection

- [Simulation control API](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/api/routes/simulation.py): control plane · Selects scenarios and reset operations. · `backend/app/api/routes/simulation.py`
- [Network simulator](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/simulator/simulator.py): scenario engine · Generates modeled node-level telemetry. · `backend/app/simulator/simulator.py`
- [Modeled network state](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/simulator/state.py): simulation state · `backend/app/simulator/state.py`
- [Fusion detection](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/analytics/fusion.py): analytics · Combines hydraulic and statistical evidence. · `backend/app/analytics/fusion.py`
- [Leak estimation](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/physics/leak_estimation.py): hydraulic analysis · `backend/app/physics/leak_estimation.py`
- [Isolation Forest](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/ml/isolation_forest.py): ML scoring · `backend/app/ml/isolation_forest.py`
- [EPANET adapter](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/services/epanet_service.py): external engine boundary · Optional external hydraulic-engine integration. · `backend/app/services/epanet_service.py`

### System of Record

- [SQLite / SQLAlchemy](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/db/database.py): system of record · `backend/app/db/database.py`
- [Unified domain models](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/models/models.py): SQLAlchemy models · Users, assets, telemetry, incidents, and audit entities. · `backend/app/models/models.py`
- [Municipal seed data](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/backend/app/db/seed.py): bootstrap data · `backend/app/db/seed.py`

### Browser Client

- [React dashboard](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/App.tsx): React/Vite client · Role-oriented operations portals and workflows. · `frontend/src/App.tsx`
- [REST API client](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/services/api.ts): frontend integration · `frontend/src/services/api.ts`
- [Live updates client](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/services/websocket.ts): WebSocket integration · Receives critical state and burst alerts. · `frontend/src/services/websocket.ts`
- [Operator portal](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/pages/OperatorPortal.tsx): role view · `frontend/src/pages/OperatorPortal.tsx`
- [Network map](https://github.com/niloydebbarma-code/aquaflow-cloud/blob/main/frontend/src/components/NetworkMap.tsx): map component · `frontend/src/components/NetworkMap.tsx`

## Connections

- 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
