# ericsk-max/lightweight-flow-based-ids-ips architecture

> Architecture diagram of the GitHub repository ericsk-max/lightweight-flow-based-ids-ips, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ericsk-max/lightweight-flow-based-ids-ips
- Repository: https://github.com/ericsk-max/lightweight-flow-based-ids-ips

## Overview

This repository is a lightweight flow-based intrusion detection and prevention system. Its main workflow captures TCP packet metadata, classifies scan-like flags, checks port spread and connection rate, then records alerts and applies firewall prevention; a Flask dashboard reads persisted results and supports manual unblock. Calibration learns per-source rate baselines. The graph follows the sampled entry points and explicit module references; some engine internals are omitted from excerpts, so uncertain wiring is not asserted.

Main entry points: [`ids_ips/ids/engine.py`](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/engine.py) (Detection engine), [`ids_ips/dashboard/app.py`](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/dashboard/app.py) (Dashboard API), [`ids_ips/ids/main.py`](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/main.py) (CLI entry), [`ids_ips/ids/prevention.py`](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/prevention.py) (Firewall response)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Detection runtime"]
  node_main["CLI entry<br/>[main.py]"]
  node_engine["Detection engine<br/>[engine.py]"]
  node_capture["Packet capture<br/>[capture.py]"]
  node_detector["Flow detection<br/>[detector.py]"]
end

subgraph group_state["Baselines and persistence"]
  node_baseline["Rate baseline<br/>[baseline.py]"]
  node_database[("SQLite persistence<br/>[database.py]")]
end

subgraph group_response["Prevention response"]
  node_prevention["Firewall response<br/>[prevention.py]"]
end

subgraph group_monitor["Monitoring dashboard"]
  node_dashboard["Dashboard API<br/>[app.py]"]
  node_dashboard_page["Dashboard page<br/>[dashboard.html]"]
end

node_operator(("Operator"))
node_network(("TCP traffic"))
node_iptables["iptables"]
node_config["Runtime configuration<br/>[config.yaml]"]
node_user(("Dashboard user"))

node_operator -->|"starts"| node_main
node_main -->|"creates and runs"| node_engine
node_main -->|"loads"| node_config
node_operator -.->|"opens"| node_dashboard
node_dashboard -->|"loads"| node_config
node_network -.->|"supplies packets"| node_capture
node_engine -->|"starts capture"| node_capture
node_engine -->|"classifies and tracks"| node_detector
node_engine -->|"loads and calibrates"| node_baseline
node_detector -->|"checks threshold"| node_baseline
node_engine -->|"records detections"| node_database
node_engine -->|"blocks source"| node_prevention
node_prevention -->|"updates rules"| node_iptables
node_engine -->|"stores metrics"| node_database
node_dashboard -->|"reads and updates"| node_database
node_dashboard -->|"unblocks source"| node_prevention
node_dashboard -->|"renders"| node_dashboard_page
node_user -.->|"views and manages"| node_dashboard

click node_main "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/main.py"
click node_engine "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/engine.py"
click node_capture "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/capture.py"
click node_detector "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/detector.py"
click node_baseline "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/baseline.py"
click node_database "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/database.py"
click node_prevention "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/prevention.py"
click node_dashboard "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/dashboard/app.py"
click node_dashboard_page "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/dashboard/templates/dashboard.html"
click node_config "https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/config/config.yaml"

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_main,node_engine,node_capture,node_detector,node_user toneBlue
class node_baseline,node_database toneAmber
class node_prevention toneMint
class node_dashboard,node_dashboard_page toneRose
class node_operator,node_network,node_iptables toneIndigo
class node_config toneTeal
```

## Components

### Detection runtime

- [CLI entry](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/main.py): `ids_ips/ids/main.py`
- [Detection engine](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/engine.py): `ids_ips/ids/engine.py`
- [Packet capture](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/capture.py): `ids_ips/ids/capture.py`
- [Flow detection](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/detector.py): `ids_ips/ids/detector.py`

### Baselines and persistence

- [Rate baseline](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/baseline.py): `ids_ips/ids/baseline.py`
- [SQLite persistence](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/database.py): `ids_ips/ids/database.py`

### Prevention response

- [Firewall response](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/ids/prevention.py): `ids_ips/ids/prevention.py`

### Monitoring dashboard

- [Dashboard API](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/dashboard/app.py): `ids_ips/dashboard/app.py`
- [Dashboard page](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/dashboard/templates/dashboard.html): `ids_ips/dashboard/templates/dashboard.html`

### Other components

- **Operator**
- **TCP traffic**
- **iptables**
- [Runtime configuration](https://github.com/ericsk-max/lightweight-flow-based-ids-ips/blob/main/ids_ips/config/config.yaml): `ids_ips/config/config.yaml`
- **Dashboard user**

## Connections

- Operator → CLI entry: starts (evidence: `ids_ips/ids/main.py`)
- CLI entry → Detection engine: creates and runs (evidence: `ids_ips/ids/main.py`)
- CLI entry → Runtime configuration: loads (evidence: `ids_ips/ids/main.py`)
- Operator → Dashboard API: opens
- Dashboard API → Runtime configuration: loads (evidence: `ids_ips/dashboard/app.py`)
- TCP traffic → Packet capture: supplies packets
- Detection engine → Packet capture: starts capture (evidence: `ids_ips/ids/engine.py`)
- Detection engine → Flow detection: classifies and tracks (evidence: `ids_ips/ids/engine.py`)
- Detection engine → Rate baseline: loads and calibrates (evidence: `ids_ips/ids/engine.py`)
- Flow detection → Rate baseline: checks threshold (evidence: `ids_ips/ids/detector.py`)
- Detection engine → SQLite persistence: records detections (evidence: `ids_ips/ids/engine.py`)
- Detection engine → Firewall response: blocks source (evidence: `ids_ips/ids/engine.py`)
- Firewall response → iptables: updates rules (evidence: `ids_ips/ids/prevention.py`)
- Detection engine → SQLite persistence: stores metrics (evidence: `ids_ips/ids/engine.py`)
- Dashboard API → SQLite persistence: reads and updates (evidence: `ids_ips/dashboard/app.py`)
- Dashboard API → Firewall response: unblocks source (evidence: `ids_ips/dashboard/app.py`)
- Dashboard API → Dashboard page: renders (evidence: `ids_ips/dashboard/app.py`)
- Dashboard user → Dashboard API: views and manages
