# hxtanishq/ddos_prediction architecture

> Architecture diagram of the GitHub repository hxtanishq/ddos_prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hxtanishq/ddos_prediction
- Repository: https://github.com/hxtanishq/ddos_prediction

## Overview

##### Project type and purpose
- From the file tree and README, this is a full-stack web application with an embedded machine-learning pipeline.
- Purpose: Real-time DDoS detection using an LSTM-RNN model, plus a Flask-based web UI for monitoring, testing, and managing the system.

##### File structure
- Top-level scripts:
- server.py: Flask app exposing REST endpoints
- prediction.py: real-time inference code loading the trained model
- train_model.py + dataloader.py: offline ML training pipeline
- attack.py: synthetic DDoS traffic generator for test mode
- main.py: (likely) orchestrator or legacy entry point
- Directories:
- data/: raw or preprocessed CSV data for training/testing
- model/: stored artifacts (Keras .h5, scalers, encoders, metrics)
- logs/: runtime prediction logs for download and audit
- templates/: Jinja2 HTML (index.html, monitor.html) for the UI
- test/: unit or integration tests
- Config/build files:
- requirements.txt: Python dependencies (Flask, TensorFlow/Keras, Chart.js, etc.)

##### README for architecture hints
- Three primary subsystems described:
a. Real-time traffic monitoring (endpoints /status, /total_count)
b. DDoS detection via LSTM-RNN (offline training vs online inference)
c. Web interface (dashboard, charts, test trigger, log download)
- Simulation & testing via attack.py and “Test Detection” UI button
- Logging and model-metrics reporting endpoints

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Storage Layer
    subgraph "Data Storage"
        direction TB
        RawData["Raw/Training Data\ndata/data.csv"]:::storage
        ModelArtifacts["Model Artifacts\n(model/*.h5, *.pkl, metrics)"]:::storage
        Logs["Inference & Audit Logs\nlogs/OUTPUT*.csv"]:::storage
    end

    %% Offline ML Pipeline
    subgraph "Offline ML Pipeline"
        direction TB
        DL["Data Loader\ndataloader.py"]:::ml
        Trainer["Training Service\ntrain_model.py"]:::ml
    end

    %% Online Inference Pipeline
    subgraph "Online Inference Pipeline"
        direction TB
        Server["Flask REST API\nserver.py"]:::backend
        Predictor["Prediction Engine\nprediction.py"]:::ml
    end

    %% Frontend UI
    subgraph "Frontend Dashboard" 
        direction TB
        Index["Index Page\ntemplates/index.html"]:::frontend
        Monitor["Monitor Page\ntemplates/monitor.html"]:::frontend
    end

    %% External / Simulation
    subgraph "External Traffic & Simulation"
        direction TB
        Traffic["Client / Network Traffic"]:::external
        AttackSim["Attack Simulator\nattack.py"]:::external
    end

    %% Miscellaneous Components
    subgraph "Other Components"
        direction TB
        Orchestrator["Orchestrator\nmain.py"]:::backend
        Requirements["Dependencies\nrequirements.txt"]:::backend
        Tests["Tests\ntest/"]:::backend
    end

    %% Connections: Offline
    RawData -->|"reads CSV"| DL
    DL -->|"preprocessed features"| Trainer
    Trainer -->|"saves model"| ModelArtifacts

    %% Connections: Online Inference
    ModelArtifacts -->|"loaded at startup"| Predictor
    Predictor -->|"prediction result"| Server
    Server -->|"logs result"| Logs

    %% Connections: Traffic
    Traffic -->|"HTTP/JSON"| Server
    AttackSim -->|"simulated traffic"| Traffic
    Server -->|"serves UI data"| Index
    Server -->|"serves UI data"| Monitor
    Monitor -->|"polls endpoints"| Server
    Index -->|"Test Detection"| Server
    Server -->|"invokes"| AttackSim

    %% UI Chart Updates
    Monitor -->|"fetch /status, /total_count"| Server

    %% Misc
    Requirements
    Tests
    Orchestrator

    %% Click Events
    click RawData "https://github.com/hxtanishq/ddos_prediction/blob/main/data/data.csv"
    click ModelArtifacts "https://github.com/hxtanishq/ddos_prediction/tree/main/model"
    click Logs "https://github.com/hxtanishq/ddos_prediction/blob/main/logs/OUTPUT.20250225_204211.csv"
    click DL "https://github.com/hxtanishq/ddos_prediction/blob/main/dataloader.py"
    click Trainer "https://github.com/hxtanishq/ddos_prediction/blob/main/train_model.py"
    click Server "https://github.com/hxtanishq/ddos_prediction/blob/main/server.py"
    click Predictor "https://github.com/hxtanishq/ddos_prediction/blob/main/prediction.py"
    click Index "https://github.com/hxtanishq/ddos_prediction/blob/main/templates/index.html"
    click Monitor "https://github.com/hxtanishq/ddos_prediction/blob/main/templates/monitor.html"
    click AttackSim "https://github.com/hxtanishq/ddos_prediction/blob/main/attack.py"
    click Orchestrator "https://github.com/hxtanishq/ddos_prediction/blob/main/main.py"
    click Requirements "https://github.com/hxtanishq/ddos_prediction/blob/main/requirements.txt"
    click Tests "https://github.com/hxtanishq/ddos_prediction/tree/main/test/"

    %% Styles
    classDef frontend fill:#8FD8D2,stroke:#004D40,color:#000;
    classDef backend fill:#A5D6A7,stroke:#1B5E20,color:#000;
    classDef ml fill:#CE93D8,stroke:#6A1B9A,color:#000;
    classDef storage fill:#B0BEC5,stroke:#263238,color:#000;
    classDef external fill:#FFCC80,stroke:#E65100,color:#000;
```
