# ruchitbhalerao/network-intrusion-detection-and-live-monitoring architecture

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

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

## Overview

This is a localhost network intrusion-monitoring application. Its main workflow is optional synthetic or real packet input, normalization into packet records, five independent detection rules plus deduplication, and SQLite persistence; a read-only JSON API and two dashboard views expose alerts, devices, statistics, and traffic summaries. Configuration and traffic metering are supporting runtime layers. The README documents the overall flow; source excerpts establish the engine, API, and application-startup relationships, while some capture and web wiring is documented rather than excerpted.

Main entry points: [`nids/engine.py`](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/engine.py) (Detection engine), [`run.py`](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/run.py) (Application startup), [`nids/api.py`](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/api.py) (Read-only JSON API), [`nids/detectors/base.py`](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/base.py) (Detector interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Traffic inputs"]
  node_run["Application startup<br/>[run.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_capture["Packet capture<br/>[capture.py]"]
  node_livefeed["Synthetic live feed<br/>[livefeed.py]"]
  node_synthetic["Synthetic records<br/>[synthetic.py]"]
end

subgraph group_detection["Detection pipeline"]
  node_parser["Packet parser<br/>[parser.py]"]
  node_models["Packet and event models<br/>[models.py]"]
  node_engine["Detection engine<br/>[engine.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-connection rule"]
  node_detectorbase["Detector interface<br/>[base.py]"]
  node_dedup["Alert deduplication<br/>[dedup.py]"]
end

subgraph group_storage["State and metrics"]
  node_database[("SQLite store<br/>[db.py]")]
  node_meter["Traffic meter<br/>[metrics.py]"]
end

subgraph group_presentation["API and dashboard"]
  node_api["Read-only JSON API<br/>[api.py]"]
  node_web["Web route registration<br/>[__init__.py]"]
  node_dashboard["Alerts dashboard<br/>[app.js]"]
  node_liveview["Live traffic view<br/>[live.js]"]
end

node_operator(("Operator"))
node_browser(("Dashboard user"))

node_operator -->|"starts"| node_run
node_run -->|"loads"| node_config
node_run -->|"builds"| node_api
node_run -->|"starts optionally"| node_livefeed
node_run -->|"starts optionally"| node_capture
node_livefeed -->|"generates records"| node_synthetic
node_livefeed -->|"processes records"| node_engine
node_livefeed -->|"stores devices"| node_database
node_capture -->|"parses packets"| node_parser
node_capture -->|"feeds records"| node_engine
node_parser -->|"creates records"| node_models
node_engine -->|"checks records"| node_portscan
node_engine -->|"checks records"| node_rate
node_engine -->|"checks records"| node_arp
node_engine -->|"checks records"| node_unknown
node_engine -->|"checks records"| node_repeated
node_portscan -->|"inherits"| node_detectorbase
node_rate -->|"inherits"| node_detectorbase
node_arp -->|"inherits"| node_detectorbase
node_unknown -->|"inherits"| node_detectorbase
node_repeated -->|"inherits"| node_detectorbase
node_engine -->|"suppresses duplicates"| node_dedup
node_engine -->|"stores alerts"| node_database
node_engine -->|"records traffic"| node_meter
node_meter -->|"writes traffic"| node_database
node_api -->|"reads stored data"| node_database
node_api -->|"registers routes"| node_web
node_browser -->|"views alerts"| node_dashboard
node_dashboard -->|"requests JSON"| node_api
node_browser -->|"views traffic"| node_liveview
node_liveview -->|"requests traffic"| node_api

click node_run "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/run.py"
click node_config "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/config.py"
click node_capture "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/capture.py"
click node_livefeed "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/livefeed.py"
click node_synthetic "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/synthetic.py"
click node_parser "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/parser.py"
click node_models "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/models.py"
click node_engine "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/engine.py"
click node_portscan "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/port_scan.py"
click node_rate "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/rate_anomaly.py"
click node_arp "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/arp_anomaly.py"
click node_unknown "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/unknown_device.py"
click node_repeated "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/repeated_connections.py"
click node_detectorbase "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/base.py"
click node_dedup "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/dedup.py"
click node_database "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/db.py"
click node_meter "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/metrics.py"
click node_api "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/api.py"
click node_web "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/web/__init__.py"
click node_dashboard "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/web/static/app.js"
click node_liveview "https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/web/static/live.js"

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_run,node_config,node_capture,node_livefeed,node_synthetic,node_browser toneBlue
class node_parser,node_models,node_engine,node_portscan,node_rate,node_arp,node_unknown,node_repeated,node_detectorbase,node_dedup toneAmber
class node_database,node_meter toneMint
class node_api,node_web,node_dashboard,node_liveview toneRose
class node_operator toneIndigo
```

## Components

### Traffic inputs

- [Application startup](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/run.py): `run.py`
- [Configuration](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/config.py): `nids/config.py`
- [Packet capture](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/capture.py): `nids/capture.py`
- [Synthetic live feed](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/livefeed.py): `nids/livefeed.py`
- [Synthetic records](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/synthetic.py): `nids/synthetic.py`

### Detection pipeline

- [Packet parser](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/parser.py): `nids/parser.py`
- [Packet and event models](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/models.py): `nids/models.py`
- [Detection engine](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/engine.py): `nids/engine.py`
- [Port-scan rule](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/port_scan.py): `nids/detectors/port_scan.py`
- [Rate-anomaly rule](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/rate_anomaly.py): `nids/detectors/rate_anomaly.py`
- [ARP-anomaly rule](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/arp_anomaly.py): `nids/detectors/arp_anomaly.py`
- [Unknown-device rule](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/unknown_device.py): `nids/detectors/unknown_device.py`
- [Repeated-connection rule](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/repeated_connections.py): `nids/detectors/repeated_connections.py`
- [Detector interface](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/detectors/base.py): `nids/detectors/base.py`
- [Alert deduplication](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/dedup.py): `nids/dedup.py`

### State and metrics

- [SQLite store](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/db.py): `nids/db.py`
- [Traffic meter](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/metrics.py): `nids/metrics.py`

### API and dashboard

- [Read-only JSON API](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/api.py): `nids/api.py`
- [Web route registration](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/web/__init__.py): `nids/web/__init__.py`
- [Alerts dashboard](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/web/static/app.js): `nids/web/static/app.js`
- [Live traffic view](https://github.com/ruchitbhalerao/network-intrusion-detection-and-live-monitoring/blob/main/nids/web/static/live.js): `nids/web/static/live.js`

### Other components

- **Operator**
- **Dashboard user**

## Connections

- Operator → Application startup: starts (evidence: `README.md`)
- Application startup → Configuration: loads (evidence: `run.py`)
- Application startup → Read-only JSON API: builds (evidence: `run.py`)
- Application startup → Synthetic live feed: starts optionally (evidence: `run.py`)
- Application startup → Packet capture: starts optionally (evidence: `run.py`)
- Synthetic live feed → Synthetic records: generates records (evidence: `nids/livefeed.py`)
- Synthetic live feed → Detection engine: processes records (evidence: `nids/livefeed.py`)
- Synthetic live feed → SQLite store: stores devices (evidence: `nids/livefeed.py`)
- Packet capture → Packet parser: parses packets (evidence: `README.md`)
- Packet capture → Detection engine: feeds records (evidence: `README.md`)
- Packet parser → Packet and event models: creates records (evidence: `nids/parser.py`)
- Detection engine → Port-scan rule: checks records (evidence: `nids/engine.py`)
- Detection engine → Rate-anomaly rule: checks records (evidence: `nids/engine.py`)
- Detection engine → ARP-anomaly rule: checks records (evidence: `nids/engine.py`)
- Detection engine → Unknown-device rule: checks records (evidence: `nids/engine.py`)
- Detection engine → Repeated-connection rule: checks records (evidence: `nids/engine.py`)
- Port-scan rule → Detector interface: inherits (evidence: `nids/detectors/port_scan.py`)
- Rate-anomaly rule → Detector interface: inherits (evidence: `nids/detectors/rate_anomaly.py`)
- ARP-anomaly rule → Detector interface: inherits (evidence: `nids/detectors/arp_anomaly.py`)
- Unknown-device rule → Detector interface: inherits (evidence: `nids/detectors/unknown_device.py`)
- Repeated-connection rule → Detector interface: inherits (evidence: `nids/detectors/repeated_connections.py`)
- Detection engine → Alert deduplication: suppresses duplicates (evidence: `nids/engine.py`)
- Detection engine → SQLite store: stores alerts (evidence: `nids/engine.py`)
- Detection engine → Traffic meter: records traffic (evidence: `nids/engine.py`)
- Traffic meter → SQLite store: writes traffic (evidence: `nids/metrics.py`)
- Read-only JSON API → SQLite store: reads stored data (evidence: `nids/api.py`)
- Read-only JSON API → Web route registration: registers routes (evidence: `nids/api.py`)
- Dashboard user → Alerts dashboard: views alerts (evidence: `README.md`)
- Alerts dashboard → Read-only JSON API: requests JSON (evidence: `README.md`)
- Dashboard user → Live traffic view: views traffic (evidence: `README.md`)
- Live traffic view → Read-only JSON API: requests traffic (evidence: `README.md`)
