# sumit-chand/hybrid-nids architecture

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

- Interactive diagram: https://gitdiagram.com/sumit-chand/hybrid-nids
- Repository: https://github.com/sumit-chand/hybrid-nids

## Overview

Hybrid ML + signature network intrusion detection system: train or load a classifier, submit flow records through the Flask dashboard/API, combine deterministic signatures with model predictions, and persist alerts for history and statistics. The README also documents CSV upload, simulation, metrics, and alert clearing. Evidence for runtime links comes from the excerpts and README; live capture is explicitly not included.

Main entry points: [`app.py`](https://github.com/sumit-chand/hybrid-nids/blob/main/app.py) (Flask API), [`train.py`](https://github.com/sumit-chand/hybrid-nids/blob/main/train.py) (Training workflow), [`nids.py`](https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py) (Hybrid detector), [`templates/index.html`](https://github.com/sumit-chand/hybrid-nids/blob/main/templates/index.html) (Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["API and dashboard"]
  node_dashboard["Dashboard<br/>[index.html]"]
  node_api["Flask API<br/>[app.py]"]
  node_flow_input["Flow inputs<br/>[app.py]"]
end

subgraph group_detection["Flow detection"]
  node_generator["Synthetic flows<br/>[nids.py]"]
  node_features["Features and labels<br/>[nids.py]"]
  node_signatures["Signature rules<br/>[nids.py]"]
  node_detector["Hybrid detector<br/>[nids.py]"]
end

subgraph group_training["Model training"]
  node_model["Trained classifier<br/>[nids_model.joblib]"]
  node_trainer["Training workflow<br/>[train.py]"]
  node_cic_data["CIC-IDS2017 CSVs"]
  node_metrics["Training metrics<br/>[metrics.json]"]
end

subgraph group_storage["Alert history"]
  node_ingest["Alert ingestion<br/>[nids.py]"]
  node_alert_db[("SQLite alert store<br/>[nids.py]")]
  node_history["Alert history and stats<br/>[nids.py]"]
end

node_operator(("User"))

node_operator -->|"views"| node_dashboard
node_operator -->|"submits flows"| node_api
node_dashboard -.->|"uses endpoints"| node_api
node_api -->|"accepts uploads"| node_flow_input
node_api -->|"generates simulation"| node_generator
node_api -->|"submits flows"| node_ingest
node_api -->|"requests stats and alerts"| node_history
node_api -->|"reads metrics"| node_metrics
node_api -->|"clears records"| node_alert_db
node_trainer -->|"uses features"| node_features
node_trainer -->|"loads CSVs"| node_cic_data
node_trainer -->|"generates fallback data"| node_generator
node_features -->|"loads and cleans"| node_trainer
node_trainer -->|"saves classifier"| node_model
node_trainer -->|"writes metrics"| node_metrics
node_ingest -->|"inspects batch"| node_detector
node_detector -->|"applies rules"| node_signatures
node_detector -->|"loads classifier"| node_model
node_ingest -->|"writes alerts"| node_alert_db
node_history -->|"queries and clears"| node_alert_db

click node_dashboard "https://github.com/sumit-chand/hybrid-nids/blob/main/templates/index.html"
click node_api "https://github.com/sumit-chand/hybrid-nids/blob/main/app.py"
click node_flow_input "https://github.com/sumit-chand/hybrid-nids/blob/main/app.py"
click node_generator "https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py"
click node_features "https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py"
click node_signatures "https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py"
click node_detector "https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py"
click node_model "https://github.com/sumit-chand/hybrid-nids/blob/main/models/nids_model.joblib"
click node_trainer "https://github.com/sumit-chand/hybrid-nids/blob/main/train.py"
click node_metrics "https://github.com/sumit-chand/hybrid-nids/blob/main/models/metrics.json"
click node_ingest "https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py"
click node_alert_db "https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py"
click node_history "https://github.com/sumit-chand/hybrid-nids/blob/main/nids.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_dashboard,node_api,node_flow_input,node_operator toneBlue
class node_generator,node_features,node_signatures,node_detector toneAmber
class node_model,node_trainer,node_cic_data,node_metrics toneMint
class node_ingest,node_alert_db,node_history toneRose
```

## Components

### API and dashboard

- [Dashboard](https://github.com/sumit-chand/hybrid-nids/blob/main/templates/index.html): `templates/index.html`
- [Flask API](https://github.com/sumit-chand/hybrid-nids/blob/main/app.py): `app.py`
- [Flow inputs](https://github.com/sumit-chand/hybrid-nids/blob/main/app.py): `app.py`

### Flow detection

- [Synthetic flows](https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py): `nids.py`
- [Features and labels](https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py): `nids.py`
- [Signature rules](https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py): `nids.py`
- [Hybrid detector](https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py): `nids.py`

### Model training

- [Trained classifier](https://github.com/sumit-chand/hybrid-nids/blob/main/models/nids_model.joblib): `models/nids_model.joblib`
- [Training workflow](https://github.com/sumit-chand/hybrid-nids/blob/main/train.py): `train.py`
- **CIC-IDS2017 CSVs**
- [Training metrics](https://github.com/sumit-chand/hybrid-nids/blob/main/models/metrics.json): `models/metrics.json`

### Alert history

- [Alert ingestion](https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py): `nids.py`
- [SQLite alert store](https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py): `nids.py`
- [Alert history and stats](https://github.com/sumit-chand/hybrid-nids/blob/main/nids.py): `nids.py`

### Other components

- **User**

## Connections

- User → Dashboard: views (evidence: `README.md`)
- User → Flask API: submits flows (evidence: `README.md`)
- Dashboard → Flask API: uses endpoints
- Flask API → Flow inputs: accepts uploads (evidence: `app.py`)
- Flask API → Synthetic flows: generates simulation (evidence: `app.py`)
- Flask API → Alert ingestion: submits flows (evidence: `app.py`)
- Flask API → Alert history and stats: requests stats and alerts (evidence: `app.py`)
- Flask API → Training metrics: reads metrics (evidence: `app.py`)
- Flask API → SQLite alert store: clears records (evidence: `app.py`)
- Training workflow → Features and labels: uses features (evidence: `train.py`)
- Training workflow → CIC-IDS2017 CSVs: loads CSVs (evidence: `train.py`)
- Training workflow → Synthetic flows: generates fallback data (evidence: `train.py`)
- Features and labels → Training workflow: loads and cleans (evidence: `nids.py`)
- Training workflow → Trained classifier: saves classifier (evidence: `train.py`)
- Training workflow → Training metrics: writes metrics (evidence: `train.py`)
- Alert ingestion → Hybrid detector: inspects batch (evidence: `nids.py`)
- Hybrid detector → Signature rules: applies rules (evidence: `nids.py`)
- Hybrid detector → Trained classifier: loads classifier (evidence: `nids.py`)
- Alert ingestion → SQLite alert store: writes alerts (evidence: `nids.py`)
- Alert history and stats → SQLite alert store: queries and clears (evidence: `nids.py`)
