AI-powered anomaly detection for SCADA water networks using a trained Conv1D Autoencoder.
Full-stack system: FastAPI backend Β· Web dashboard Β· Flutter mobile app.
Water-Leak/
βββ backend/ β FastAPI + TensorFlow inference
β βββ main.py β App entry point
β βββ model/
β β βββ predictor.py β Real + Mock autoencoder inference
β β βββ zones.py β Zone mapping (n1βZone1 β¦ n300βZone5)
β βββ api/routes/
β β βββ predict.py β POST /predict
β β βββ reports.py β POST /report Β· GET /alerts
β β βββ analytics.py β GET /analytics Β· GET /timeseries
β β βββ auth.py β User & Engineer register/login
β βββ db/
β β βββ database.py β SQLAlchemy + SQLite engine
β β βββ models.py β users Β· engineers Β· reports Β· anomalies Β· sensor_logs Β· outages
β βββ schemas/
β β βββ schemas.py β Pydantic v2 request/response models
β βββ model_files/ β DROP .keras + .pkl FILES HERE
β βββ requirements.txt
β βββ .env
β
βββ dashboard/ β Browser-based control panel
β βββ index.html
β βββ style.css β Dark-mode glassmorphism design
β βββ app.js β Synthetic data generators + Chart.js
β
βββ mobile/ β Flutter mobile app
β βββ pubspec.yaml
β βββ lib/
β βββ main.dart
β βββ theme/app_theme.dart
β βββ models/prediction_model.dart
β βββ services/api_service.dart
β βββ screens/
β βββ role_selection_screen.dart
β βββ auth/login_screen.dart
β βββ auth/register_screen.dart
β βββ user/user_home_screen.dart
β βββ user/report_issue_screen.dart
β βββ engineer/engineer_dashboard_screen.dart
β βββ engineer/analytics_screen.dart
β
βββ run_system.bat β One-click Windows startup script
βββ another_copy_of_water_leakage_advanced.py β Original training notebook
# Windows β double-click or run:
run_system.bat# Manual
cd backend
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload --host 0.0.0.0 --port 8000| URL | Purpose |
|---|---|
| http://localhost:8000/docs | Interactive Swagger UI |
| http://localhost:8000/health | Model status + sensor count |
| http://localhost:8000/redoc | ReDoc documentation |
Simply open in your browser β no build step needed:
dashboard/index.html
Click the three buttons to test the detection pipeline live.
cd mobile
flutter pub get
flutter runAndroid emulator: Backend URL is pre-set to
http://10.0.2.2:8000
Physical device / iOS: UpdatebaseUrlinlib/services/api_service.dart
Place your trained files in backend/model_files/:
backend/model_files/
βββ water_leakage_model.keras β from training notebook
βββ scaler.pkl β RobustScaler
βββ threshold.pkl β 95th-percentile MSE float
No files? The backend auto-switches to a smart mock predictor that correctly classifies Leak / Normal / Random data based on statistical patterns β perfect for development.
// Request
{
"data": [[...], [...], ...] // shape (48, N_sensors)
}
// Response
{
"is_anomaly": 1,
"confidence": 0.8742,
"mse": 0.234512,
"threshold": 0.100000,
"top_sensors": ["n33", "n28", "n74"],
"zone": "Zone 2",
"sensor_errors": [0.001, 0.023, ...],
"message": "β οΈ Leak detected in Zone 2 with 87.4% confidence",
"latency_ms": 12.4
}{ "zone": "Zone 3", "description": "Visible puddle near node 65", "severity": "high" }{ "name": "Ahmed", "address": "...", "zone": "Zone 1", "phone": "...", "email": "...", "password": "..." }{ "engineer_id": "ENG-001", "password": "..." }{ "zone": "Zone 1", "title": "Main pipe repair", "description": "...", "start_time": "2026-05-14T20:00:00Z", "end_time": "2026-05-14T22:00:00Z" }| Table | Key Columns |
|---|---|
users |
id Β· name Β· email Β· phone Β· zone Β· password_hash |
engineers |
id Β· engineer_id Β· name Β· password_hash |
reports |
id Β· user_id Β· zone Β· description Β· severity Β· status |
anomalies |
id Β· is_anomaly Β· confidence Β· mse Β· threshold Β· top_sensors Β· zone |
sensor_logs |
id Β· timestamp Β· num_sensors Β· mean_value Β· std_value Β· anomaly_detected |
water_outages |
id Β· zone Β· title Β· description Β· start_time Β· end_time Β· is_cancelled |
| Zone | Sensors | Description |
|---|---|---|
| Zone 1 | n1 β n30 | Early Network (Intake / Primary Pipes) |
| Zone 2 | n31 β n60 | Middle Distribution Network |
| Zone 3 | n61 β n90 | Main Distribution Grid |
| Zone 4 | n91 β n120 | End Network / High Pressure Zones |
| Zone 5 | n121 β n300 | Extended / Remote Network |
| Screen | Role | Features |
|---|---|---|
| Role Selection | Both | Animated User/Engineer card selection |
| Login | Both | Email/phone + password Β· Forgot password |
| Register | User | 6-field form Β· Zone dropdown Β· Password confirm |
| User Home | User | Alerts feed Β· Report issue Β· Water-saving tips Β· Active Outages |
| Report Issue | User | Zone + severity + description Β· Success animation |
| Outages | User | Full-screen alarm notification Β· Countdown timer |
| Engineer Dashboard | Engineer | Overview KPIs Β· Pressure/flow charts Β· Alerts tab |
| Analytics | Engineer | Bar chart Β· Zone leaks table Β· Period filter |
- Passwords hashed with
bcrypt(12 rounds) - JWT tokens with 7-day expiry
- Change
SECRET_KEYin.envbefore any production deployment - Restrict CORS
allow_originsto your actual frontend domain in production
# Leak data β should return is_anomaly: 1
curl -X POST http://localhost:8000/api/v1/predict \
-H "Content-Type: application/json" \
-d @- << 'EOF'
{
"data": [
[-0.0, -0.1, -0.2, 0.01, 0.02, 0.0, -0.01, 0.01, 0.0, -0.02,
0.0, 0.01, -0.01, 0.0, 0.01, -0.01, 0.0, 0.01, 0.0, -0.01],
[-0.1, -0.2, -0.35, 0.0, 0.01, -0.01, 0.0, 0.01, 0.0, -0.01,
0.01, 0.0, -0.01, 0.0, 0.01, 0.0, 0.01, 0.0, 0.01, 0.0]
]
}
EOFTip: Use the web dashboard buttons for a richer visual test experience.