# pranesh-22kk/dos_attack_detection architecture

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

- Interactive diagram: https://gitdiagram.com/pranesh-22kk/dos_attack_detection
- Repository: https://github.com/pranesh-22kk/dos_attack_detection

## Overview

This repository is a WSN denial-of-service detection project. Its main workflow prepares and scales labeled traffic data, creates temporal train/validation/test splits, trains sequence classifiers, then processes UDP traffic at a gateway and publishes detections to a web dashboard. Separate node simulators represent normal and attack traffic. The tree and excerpts support the preprocessing, LSTM training, gateway inference, and Flask update flow; several listed gateway helpers and CNN/GRU training modules were not sampled, so their runtime relationships are not asserted.

Main entry points: [`WSN_DoS_Detection/realtime/gateway/gateway_detector.py`](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/gateway_detector.py) (Gateway detector), [`WSN_DoS_Detection/preprocessing/scale_features.py`](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/preprocessing/scale_features.py) (Feature scaling), [`WSN_DoS_Detection/models/lstm_model.h5`](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/models/lstm_model.h5) (LSTM model), [`WSN_DoS_Detection/realtime/web/app.py`](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/web/app.py) (Status API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Data preparation"]
  node_rawdata[("WSN-DS data<br/>[WSN-DS.csv]")]
  node_encode["Label encoding<br/>[encode_labels.py]"]
  node_features["Feature selection"]
  node_scale["Feature scaling<br/>[scale_features.py]"]
  node_scaleddata[("Scaled dataset<br/>[WSN-DS-scaled.csv]")]
end

subgraph group_training["Model training"]
  node_split["Sequence splitting"]
  node_sequencehelper["Sequence creation"]
  node_lstmtrain["LSTM training<br/>[train_lstm.py]"]
  node_cnntrain["CNN training<br/>[train_cnn.py]"]
  node_grutrain["GRU training<br/>[train_gru.py]"]
  node_model[("LSTM model<br/>[lstm_model.h5]")]
  node_scalerartifact[("Fitted scaler<br/>[scaler.save]")]
  node_evaluation["Model evaluation<br/>[evaluate_lstm.py]"]
end

subgraph group_realtime["Realtime detection"]
  node_normalnode["Normal node<br/>[normal_node.py]"]
  node_floodnode["Flooding node<br/>[flooding_node.py]"]
  node_blacknode["Blackhole node<br/>[blackhole_node.py]"]
  node_graynode["Grayhole node<br/>[grayhole_node.py]"]
  node_gateway["Gateway detector"]
  node_listener["Gateway listener"]
  node_aggregator["Feature aggregator"]
  node_sequencebuilder["Sequence builder"]
  node_realtimedetector["Realtime detector"]
  node_alerts["Alert manager<br/>[alert_manager.py]"]
end

subgraph group_dashboard["Dashboard"]
  node_webapp["Status API<br/>[app.py]"]
  node_dashboardview["Dashboard view<br/>[dashboard.html]"]
end

node_operator(("Operator"))

node_rawdata -->|"loads"| node_encode
node_encode -->|"writes encoded data"| node_features
node_features -->|"writes final data"| node_scale
node_scale -->|"writes scaled data"| node_scaleddata
node_scale -->|"saves scaler"| node_scalerartifact
node_scaleddata -->|"loads"| node_split
node_split -->|"saves training splits"| node_lstmtrain
node_lstmtrain -->|"saves checkpoint"| node_model
node_model -->|"loads for evaluation"| node_evaluation
node_normalnode -.->|"sends UDP"| node_gateway
node_floodnode -->|"sends UDP"| node_gateway
node_blacknode -->|"sends drop notice"| node_gateway
node_graynode -.->|"sends traffic"| node_gateway
node_model -->|"predicts with"| node_gateway
node_scalerartifact -->|"scales features"| node_gateway
node_gateway -->|"posts detection"| node_webapp
node_operator -->|"views status"| node_webapp
node_webapp -->|"renders"| node_dashboardview

click node_rawdata "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/dataset/WSN-DS.csv"
click node_encode "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/preprocessing/encode_labels.py"
click node_features "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/preprocessing/clean_and_select_features.py"
click node_scale "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/preprocessing/scale_features.py"
click node_scaleddata "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/dataset/WSN-DS-scaled.csv"
click node_split "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/train_val_test_split.py"
click node_sequencehelper "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/create_sequences.py"
click node_lstmtrain "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/train_lstm.py"
click node_cnntrain "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/train_cnn.py"
click node_grutrain "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/train_gru.py"
click node_model "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/models/lstm_model.h5"
click node_scalerartifact "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/models/scaler.save"
click node_evaluation "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/evaluate_lstm.py"
click node_normalnode "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/nodes/normal_node.py"
click node_floodnode "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/nodes/flooding_node.py"
click node_blacknode "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/nodes/blackhole_node.py"
click node_graynode "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/nodes/grayhole_node.py"
click node_gateway "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/gateway_detector.py"
click node_listener "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/gateway_listener.py"
click node_aggregator "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/feature_aggregator.py"
click node_sequencebuilder "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/sequence_builder.py"
click node_realtimedetector "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/realtime_detector.py"
click node_alerts "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/alert_manager.py"
click node_webapp "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/web/app.py"
click node_dashboardview "https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/web/templates/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_rawdata,node_encode,node_features,node_scale,node_scaleddata toneBlue
class node_split,node_sequencehelper,node_lstmtrain,node_cnntrain,node_grutrain,node_model,node_scalerartifact,node_evaluation toneAmber
class node_normalnode,node_floodnode,node_blacknode,node_graynode,node_gateway,node_listener,node_aggregator,node_sequencebuilder,node_realtimedetector,node_alerts toneMint
class node_webapp,node_dashboardview toneRose
class node_operator toneIndigo
```

## Components

### Data preparation

- [WSN-DS data](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/dataset/WSN-DS.csv): `WSN_DoS_Detection/dataset/WSN-DS.csv`
- [Label encoding](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/preprocessing/encode_labels.py): `WSN_DoS_Detection/preprocessing/encode_labels.py`
- [Feature selection](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/preprocessing/clean_and_select_features.py): `WSN_DoS_Detection/preprocessing/clean_and_select_features.py`
- [Feature scaling](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/preprocessing/scale_features.py): `WSN_DoS_Detection/preprocessing/scale_features.py`
- [Scaled dataset](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/dataset/WSN-DS-scaled.csv): `WSN_DoS_Detection/dataset/WSN-DS-scaled.csv`

### Model training

- [Sequence splitting](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/train_val_test_split.py): `WSN_DoS_Detection/training/train_val_test_split.py`
- [Sequence creation](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/create_sequences.py): `WSN_DoS_Detection/training/create_sequences.py`
- [LSTM training](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/train_lstm.py): `WSN_DoS_Detection/training/train_lstm.py`
- [CNN training](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/train_cnn.py): `WSN_DoS_Detection/training/train_cnn.py`
- [GRU training](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/train_gru.py): `WSN_DoS_Detection/training/train_gru.py`
- [LSTM model](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/models/lstm_model.h5): `WSN_DoS_Detection/models/lstm_model.h5`
- [Fitted scaler](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/models/scaler.save): `WSN_DoS_Detection/models/scaler.save`
- [Model evaluation](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/training/evaluate_lstm.py): `WSN_DoS_Detection/training/evaluate_lstm.py`

### Realtime detection

- [Normal node](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/nodes/normal_node.py): `WSN_DoS_Detection/realtime/nodes/normal_node.py`
- [Flooding node](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/nodes/flooding_node.py): `WSN_DoS_Detection/realtime/nodes/flooding_node.py`
- [Blackhole node](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/nodes/blackhole_node.py): `WSN_DoS_Detection/realtime/nodes/blackhole_node.py`
- [Grayhole node](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/nodes/grayhole_node.py): `WSN_DoS_Detection/realtime/nodes/grayhole_node.py`
- [Gateway detector](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/gateway_detector.py): `WSN_DoS_Detection/realtime/gateway/gateway_detector.py`
- [Gateway listener](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/gateway_listener.py): `WSN_DoS_Detection/realtime/gateway/gateway_listener.py`
- [Feature aggregator](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/feature_aggregator.py): `WSN_DoS_Detection/realtime/gateway/feature_aggregator.py`
- [Sequence builder](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/sequence_builder.py): `WSN_DoS_Detection/realtime/gateway/sequence_builder.py`
- [Realtime detector](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/realtime_detector.py): `WSN_DoS_Detection/realtime/gateway/realtime_detector.py`
- [Alert manager](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/gateway/alert_manager.py): `WSN_DoS_Detection/realtime/gateway/alert_manager.py`

### Dashboard

- [Status API](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/web/app.py): `WSN_DoS_Detection/realtime/web/app.py`
- [Dashboard view](https://github.com/pranesh-22kk/dos_attack_detection/blob/main/WSN_DoS_Detection/realtime/web/templates/dashboard.html): `WSN_DoS_Detection/realtime/web/templates/dashboard.html`

### Other components

- **Operator**

## Connections

- WSN-DS data → Label encoding: loads (evidence: `WSN_DoS_Detection/preprocessing/encode_labels.py`)
- Label encoding → Feature selection: writes encoded data (evidence: `WSN_DoS_Detection/preprocessing/encode_labels.py`)
- Feature selection → Feature scaling: writes final data (evidence: `WSN_DoS_Detection/preprocessing/scale_features.py`)
- Feature scaling → Scaled dataset: writes scaled data (evidence: `WSN_DoS_Detection/preprocessing/scale_features.py`)
- Feature scaling → Fitted scaler: saves scaler (evidence: `WSN_DoS_Detection/preprocessing/scale_features.py`)
- Scaled dataset → Sequence splitting: loads (evidence: `WSN_DoS_Detection/training/train_val_test_split.py`)
- Sequence splitting → LSTM training: saves training splits (evidence: `WSN_DoS_Detection/training/train_val_test_split.py`)
- LSTM training → LSTM model: saves checkpoint (evidence: `WSN_DoS_Detection/training/train_lstm.py`)
- LSTM model → Model evaluation: loads for evaluation (evidence: `WSN_DoS_Detection/training/evaluate_lstm.py`)
- Normal node → Gateway detector: sends UDP
- Flooding node → Gateway detector: sends UDP (evidence: `WSN_DoS_Detection/realtime/nodes/flooding_node.py`)
- Blackhole node → Gateway detector: sends drop notice (evidence: `WSN_DoS_Detection/realtime/nodes/blackhole_node.py`)
- Grayhole node → Gateway detector: sends traffic
- LSTM model → Gateway detector: predicts with (evidence: `WSN_DoS_Detection/realtime/gateway/gateway_detector.py`)
- Fitted scaler → Gateway detector: scales features (evidence: `WSN_DoS_Detection/realtime/gateway/gateway_detector.py`)
- Gateway detector → Status API: posts detection (evidence: `WSN_DoS_Detection/realtime/gateway/gateway_detector.py`)
- Operator → Status API: views status (evidence: `WSN_DoS_Detection/realtime/web/app.py`)
- Status API → Dashboard view: renders (evidence: `WSN_DoS_Detection/realtime/web/app.py`)
