# codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn architecture

> Architecture diagram of the GitHub repository codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn
- Repository: https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn

## Overview

The product is a real-time environmental WSN fault-monitoring system. Sensor readings are simulated or supplied by nodes, sent to a Flask API, checked by a three-layer detector, persisted, and exposed to a live dashboard; separate training and evaluation flows support the ML capability. The README documents the end-to-end flow, while some route internals and dashboard implementation details were not sampled, so those links rely on documented behavior.

Main entry points: [`server.py`](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/server.py) (Flask API), [`detection_system/hybrid_detector.py`](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py) (Hybrid Detector), [`detection_system/ml_trainer.py`](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/ml_trainer.py) (Model Trainer), [`database/db_manager.py`](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/database/db_manager.py) (Database Access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Sensor Ingestion"]
  node_simulator["Node Simulator<br/>[node_simulator.py]"]
  node_sensor_client["Simulator Client<br/>[sensor_client.py]"]
end

subgraph group_detect["Fault Detection"]
  node_peer_cache["Cluster Peer Cache<br/>[server.py]"]
  node_hybrid["Hybrid Detector<br/>[hybrid_detector.py]"]
  node_rules["Rule Checks<br/>[hybrid_detector.py]"]
  node_cluster_checks["Cluster Checks<br/>[hybrid_detector.py]"]
  node_ml_inference["ML Inference<br/>[hybrid_detector.py]"]
  node_fusion["Decision Fusion<br/>[hybrid_detector.py]"]
end

subgraph group_data["Persistence and API"]
  node_api["Flask API<br/>[server.py]"]
  node_validation["Payload Validation<br/>[server.py]"]
  node_db_manager["Database Access<br/>[db_manager.py]"]
  node_sqlite[("SQLite Store<br/>[wsn_detections.db]")]
end

subgraph group_model["ML Lifecycle"]
  node_training_data["Training Dataset"]
  node_trainer["Model Trainer<br/>[ml_trainer.py]"]
  node_model_artifacts["Model Artifacts"]
  node_metrics["ML Metrics<br/>[ml_metrics.json]"]
  node_report["Evaluation Report<br/>[generate_report.py]"]
end

subgraph group_experience["Monitoring Experience"]
  node_dashboard["Live Dashboard<br/>[dashboard.html]"]
end

node_sensor_nodes(("Sensor Nodes"))
node_dashboard_user(("Dashboard User"))

node_sensor_nodes -->|"simulated by"| node_simulator
node_simulator -->|"generates readings"| node_sensor_client
node_sensor_client -->|"POSTs readings"| node_api
node_sensor_nodes -.->|"sends readings"| node_api
node_api -->|"validates payload"| node_validation
node_api -->|"updates peers"| node_peer_cache
node_api -->|"runs detection"| node_hybrid
node_peer_cache -.->|"provides peers"| node_hybrid
node_hybrid -->|"checks thresholds"| node_rules
node_hybrid -->|"checks peer anomalies"| node_cluster_checks
node_hybrid -->|"classifies readings"| node_ml_inference
node_rules -->|"votes in"| node_fusion
node_cluster_checks -->|"votes in"| node_fusion
node_ml_inference -->|"votes in"| node_fusion
node_api -->|"stores result"| node_db_manager
node_db_manager -->|"writes and queries"| node_sqlite
node_api -->|"queries status and history"| node_db_manager
node_trainer -->|"loads dataset"| node_training_data
node_trainer -->|"saves model files"| node_model_artifacts
node_trainer -->|"writes metrics"| node_metrics
node_hybrid -->|"loads classifier"| node_model_artifacts
node_report -->|"evaluates dataset"| node_training_data
node_report -->|"loads trained artifacts"| node_model_artifacts
node_dashboard_user -->|"views"| node_dashboard
node_dashboard -->|"fetches live data"| node_api
node_api -->|"serves metrics"| node_metrics

click node_simulator "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/testing_environment/node_simulator.py"
click node_sensor_client "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/sensor_client.py"
click node_api "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/server.py"
click node_validation "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/server.py"
click node_peer_cache "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/server.py"
click node_hybrid "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py"
click node_rules "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py"
click node_cluster_checks "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py"
click node_ml_inference "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py"
click node_fusion "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py"
click node_db_manager "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/database/db_manager.py"
click node_sqlite "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/database/wsn_detections.db"
click node_training_data "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/database/wsn_aft_dataset.csv"
click node_trainer "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/ml_trainer.py"
click node_model_artifacts "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/tree/main/models"
click node_metrics "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/evaluation/ml_metrics.json"
click node_report "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/evaluation/generate_report.py"
click node_dashboard "https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/static/dashboard.html"

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_simulator,node_sensor_client,node_dashboard_user toneBlue
class node_peer_cache,node_hybrid,node_rules,node_cluster_checks,node_ml_inference,node_fusion toneAmber
class node_api,node_validation,node_db_manager,node_sqlite toneMint
class node_training_data,node_trainer,node_model_artifacts,node_metrics,node_report toneRose
class node_dashboard,node_sensor_nodes toneIndigo
```

## Components

### Sensor Ingestion

- [Node Simulator](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/testing_environment/node_simulator.py): `testing_environment/node_simulator.py`
- [Simulator Client](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/sensor_client.py): `sensor_client.py`

### Fault Detection

- [Cluster Peer Cache](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/server.py): `server.py`
- [Hybrid Detector](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py): `detection_system/hybrid_detector.py`
- [Rule Checks](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py): `detection_system/hybrid_detector.py`
- [Cluster Checks](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py): `detection_system/hybrid_detector.py`
- [ML Inference](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py): `detection_system/hybrid_detector.py`
- [Decision Fusion](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/hybrid_detector.py): `detection_system/hybrid_detector.py`

### Persistence and API

- [Flask API](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/server.py): `server.py`
- [Payload Validation](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/server.py): `server.py`
- [Database Access](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/database/db_manager.py): `database/db_manager.py`
- [SQLite Store](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/database/wsn_detections.db): `database/wsn_detections.db`

### ML Lifecycle

- [Training Dataset](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/database/wsn_aft_dataset.csv): `database/wsn_aft_dataset.csv`
- [Model Trainer](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/detection_system/ml_trainer.py): `detection_system/ml_trainer.py`
- [Model Artifacts](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/tree/main/models): `models`
- [ML Metrics](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/evaluation/ml_metrics.json): `evaluation/ml_metrics.json`
- [Evaluation Report](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/evaluation/generate_report.py): `evaluation/generate_report.py`

### Monitoring Experience

- [Live Dashboard](https://github.com/codingguna/enhanced-fault-node-detection-in-environmental-monitoring-wsn/blob/main/static/dashboard.html): `static/dashboard.html`

### Other components

- **Sensor Nodes**
- **Dashboard User**

## Connections

- Sensor Nodes → Node Simulator: simulated by (evidence: `README.md`)
- Node Simulator → Simulator Client: generates readings (evidence: `sensor_client.py`)
- Simulator Client → Flask API: POSTs readings (evidence: `sensor_client.py`)
- Sensor Nodes → Flask API: sends readings
- Flask API → Payload Validation: validates payload (evidence: `server.py`)
- Flask API → Cluster Peer Cache: updates peers (evidence: `server.py`)
- Flask API → Hybrid Detector: runs detection (evidence: `README.md`)
- Cluster Peer Cache → Hybrid Detector: provides peers (evidence: `server.py`)
- Hybrid Detector → Rule Checks: checks thresholds (evidence: `README.md`)
- Hybrid Detector → Cluster Checks: checks peer anomalies (evidence: `README.md`)
- Hybrid Detector → ML Inference: classifies readings (evidence: `README.md`)
- Rule Checks → Decision Fusion: votes in (evidence: `detection_system/hybrid_detector.py`)
- Cluster Checks → Decision Fusion: votes in (evidence: `detection_system/hybrid_detector.py`)
- ML Inference → Decision Fusion: votes in (evidence: `detection_system/hybrid_detector.py`)
- Flask API → Database Access: stores result (evidence: `README.md`)
- Database Access → SQLite Store: writes and queries (evidence: `database/db_manager.py`)
- Flask API → Database Access: queries status and history (evidence: `server.py`)
- Model Trainer → Training Dataset: loads dataset (evidence: `detection_system/ml_trainer.py`)
- Model Trainer → Model Artifacts: saves model files (evidence: `detection_system/ml_trainer.py`)
- Model Trainer → ML Metrics: writes metrics (evidence: `detection_system/ml_trainer.py`)
- Hybrid Detector → Model Artifacts: loads classifier (evidence: `detection_system/hybrid_detector.py`)
- Evaluation Report → Training Dataset: evaluates dataset (evidence: `evaluation/generate_report.py`)
- Evaluation Report → Model Artifacts: loads trained artifacts (evidence: `evaluation/generate_report.py`)
- Dashboard User → Live Dashboard: views (evidence: `README.md`)
- Live Dashboard → Flask API: fetches live data (evidence: `README.md`)
- Flask API → ML Metrics: serves metrics (evidence: `server.py`)
