# prajwalj1506/waterleakagedetection architecture

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

- Interactive diagram: https://gitdiagram.com/prajwalj1506/waterleakagedetection
- Repository: https://github.com/prajwalj1506/waterleakagedetection

## Overview

This is a water-leak inspection system: an engineer enters pressure, refill status, pipe identity and inspection metadata in the Android app; the app submits a reading to the FastAPI backend, which runs four trained models, averages their leak probabilities, and saves the result. The app then presents the prediction and supports dashboard, searchable/filterable history and record details. Backend persistence and model inference are shown in sampled source; Android-to-backend submission is documented, while unsampled implementation details are not inferred.

Main entry points: [`android/app/src/main/kotlin/com/waterleakage/app/data/repository/WaterLeakageRepository.kt`](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/repository/WaterLeakageRepository.kt) (API repository), [`android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt) (App navigation), [`backend/app/main.py`](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/main.py) (FastAPI entry), [`backend/app/routers/readings.py`](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/routers/readings.py) (Reading endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Android app"]
  node_navigation["App navigation<br/>[AppNavHost.kt]"]
  node_add["Add reading"]
  node_addvm["Submission state"]
  node_result["Prediction result"]
  node_resultvm["Result state"]
  node_dashboard["Dashboard<br/>[DashboardScreen.kt]"]
  node_dashboardvm["Dashboard state"]
  node_history["Reading history"]
  node_historyvm["History state"]
  node_details["Reading details"]
  node_detailvm["Detail state"]
  node_repository["API repository"]
  node_api_client["Server connection<br/>[ApiClient.kt]"]
  node_api_contract["API endpoints<br/>[WaterLeakageApi.kt]"]
  node_reading_models["Reading data models<br/>[ReadingModels.kt]"]
end

subgraph group_backend["API and inference"]
  node_backend_entry["FastAPI entry<br/>[main.py]"]
  node_reading_routes["Reading endpoints<br/>[readings.py]"]
  node_dashboard_routes["Dashboard endpoint<br/>[dashboard.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
  node_ml["Ensemble inference<br/>[ml_service.py]"]
  node_artifacts["Trained models"]
end

subgraph group_persistence["Reading storage"]
  node_db_session["Database session<br/>[database.py]"]
  node_reading_model["Reading records<br/>[models.py]"]
  node_sqlite[("SQLite database<br/>[water_leakage.db]")]
end

node_engineer(("Engineer"))

node_engineer -->|"opens app"| node_navigation
node_navigation -->|"shows"| node_dashboard
node_navigation -->|"routes to"| node_add
node_navigation -->|"routes to"| node_result
node_navigation -->|"routes to"| node_history
node_navigation -->|"routes to"| node_details
node_add -->|"uses state"| node_addvm
node_addvm -->|"submits reading"| node_repository
node_repository -->|"gets API client"| node_api_client
node_api_client -->|"creates client"| node_api_contract
node_repository -.->|"calls REST API"| node_backend_entry
node_backend_entry -->|"registers routes"| node_reading_routes
node_backend_entry -->|"registers routes"| node_dashboard_routes
node_backend_entry -->|"creates tables"| node_db_session
node_backend_entry -->|"loads models"| node_ml
node_reading_routes -->|"requests prediction"| node_ml
node_reading_routes -->|"uses session"| node_db_session
node_dashboard_routes -->|"queries records"| node_db_session
node_reading_routes -->|"validates and returns"| node_schemas
node_dashboard_routes -->|"returns summary"| node_schemas
node_ml -->|"loads models"| node_artifacts
node_db_session -->|"connects to"| node_sqlite
node_reading_routes -->|"creates and queries"| node_reading_model
node_dashboard_routes -->|"aggregates"| node_reading_model
node_reading_model -->|"uses ORM base"| node_db_session
node_addvm -->|"navigates after submit"| node_result
node_result -->|"uses state"| node_resultvm
node_resultvm -->|"loads reading"| node_repository
node_dashboard -->|"uses state"| node_dashboardvm
node_dashboardvm -->|"loads summary"| node_repository
node_history -->|"uses state"| node_historyvm
node_historyvm -->|"loads readings"| node_repository
node_details -->|"uses state"| node_detailvm
node_detailvm -->|"loads and deletes"| node_repository

click node_navigation "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt"
click node_add "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/add/AddReadingScreen.kt"
click node_addvm "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/add/AddReadingViewModel.kt"
click node_result "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/result/PredictionResultScreen.kt"
click node_resultvm "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/result/PredictionResultViewModel.kt"
click node_dashboard "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/dashboard/DashboardScreen.kt"
click node_dashboardvm "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/dashboard/DashboardViewModel.kt"
click node_history "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/history/ReadingHistoryScreen.kt"
click node_historyvm "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/history/ReadingHistoryViewModel.kt"
click node_details "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/details/ReadingDetailScreen.kt"
click node_detailvm "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/details/ReadingDetailViewModel.kt"
click node_repository "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/repository/WaterLeakageRepository.kt"
click node_api_client "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/remote/ApiClient.kt"
click node_api_contract "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/remote/WaterLeakageApi.kt"
click node_reading_models "https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/model/ReadingModels.kt"
click node_backend_entry "https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/main.py"
click node_reading_routes "https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/routers/readings.py"
click node_dashboard_routes "https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/routers/dashboard.py"
click node_schemas "https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/schemas.py"
click node_ml "https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/services/ml_service.py"
click node_artifacts "https://github.com/prajwalj1506/waterleakagedetection/tree/main/backend/artifacts"
click node_db_session "https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/database.py"
click node_reading_model "https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/models.py"
click node_sqlite "https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/water_leakage.db"

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_navigation,node_add,node_addvm,node_result,node_resultvm,node_dashboard,node_dashboardvm,node_history,node_historyvm,node_details,node_detailvm,node_repository,node_api_client,node_api_contract,node_reading_models toneBlue
class node_backend_entry,node_reading_routes,node_dashboard_routes,node_schemas,node_ml,node_artifacts toneAmber
class node_db_session,node_reading_model,node_sqlite toneMint
class node_engineer toneIndigo
```

## Components

### Android app

- [App navigation](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`
- [Add reading](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/add/AddReadingScreen.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/add/AddReadingScreen.kt`
- [Submission state](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/add/AddReadingViewModel.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/add/AddReadingViewModel.kt`
- [Prediction result](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/result/PredictionResultScreen.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/result/PredictionResultScreen.kt`
- [Result state](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/result/PredictionResultViewModel.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/result/PredictionResultViewModel.kt`
- [Dashboard](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/dashboard/DashboardScreen.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/dashboard/DashboardScreen.kt`
- [Dashboard state](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/dashboard/DashboardViewModel.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/dashboard/DashboardViewModel.kt`
- [Reading history](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/history/ReadingHistoryScreen.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/history/ReadingHistoryScreen.kt`
- [History state](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/history/ReadingHistoryViewModel.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/history/ReadingHistoryViewModel.kt`
- [Reading details](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/details/ReadingDetailScreen.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/details/ReadingDetailScreen.kt`
- [Detail state](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/ui/screens/details/ReadingDetailViewModel.kt): `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/details/ReadingDetailViewModel.kt`
- [API repository](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/repository/WaterLeakageRepository.kt): `android/app/src/main/kotlin/com/waterleakage/app/data/repository/WaterLeakageRepository.kt`
- [Server connection](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/remote/ApiClient.kt): `android/app/src/main/kotlin/com/waterleakage/app/data/remote/ApiClient.kt`
- [API endpoints](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/remote/WaterLeakageApi.kt): `android/app/src/main/kotlin/com/waterleakage/app/data/remote/WaterLeakageApi.kt`
- [Reading data models](https://github.com/prajwalj1506/waterleakagedetection/blob/main/android/app/src/main/kotlin/com/waterleakage/app/data/model/ReadingModels.kt): `android/app/src/main/kotlin/com/waterleakage/app/data/model/ReadingModels.kt`

### API and inference

- [FastAPI entry](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/main.py): `backend/app/main.py`
- [Reading endpoints](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/routers/readings.py): `backend/app/routers/readings.py`
- [Dashboard endpoint](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/routers/dashboard.py): `backend/app/routers/dashboard.py`
- [Request and response schemas](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/schemas.py): `backend/app/schemas.py`
- [Ensemble inference](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/services/ml_service.py): `backend/app/services/ml_service.py`
- [Trained models](https://github.com/prajwalj1506/waterleakagedetection/tree/main/backend/artifacts): `backend/artifacts`

### Reading storage

- [Database session](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/database.py): `backend/app/database.py`
- [Reading records](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/app/models.py): `backend/app/models.py`
- [SQLite database](https://github.com/prajwalj1506/waterleakagedetection/blob/main/backend/water_leakage.db): `backend/water_leakage.db`

### Other components

- **Engineer**

## Connections

- Engineer → App navigation: opens app
- App navigation → Dashboard: shows (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`)
- App navigation → Add reading: routes to (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`)
- App navigation → Prediction result: routes to (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`)
- App navigation → Reading history: routes to (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`)
- App navigation → Reading details: routes to (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`)
- Add reading → Submission state: uses state (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/add/AddReadingScreen.kt`)
- Submission state → API repository: submits reading (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/add/AddReadingViewModel.kt`)
- API repository → Server connection: gets API client (evidence: `android/app/src/main/kotlin/com/waterleakage/app/data/repository/WaterLeakageRepository.kt`)
- Server connection → API endpoints: creates client (evidence: `android/app/src/main/kotlin/com/waterleakage/app/data/remote/ApiClient.kt`)
- API repository → FastAPI entry: calls REST API (evidence: `README.md`)
- FastAPI entry → Reading endpoints: registers routes (evidence: `backend/app/main.py`)
- FastAPI entry → Dashboard endpoint: registers routes (evidence: `backend/app/main.py`)
- FastAPI entry → Database session: creates tables (evidence: `backend/app/main.py`)
- FastAPI entry → Ensemble inference: loads models (evidence: `backend/app/main.py`)
- Reading endpoints → Ensemble inference: requests prediction (evidence: `backend/app/routers/readings.py`)
- Reading endpoints → Database session: uses session (evidence: `backend/app/routers/readings.py`)
- Dashboard endpoint → Database session: queries records (evidence: `backend/app/routers/dashboard.py`)
- Reading endpoints → Request and response schemas: validates and returns (evidence: `backend/app/routers/readings.py`)
- Dashboard endpoint → Request and response schemas: returns summary (evidence: `backend/app/routers/dashboard.py`)
- Ensemble inference → Trained models: loads models (evidence: `backend/app/services/ml_service.py`)
- Database session → SQLite database: connects to (evidence: `backend/app/database.py`)
- Reading endpoints → Reading records: creates and queries (evidence: `backend/app/routers/readings.py`)
- Dashboard endpoint → Reading records: aggregates (evidence: `backend/app/routers/dashboard.py`)
- Reading records → Database session: uses ORM base (evidence: `backend/app/models.py`)
- Submission state → Prediction result: navigates after submit (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`)
- Prediction result → Result state: uses state (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/navigation/AppNavHost.kt`)
- Result state → API repository: loads reading (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/result/PredictionResultViewModel.kt`)
- Dashboard → Dashboard state: uses state (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/dashboard/DashboardScreen.kt`)
- Dashboard state → API repository: loads summary (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/dashboard/DashboardViewModel.kt`)
- Reading history → History state: uses state (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/history/ReadingHistoryScreen.kt`)
- History state → API repository: loads readings (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/history/ReadingHistoryViewModel.kt`)
- Reading details → Detail state: uses state (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/details/ReadingDetailScreen.kt`)
- Detail state → API repository: loads and deletes (evidence: `android/app/src/main/kotlin/com/waterleakage/app/ui/screens/details/ReadingDetailViewModel.kt`)
