# ruchitbhalerao/network-intrusion-detection architecture

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

- Interactive diagram: https://gitdiagram.com/ruchitbhalerao/network-intrusion-detection
- Repository: https://github.com/ruchitbhalerao/network-intrusion-detection

## Overview

This NIDS turns captured packets into normalized records, evaluates five configured rules, deduplicates alerts, and persists alerts for read-only API and dashboard viewing. Live capture is optional and explicitly started; synthetic records support demos. The README documents the API/dashboard behavior, while source excerpts show the engine, parser, rules, configuration, and SQLite interactions. The web presentation and some capture/API wiring are not sampled, so those relationships follow the README and SOURCE INDEX rather than inspected implementation.

Main entry points: [`nids/engine.py`](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/engine.py) (Detection engine), [`nids/detectors/base.py`](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/base.py) (Rule interface), [`nids/capture.py`](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/capture.py) (Live capture), [`nids/web`](https://github.com/ruchitbhalerao/network-intrusion-detection/tree/main/nids/web) (Web dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Packet ingestion"]
  node_capture["Live capture<br/>[capture.py]"]
  node_parser["Packet parser<br/>[parser.py]"]
  node_records["Synthetic records<br/>[synthetic.py]"]
end

subgraph group_detection["Detection pipeline"]
  node_models["Shared models<br/>[models.py]"]
  node_engine["Detection engine<br/>[engine.py]"]
  node_rulebase["Rule interface<br/>[base.py]"]
  node_portscan["Port scan rule<br/>[port_scan.py]"]
  node_rate["Rate anomaly rule<br/>[rate_anomaly.py]"]
  node_arp["ARP anomaly rule<br/>[arp_anomaly.py]"]
  node_unknown["Unknown device rule<br/>[unknown_device.py]"]
  node_repeated["Repeated connections rule"]
  node_dedup["Alert deduplicator<br/>[dedup.py]"]
end

subgraph group_state["Configuration and storage"]
  node_config["Config loader<br/>[config.py]"]
  node_sqlite[("SQLite persistence<br/>[db.py]")]
end

subgraph group_presentation["Read-only monitoring"]
  node_api["JSON API<br/>[api.py]"]
  node_dashboard["Web dashboard"]
end

node_operator(("Operator"))
node_browser(("Browser user"))

node_capture -->|"parses packets"| node_parser
node_capture -->|"submits records"| node_engine
node_parser -->|"creates records"| node_models
node_records -->|"creates records"| node_models
node_records -->|"feeds records"| node_engine
node_engine -->|"dispatches records"| node_portscan
node_engine -->|"dispatches records"| node_rate
node_engine -->|"dispatches records"| node_arp
node_engine -->|"dispatches records"| node_unknown
node_engine -->|"dispatches records"| node_repeated
node_portscan -->|"extends"| node_rulebase
node_rate -->|"extends"| node_rulebase
node_arp -->|"extends"| node_rulebase
node_unknown -->|"extends"| node_rulebase
node_repeated -->|"extends"| node_rulebase
node_engine -->|"filters alerts"| node_dedup
node_engine -->|"stores alerts"| node_sqlite
node_config -.->|"configures rules"| node_engine
node_operator -->|"starts optionally"| node_capture
node_operator -->|"views monitoring"| node_dashboard
node_api -->|"reads data"| node_sqlite
node_dashboard -->|"requests JSON"| node_api
node_browser -->|"views page"| node_dashboard

click node_capture "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/capture.py"
click node_parser "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/parser.py"
click node_records "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/synthetic.py"
click node_models "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/models.py"
click node_engine "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/engine.py"
click node_rulebase "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/base.py"
click node_portscan "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/port_scan.py"
click node_rate "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/rate_anomaly.py"
click node_arp "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/arp_anomaly.py"
click node_unknown "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/unknown_device.py"
click node_repeated "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/repeated_connections.py"
click node_dedup "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/dedup.py"
click node_config "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/config.py"
click node_sqlite "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/db.py"
click node_api "https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/api.py"
click node_dashboard "https://github.com/ruchitbhalerao/network-intrusion-detection/tree/main/nids/web"

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_capture,node_parser,node_records,node_browser toneBlue
class node_models,node_engine,node_rulebase,node_portscan,node_rate,node_arp,node_unknown,node_repeated,node_dedup toneAmber
class node_config,node_sqlite toneMint
class node_api,node_dashboard toneRose
class node_operator toneIndigo
```

## Components

### Packet ingestion

- [Live capture](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/capture.py): `nids/capture.py`
- [Packet parser](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/parser.py): `nids/parser.py`
- [Synthetic records](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/synthetic.py): `nids/synthetic.py`

### Detection pipeline

- [Shared models](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/models.py): `nids/models.py`
- [Detection engine](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/engine.py): `nids/engine.py`
- [Rule interface](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/base.py): `nids/detectors/base.py`
- [Port scan rule](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/port_scan.py): `nids/detectors/port_scan.py`
- [Rate anomaly rule](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/rate_anomaly.py): `nids/detectors/rate_anomaly.py`
- [ARP anomaly rule](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/arp_anomaly.py): `nids/detectors/arp_anomaly.py`
- [Unknown device rule](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/unknown_device.py): `nids/detectors/unknown_device.py`
- [Repeated connections rule](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/detectors/repeated_connections.py): `nids/detectors/repeated_connections.py`
- [Alert deduplicator](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/dedup.py): `nids/dedup.py`

### Configuration and storage

- [Config loader](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/config.py): `nids/config.py`
- [SQLite persistence](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/db.py): `nids/db.py`

### Read-only monitoring

- [JSON API](https://github.com/ruchitbhalerao/network-intrusion-detection/blob/main/nids/api.py): `nids/api.py`
- [Web dashboard](https://github.com/ruchitbhalerao/network-intrusion-detection/tree/main/nids/web): `nids/web`

### Other components

- **Operator**
- **Browser user**

## Connections

- Live capture → Packet parser: parses packets (evidence: `README.md`)
- Live capture → Detection engine: submits records (evidence: `nids/capture.py`)
- Packet parser → Shared models: creates records (evidence: `nids/parser.py`)
- Synthetic records → Shared models: creates records (evidence: `nids/synthetic.py`)
- Synthetic records → Detection engine: feeds records (evidence: `README.md`)
- Detection engine → Port scan rule: dispatches records (evidence: `nids/engine.py`)
- Detection engine → Rate anomaly rule: dispatches records (evidence: `nids/engine.py`)
- Detection engine → ARP anomaly rule: dispatches records (evidence: `nids/engine.py`)
- Detection engine → Unknown device rule: dispatches records (evidence: `nids/engine.py`)
- Detection engine → Repeated connections rule: dispatches records (evidence: `nids/engine.py`)
- Port scan rule → Rule interface: extends (evidence: `nids/detectors/port_scan.py`)
- Rate anomaly rule → Rule interface: extends (evidence: `nids/detectors/rate_anomaly.py`)
- ARP anomaly rule → Rule interface: extends (evidence: `nids/detectors/arp_anomaly.py`)
- Unknown device rule → Rule interface: extends (evidence: `nids/detectors/unknown_device.py`)
- Repeated connections rule → Rule interface: extends (evidence: `nids/detectors/repeated_connections.py`)
- Detection engine → Alert deduplicator: filters alerts (evidence: `nids/engine.py`)
- Detection engine → SQLite persistence: stores alerts (evidence: `nids/engine.py`)
- Config loader → Detection engine: configures rules (evidence: `README.md`)
- Operator → Live capture: starts optionally (evidence: `README.md`)
- Operator → Web dashboard: views monitoring (evidence: `README.md`)
- JSON API → SQLite persistence: reads data (evidence: `nids/api.py`)
- Web dashboard → JSON API: requests JSON (evidence: `README.md`)
- Browser user → Web dashboard: views page (evidence: `README.md`)
