# vivekreddy1234/network_intrusion_detection architecture

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

- Interactive diagram: https://gitdiagram.com/vivekreddy1234/network_intrusion_detection
- Repository: https://github.com/vivekreddy1234/network_intrusion_detection

## Overview

This is a flow-based network intrusion detection system: the ML engine captures packets, aggregates them into flows, extracts features, classifies attack probability, and persists qualifying alerts; a separate Streamlit dashboard reads and visualizes those alerts. Training and preprocessing form a supporting model-development branch. Dashboard call paths are supported by excerpts; the README documents the live inference sequence, while the sniffer, trainer, and writer implementations were not excerpted.

Main entry points: [`dashboard/app.py`](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/app.py) (Dashboard Orchestrator), [`dashboard/services/data_service.py`](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/services/data_service.py) (Alert Queries and Metrics), [`dashboard/services/db.py`](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/services/db.py) (Read-only DB Access), [`ml-engine/models`](https://github.com/vivekreddy1234/network_intrusion_detection/tree/main/ml-engine/models) (Random Forest Inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Live Detection"]
  node_sniffer["Packet Sniffer<br/>[sniffer.py]"]
  node_flows["Flow Aggregator<br/>[flow_aggregator.py]"]
  node_classifier["Random Forest Inference"]
end

subgraph group_training["Model Training"]
  node_preprocessor["Data Preprocessing<br/>[preprocessor.py]"]
  node_trainer["Model Training<br/>[train.py]"]
end

subgraph group_storage["Alert Storage"]
  node_writer["Alert Writer<br/>[db_writer.py]"]
  node_alertsdb[("SQLite Alerts")]
end

subgraph group_dashboard["Dashboard"]
  node_app["Dashboard Orchestrator<br/>[app.py]"]
  node_data["Alert Queries and Metrics<br/>[data_service.py]"]
  node_db["Read-only DB Access<br/>[db.py]"]
  node_config["Dashboard Configuration<br/>[config.py]"]
end

subgraph group_presentation["Dashboard Components"]
  node_sidebar["Filters and Refresh<br/>[sidebar.py]"]
  node_header["Status Header<br/>[header.py]"]
  node_empty["Empty and Error States<br/>[empty_state.py]"]
  node_kpis["KPI Cards<br/>[kpi_cards.py]"]
  node_table["Alert Table<br/>[alerts_table.py]"]
  node_charts["Traffic Charts<br/>[charts.py]"]
  node_theme["Theme Styling<br/>[theme.py]"]
  node_formatting["Value Formatting<br/>[formatting.py]"]
end

node_traffic(("Network Traffic"))
node_dataset["CIC-IDS-2017 Dataset"]

node_traffic -->|"supplies packets"| node_sniffer
node_sniffer -->|"dispatches packets"| node_flows
node_flows -->|"extracts features for"| node_classifier
node_sniffer -->|"runs inference"| node_classifier
node_classifier -->|"passes alert"| node_writer
node_writer -->|"writes alerts"| node_alertsdb
node_dataset -->|"provides training data"| node_preprocessor
node_trainer -->|"uses preprocessing"| node_preprocessor
node_trainer -->|"trains model"| node_classifier
node_app -->|"checks connection"| node_db
node_app -->|"loads alert data"| node_data
node_data -->|"executes queries"| node_db
node_db -->|"reads"| node_alertsdb
node_app -->|"renders filters"| node_sidebar
node_app -->|"renders status"| node_header
node_app -->|"renders states"| node_empty
node_app -->|"renders metrics"| node_kpis
node_app -->|"renders alerts"| node_table
node_app -->|"renders charts"| node_charts
node_charts -->|"requests chart data"| node_data
node_sidebar -->|"uses filter defaults"| node_config
node_db -->|"uses database path"| node_config
node_data -->|"uses severity threshold"| node_config
node_app -->|"applies theme"| node_theme
node_charts -->|"uses chart styling"| node_theme
node_table -->|"formats probabilities"| node_formatting
node_header -->|"formats counts"| node_formatting

click node_sniffer "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/sniffer.py"
click node_flows "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/flow_aggregator.py"
click node_classifier "https://github.com/vivekreddy1234/network_intrusion_detection/tree/main/ml-engine/models"
click node_preprocessor "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/preprocessor.py"
click node_trainer "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/train.py"
click node_writer "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/db_writer.py"
click node_app "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/app.py"
click node_data "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/services/data_service.py"
click node_db "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/services/db.py"
click node_config "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/utils/config.py"
click node_sidebar "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/sidebar.py"
click node_header "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/header.py"
click node_empty "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/empty_state.py"
click node_kpis "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/kpi_cards.py"
click node_table "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/alerts_table.py"
click node_charts "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/charts.py"
click node_theme "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/utils/theme.py"
click node_formatting "https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/utils/formatting.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_sniffer,node_flows,node_classifier toneBlue
class node_preprocessor,node_trainer toneAmber
class node_writer,node_alertsdb toneMint
class node_app,node_data,node_db,node_config toneRose
class node_sidebar,node_header,node_empty,node_kpis,node_table,node_charts,node_theme,node_formatting,node_traffic,node_dataset toneIndigo
```

## Components

### Live Detection

- [Packet Sniffer](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/sniffer.py): `ml-engine/src/sniffer.py`
- [Flow Aggregator](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/flow_aggregator.py): `ml-engine/src/flow_aggregator.py`
- [Random Forest Inference](https://github.com/vivekreddy1234/network_intrusion_detection/tree/main/ml-engine/models): `ml-engine/models`

### Model Training

- [Data Preprocessing](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/preprocessor.py): `ml-engine/src/preprocessor.py`
- [Model Training](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/train.py): `ml-engine/src/train.py`

### Alert Storage

- [Alert Writer](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/ml-engine/src/db_writer.py): `ml-engine/src/db_writer.py`
- **SQLite Alerts**

### Dashboard

- [Dashboard Orchestrator](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/app.py): `dashboard/app.py`
- [Alert Queries and Metrics](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/services/data_service.py): `dashboard/services/data_service.py`
- [Read-only DB Access](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/services/db.py): `dashboard/services/db.py`
- [Dashboard Configuration](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/utils/config.py): `dashboard/utils/config.py`

### Dashboard Components

- [Filters and Refresh](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/sidebar.py): `dashboard/components/sidebar.py`
- [Status Header](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/header.py): `dashboard/components/header.py`
- [Empty and Error States](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/empty_state.py): `dashboard/components/empty_state.py`
- [KPI Cards](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/kpi_cards.py): `dashboard/components/kpi_cards.py`
- [Alert Table](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/alerts_table.py): `dashboard/components/alerts_table.py`
- [Traffic Charts](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/components/charts.py): `dashboard/components/charts.py`
- [Theme Styling](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/utils/theme.py): `dashboard/utils/theme.py`
- [Value Formatting](https://github.com/vivekreddy1234/network_intrusion_detection/blob/main/dashboard/utils/formatting.py): `dashboard/utils/formatting.py`

### Other components

- **Network Traffic**
- **CIC-IDS-2017 Dataset**

## Connections

- Network Traffic → Packet Sniffer: supplies packets (evidence: `README.md`)
- Packet Sniffer → Flow Aggregator: dispatches packets (evidence: `ml-engine/src/sniffer.py`)
- Flow Aggregator → Random Forest Inference: extracts features for (evidence: `README.md`)
- Packet Sniffer → Random Forest Inference: runs inference (evidence: `README.md`)
- Random Forest Inference → Alert Writer: passes alert (evidence: `README.md`)
- Alert Writer → SQLite Alerts: writes alerts (evidence: `README.md`)
- CIC-IDS-2017 Dataset → Data Preprocessing: provides training data (evidence: `README.md`)
- Model Training → Data Preprocessing: uses preprocessing (evidence: `ml-engine/src/train.py`)
- Model Training → Random Forest Inference: trains model (evidence: `README.md`)
- Dashboard Orchestrator → Read-only DB Access: checks connection (evidence: `dashboard/app.py`)
- Dashboard Orchestrator → Alert Queries and Metrics: loads alert data (evidence: `dashboard/app.py`)
- Alert Queries and Metrics → Read-only DB Access: executes queries (evidence: `dashboard/services/data_service.py`)
- Read-only DB Access → SQLite Alerts: reads (evidence: `README.md`)
- Dashboard Orchestrator → Filters and Refresh: renders filters (evidence: `dashboard/app.py`)
- Dashboard Orchestrator → Status Header: renders status (evidence: `dashboard/app.py`)
- Dashboard Orchestrator → Empty and Error States: renders states (evidence: `dashboard/app.py`)
- Dashboard Orchestrator → KPI Cards: renders metrics (evidence: `dashboard/app.py`)
- Dashboard Orchestrator → Alert Table: renders alerts (evidence: `dashboard/app.py`)
- Dashboard Orchestrator → Traffic Charts: renders charts (evidence: `dashboard/app.py`)
- Traffic Charts → Alert Queries and Metrics: requests chart data (evidence: `dashboard/components/charts.py`)
- Filters and Refresh → Dashboard Configuration: uses filter defaults (evidence: `dashboard/components/sidebar.py`)
- Read-only DB Access → Dashboard Configuration: uses database path (evidence: `dashboard/services/db.py`)
- Alert Queries and Metrics → Dashboard Configuration: uses severity threshold (evidence: `dashboard/services/data_service.py`)
- Dashboard Orchestrator → Theme Styling: applies theme (evidence: `dashboard/app.py`)
- Traffic Charts → Theme Styling: uses chart styling (evidence: `dashboard/components/charts.py`)
- Alert Table → Value Formatting: formats probabilities (evidence: `dashboard/components/alerts_table.py`)
- Status Header → Value Formatting: formats counts (evidence: `dashboard/components/header.py`)
