# diyachuphal/electricity-theft-detector architecture

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

- Interactive diagram: https://gitdiagram.com/diyachuphal/electricity-theft-detector
- Repository: https://github.com/diyachuphal/electricity-theft-detector

## Overview

The product is a batch smart-meter anomaly detection pipeline with a Streamlit inspection dashboard. Its documented workflow transforms meter tables into daily features, scores meter-days with an Isolation Forest, and presents ranked flags and usage histories. Source confirms CSV inputs/outputs, model persistence, and dashboard reads; broader capabilities such as explainable reasons are represented by displayed feature values, not a separate explanation engine.

Main entry points: [`app/app.py`](https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py) (Dashboard), [`src/train_model.py`](https://github.com/diyachuphal/electricity-theft-detector/blob/main/src/train_model.py) (Train and score), [`src/feature_engineering.py`](https://github.com/diyachuphal/electricity-theft-detector/blob/main/src/feature_engineering.py) (Feature engineering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Detection Pipeline"]
  node_feature_engineering["Feature engineering"]
  node_model_training["Train and score<br/>[train_model.py]"]
  node_isolation_forest["Isolation Forest<br/>[train_model.py]"]
end

subgraph group_dashboard["Inspection Dashboard"]
  node_dashboard_app["Dashboard<br/>[app.py]"]
  node_risk_summary["Risk ranking<br/>[app.py]"]
  node_meter_history["Usage drill-down<br/>[app.py]"]
  node_flag_reasons["Feature values<br/>[app.py]"]
end

subgraph group_data["Meter Data"]
  node_meterdata["Meter CSV tables"]
  node_daily_features["Daily features"]
  node_model_file["Saved model"]
  node_flagged_data["Flagged meter-days"]
end

node_operator(("Pipeline operator"))
node_inspector(("Field inspector"))

node_operator -->|"runs"| node_feature_engineering
node_meterdata -->|"reads"| node_feature_engineering
node_feature_engineering -->|"writes"| node_daily_features
node_operator -->|"runs"| node_model_training
node_daily_features -->|"reads"| node_model_training
node_model_training -->|"fits and scores"| node_isolation_forest
node_model_training -->|"saves"| node_model_file
node_model_training -->|"writes"| node_flagged_data
node_inspector -->|"views"| node_dashboard_app
node_dashboard_app -->|"reads"| node_flagged_data
node_dashboard_app -->|"summarizes"| node_risk_summary
node_dashboard_app -->|"drills down"| node_meter_history
node_dashboard_app -->|"displays"| node_flag_reasons

click node_feature_engineering "https://github.com/diyachuphal/electricity-theft-detector/blob/main/src/feature_engineering.py"
click node_model_training "https://github.com/diyachuphal/electricity-theft-detector/blob/main/src/train_model.py"
click node_isolation_forest "https://github.com/diyachuphal/electricity-theft-detector/blob/main/src/train_model.py"
click node_dashboard_app "https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py"
click node_risk_summary "https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py"
click node_meter_history "https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py"
click node_flag_reasons "https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py"

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_feature_engineering,node_model_training,node_isolation_forest toneBlue
class node_dashboard_app,node_risk_summary,node_meter_history,node_flag_reasons toneAmber
class node_meterdata,node_daily_features,node_model_file,node_flagged_data toneMint
class node_operator,node_inspector toneIndigo
```

## Components

### Detection Pipeline

- [Feature engineering](https://github.com/diyachuphal/electricity-theft-detector/blob/main/src/feature_engineering.py): `src/feature_engineering.py`
- [Train and score](https://github.com/diyachuphal/electricity-theft-detector/blob/main/src/train_model.py): `src/train_model.py`
- [Isolation Forest](https://github.com/diyachuphal/electricity-theft-detector/blob/main/src/train_model.py): `src/train_model.py`

### Inspection Dashboard

- [Dashboard](https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py): `app/app.py`
- [Risk ranking](https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py): `app/app.py`
- [Usage drill-down](https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py): `app/app.py`
- [Feature values](https://github.com/diyachuphal/electricity-theft-detector/blob/main/app/app.py): `app/app.py`

### Meter Data

- **Meter CSV tables**
- **Daily features**
- **Saved model**
- **Flagged meter-days**

### Other components

- **Pipeline operator**
- **Field inspector**

## Connections

- Pipeline operator → Feature engineering: runs
- Meter CSV tables → Feature engineering: reads
- Feature engineering → Daily features: writes
- Pipeline operator → Train and score: runs
- Daily features → Train and score: reads
- Train and score → Isolation Forest: fits and scores
- Train and score → Saved model: saves
- Train and score → Flagged meter-days: writes
- Field inspector → Dashboard: views
- Dashboard → Flagged meter-days: reads
- Dashboard → Risk ranking: summarizes
- Dashboard → Usage drill-down: drills down
- Dashboard → Feature values: displays
