# ntu168108/realtime-packet-sniff-v2 architecture

> Architecture diagram of the GitHub repository ntu168108/realtime-packet-sniff-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ntu168108/realtime-packet-sniff-v2
- Repository: https://github.com/ntu168108/realtime-packet-sniff-v2

## Overview

1. **Overall shape**
   - This repo is a Linux packet-sniffing and IDS platform built around one capture engine with multiple front ends and processing modes.
   - The core product is the `sniff` CLI; around it are a TUI/interactive UI, a background daemon, a live NDJSON stream mode, and an extended web GUI.

2. **Capture and packet-processing core**
   - The `core/` package is the runtime heart of the system.
   - It contains the packet acquisition and buffering path (`capture`, `buffer`, `rotator`, `pcap_writer`, `native_writer`), packet decoding and filtering (`decoder`, `display_filter`), and shared constants.
   - This layer is the boundary between raw network traffic and all higher-level consumers.

3. **CLI and daemon boundary**
   - `sniff.py` and the `cli/` package provide the user-facing entrypoints.
   - The CLI supports interactive and daemonized operation, with helper code for printing live output, menus, and shell-facing behavior.
   - The daemon path is the bridge from capture into long-running background processing and service installation.

4. **Terminal UI**
   - The `ui/` package provides the local interactive screen layer: list/detail views, menu handling, and color formatting.
   - It sits on top of the capture/decoder outputs and is concerned with presentation rather than packet processing.

5. **Plugin/module architecture**
   - `modules/` contains a generic runner and a base module abstraction, suggesting pluggable analysis stages.
   - The included `modules/dummy` is a minimal example, but the structure implies the system can dispatch captured data into additional analyzers without changing the core capture path.

6. **File rotation and pcap stream output**
   - The core writes packet data into rotating pcap segments, which are the handoff artifact for downstream pipelines.
   - This is important architecturally because it decouples capture from later IDS processing, allowing live capture to continue while consumers process segments asynchronously.

7. **IDS / feature-extraction pipeline**
   - `integration/` and `Extraction-and-classification/` together implement the higher-tier IDS workflow.
   - The flow is: pcap segments are consumed, features are extracted with Argus and Zeek, normalized/mapped/merged, then classified.
   - `Extraction-and-classification/MODULE_TRICHXUAT` is the extraction stage, while `MODULE_PHANLOAI` is the classification stage.

8. **Classification subsystem**
   - `MODULE_PHANLOAI` performs UNSW-NB15-style attack-family classification.
   - It includes baseline filtering, family filtering, a DoS-specific classifier, and JSON signature sets for attack families such as reconnaissance, exploits, fuzzers, shellcode, generic, and analysis.
   - This layer is rule/model-driven and is separate from packet capture or feature extraction.

9. **Streaming infrastructure for the IDS path**
   - The `integration/` package models the production data plane: pcap segmentation, Kafka segment transport, an `ec_consumer`, and ClickHouse sink logic.
   - This shows the architecture is event-driven: capture produces segments, Kafka distributes them, consumers transform/store results, and ClickHouse persists analytics data.
   - `sql/clickhouse_init.sql` provides the storage schema bootstrapping for that analytics backend.

10. **Web GUI subsystem**
   - `sniff-web/` is a separate frontend stack with its own Python server plus a React/TypeScript/Vite app.
   - It talks to backend services for capture control, Kafka, ClickHouse, and websocket/live updates, and is backed by its own integration and end-to-end tests.
   - This is a distinct presentation boundary from the TUI, aimed at browser-based operations and observability.

11. **Operational deployment**
   - `deploy/`, `scripts/`, and `sniff-web/deploy/` contain systemd units, Kafka/Grafana deployment assets, and install/uninstall helpers.
   - The repo is designed to run both as a local capture tool and as a multi-service stack with Kafka, ClickHouse, Grafana, Argus, and Zeek in the IDS deployment.

12. **Configuration, docs, and verification**
   - Configuration is split across examples like `config.yaml.example`, `.env.example`, and package-specific config modules.
   - `docs/` and the MkDocs setup document the architecture, installation, and operations, while `tests/` and the various integration suites validate capture, segmentation, storage, and web behavior across subsystem boundaries.

Main entry points: [`cli/app.py`](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/cli/app.py) (CLI app), [`core/capture.py`](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/capture.py) (Capture core), [`core/decoder.py`](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/decoder.py) (Decode/filter), [`integration/kafka_segmenter.py`](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/kafka_segmenter.py) (Kafka transport)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_capture["Capture runtime"]
  node_node_sniff_py["sniff CLI<br/>entrypoint<br/>[sniff.py]"]
  node_node_cli_app["CLI app<br/>shell interface<br/>[app.py]"]
  node_node_cli_daemon["Daemon mode<br/>service bridge<br/>[daemon.py]"]
  node_node_ui_menu["TUI layer<br/>terminal UI<br/>[menu.py]"]
  node_node_core_capture["Capture core<br/>packet runtime<br/>[capture.py]"]
  node_node_core_buffer["Buffering<br/>packet buffer<br/>[buffer.py]"]
  node_node_core_decode["Decode/filter<br/>processing<br/>[decoder.py]"]
  node_node_core_rotate["Rotation<br/>segmenter<br/>[rotator.py]"]
  node_node_core_pcap["PCAP writer<br/>output<br/>[pcap_writer.py]"]
  node_node_core_native["Native writer<br/>output<br/>[native_writer.py]"]
  node_node_core_filter["Display rules<br/>filtering<br/>[display_filter.py]"]
end

subgraph group_group_pipeline["IDS pipeline"]
  node_node_seg["Pcap segmenter<br/>stream stage<br/>[pcap_segment.py]"]
  node_node_kafka["Kafka transport<br/>message stage<br/>[kafka_segmenter.py]"]
  node_node_consumer["EC consumer<br/>[ec_consumer.py]"]
  node_node_sink["ClickHouse sink<br/>analytics sink<br/>[clickhouse_sink.py]"]
  node_node_extract["Feature extract<br/>feature pipeline<br/>[extractor.py]"]
  node_node_classify["Attack classify<br/>IDS classifier<br/>[baseline_filter.py]"]
end

subgraph group_group_web["Web GUI"]
  node_node_web_server["Web server<br/>frontend backend<br/>[web_server.py]"]
  node_node_web_app["React app<br/>browser UI<br/>[App.tsx]"]
end

subgraph group_group_ops["Operations"]
  node_node_sql["Schema init<br/>database schema"]
  node_node_deploy["Deploy assets<br/>ops"]
end

subgraph group_group_plugins["Plugins"]
  node_node_mod_runner["Module runner<br/>plugin host<br/>[runner.py]"]
  node_node_mod_base["Module API<br/>plugin interface<br/>[base.py]"]
  node_node_mod_dummy["Dummy module<br/>example plugin<br/>[analyze.py]"]
end

node_node_sniff_py -->|"launches"| node_node_cli_app
node_node_cli_app -->|"starts capture"| node_node_core_capture
node_node_cli_app -->|"daemon mode"| node_node_cli_daemon
node_node_cli_app -->|"interactive UI"| node_node_ui_menu
node_node_core_capture -->|"buffers"| node_node_core_buffer
node_node_core_buffer -->|"decodes"| node_node_core_decode
node_node_core_decode -->|"applies rules"| node_node_core_filter
node_node_core_capture -->|"rotates"| node_node_core_rotate
node_node_core_rotate -->|"writes pcap"| node_node_core_pcap
node_node_core_capture -->|"writes native"| node_node_core_native
node_node_core_decode -->|"feeds views"| node_node_ui_menu
node_node_core_decode -->|"dispatches"| node_node_mod_runner
node_node_mod_runner -->|"implements"| node_node_mod_base
node_node_mod_runner -->|"example module"| node_node_mod_dummy
node_node_core_pcap -->|"handoff"| node_node_seg
node_node_seg -->|"publishes"| node_node_kafka
node_node_kafka -->|"consumed by"| node_node_consumer
node_node_consumer -->|"stores"| node_node_sink
node_node_sink -->|"bootstraps"| node_node_sql
node_node_seg -->|"feeds features"| node_node_extract
node_node_extract -->|"classifies"| node_node_classify
node_node_core_pcap -->|"offline input"| node_node_extract
node_node_web_server -->|"serves"| node_node_web_app
node_node_web_app -->|"live ops"| node_node_kafka
node_node_web_app -->|"analytics UI"| node_node_sink
node_node_deploy -->|"installs"| node_node_cli_daemon
node_node_deploy -->|"deploys"| node_node_web_server
node_node_deploy -->|"provisions"| node_node_kafka

click node_node_sniff_py "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/sniff.py"
click node_node_cli_app "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/cli/app.py"
click node_node_cli_daemon "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/cli/daemon.py"
click node_node_ui_menu "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/ui/menu.py"
click node_node_core_capture "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/capture.py"
click node_node_core_buffer "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/buffer.py"
click node_node_core_decode "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/decoder.py"
click node_node_core_rotate "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/rotator.py"
click node_node_core_pcap "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/pcap_writer.py"
click node_node_core_native "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/native_writer.py"
click node_node_core_filter "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/display_filter.py"
click node_node_mod_runner "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/modules/runner.py"
click node_node_mod_base "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/modules/base.py"
click node_node_mod_dummy "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/modules/dummy/analyze.py"
click node_node_seg "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/pcap_segment.py"
click node_node_kafka "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/kafka_segmenter.py"
click node_node_consumer "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/ec_consumer.py"
click node_node_sink "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/clickhouse_sink.py"
click node_node_sql "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/sql/clickhouse_init.sql"
click node_node_extract "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/Extraction-and-classification/MODULE_TRICHXUAT/extractor.py"
click node_node_classify "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/Extraction-and-classification/MODULE_PHANLOAI/baseline_filter.py"
click node_node_web_server "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/sniff-web/web_server.py"
click node_node_web_app "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/sniff-web/web/src/App.tsx"
click node_node_deploy "https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/deploy/systemd/sniff-producer.service"

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_node_sniff_py,node_node_cli_app,node_node_cli_daemon,node_node_ui_menu,node_node_core_capture,node_node_core_buffer,node_node_core_decode,node_node_core_rotate,node_node_core_pcap,node_node_core_native,node_node_core_filter toneBlue
class node_node_seg,node_node_kafka,node_node_consumer,node_node_sink,node_node_extract,node_node_classify toneAmber
class node_node_web_server,node_node_web_app toneMint
class node_node_sql,node_node_deploy toneRose
class node_node_mod_runner,node_node_mod_base,node_node_mod_dummy toneIndigo
```

## Components

### Capture runtime

Core packet acquisition, decoding, and local presentation

- [sniff CLI](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/sniff.py): entrypoint · Primary command-line entrypoint for the tool · `sniff.py`
- [CLI app](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/cli/app.py): shell interface · User-facing CLI orchestration and modes · `cli/app.py`
- [Daemon mode](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/cli/daemon.py): service bridge · Background service and install-time execution path · `cli/daemon.py`
- [TUI layer](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/ui/menu.py): terminal UI · Interactive menu, list, detail, and color presentation · `ui/menu.py`
- [Capture core](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/capture.py): packet runtime · Acquires packets and drives the capture lifecycle · `core/capture.py`
- [Buffering](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/buffer.py): packet buffer · Holds captured packets before downstream handling · `core/buffer.py`
- [Decode/filter](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/decoder.py): processing · Packet decoding and display filtering · `core/decoder.py`
- [Rotation](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/rotator.py): segmenter · Rotates capture output into manageable segments · `core/rotator.py`
- [PCAP writer](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/pcap_writer.py): output · Writes packet capture segments for downstream consumers · `core/pcap_writer.py`
- [Native writer](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/native_writer.py): output · Alternative low-level packet output path · `core/native_writer.py`
- [Display rules](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/core/display_filter.py): filtering · Shared filtering constants and predicates · `core/display_filter.py`

### IDS pipeline

Segment transport, feature extraction, classification, and analytics storage

- [Pcap segmenter](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/pcap_segment.py): stream stage · Breaks rotated PCAP into transportable segments · `integration/pcap_segment.py`
- [Kafka transport](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/kafka_segmenter.py): message stage · Publishes and routes capture segments through Kafka · `integration/kafka_segmenter.py`
- [EC consumer](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/ec_consumer.py): consumer · Consumes segments and performs downstream processing · `integration/ec_consumer.py`
- [ClickHouse sink](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/integration/clickhouse_sink.py): analytics sink · Stores processed analytics into ClickHouse · `integration/clickhouse_sink.py`
- [Feature extract](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/Extraction-and-classification/MODULE_TRICHXUAT/extractor.py): feature pipeline · Argus/Zeek extraction and feature merging · `Extraction-and-classification/MODULE_TRICHXUAT/extractor.py`
- [Attack classify](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/Extraction-and-classification/MODULE_PHANLOAI/baseline_filter.py): IDS classifier · Rule and model driven UNSW-NB15 family classification · `Extraction-and-classification/MODULE_PHANLOAI/baseline_filter.py`

### Web GUI

Browser frontend and its server boundary

- [Web server](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/sniff-web/web_server.py): frontend backend · Python server boundary for the browser GUI · `sniff-web/web_server.py`
- [React app](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/sniff-web/web/src/App.tsx): browser UI · TypeScript/Vite frontend for monitoring and control · `sniff-web/web/src/App.tsx`

### Operations

Deployment, service units, and database bootstrap

- [Schema init](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/sql/clickhouse_init.sql): database schema · Bootstraps ClickHouse storage schema · `sql/clickhouse_init.sql`
- [Deploy assets](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/deploy/systemd/sniff-producer.service): ops · Systemd, Kafka, Grafana, and install scripts · `deploy/systemd/sniff-producer.service`

### Plugins

Pluggable analysis module framework

- [Module runner](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/modules/runner.py): plugin host · Dispatches captured data into pluggable analyzers · `modules/runner.py`
- [Module API](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/modules/base.py): plugin interface · Base abstraction for analysis modules · `modules/base.py`
- [Dummy module](https://github.com/ntu168108/realtime-packet-sniff-v2/blob/main/modules/dummy/analyze.py): example plugin · Minimal example analysis module · `modules/dummy/analyze.py`

## Connections

- sniff CLI → CLI app: launches · CLI entrypoint starts application flow
- CLI app → Capture core: starts capture · CLI drives the runtime capture engine
- CLI app → Daemon mode: daemon mode · CLI can hand off to background service behavior
- CLI app → TUI layer: interactive UI · CLI routes interactive sessions into the TUI
- Capture core → Buffering: buffers · Captured packets are staged in memory
- Buffering → Decode/filter: decodes · Buffered traffic is decoded and filtered
- Decode/filter → Display rules: applies rules · Display and packet filtering constrain what is surfaced
- Capture core → Rotation: rotates · Capture output is segmented for downstream use
- Rotation → PCAP writer: writes pcap · Rotated segments are persisted as PCAP artifacts
- Capture core → Native writer: writes native · Alternative low-level writer path
- Decode/filter → TUI layer: feeds views · Decoded packets power the interactive terminal display
- Decode/filter → Module runner: dispatches · Decoded data can be sent to analysis modules
- Module runner → Module API: implements · Runner depends on the shared module contract
- Module runner → Dummy module: example module · Repository includes a minimal plugin implementation
- PCAP writer → Pcap segmenter: handoff · PCAP files become segment inputs for the IDS pipeline
- Pcap segmenter → Kafka transport: publishes · Segmented captures are distributed over Kafka
- Kafka transport → EC consumer: consumed by · Consumers read segmented traffic from the message layer
- EC consumer → ClickHouse sink: stores · Processed events are written into ClickHouse
- ClickHouse sink → Schema init: bootstraps · Sink relies on the schema initialization script
- Pcap segmenter → Feature extract: feeds features · Segment artifacts drive feature extraction
- Feature extract → Attack classify: classifies · Extracted features are passed to attack-family classification
- PCAP writer → Feature extract: offline input · PCAP output can be consumed by the extraction pipeline
- Web server → React app: serves · Python backend serves the browser frontend
- React app → Kafka transport: live ops · Web UI surfaces Kafka-backed pipeline state
- React app → ClickHouse sink: analytics UI · Frontend reads analytics results from ClickHouse-backed services
- Deploy assets → Daemon mode: installs · Operational assets wire the daemonized runtime into the host
- Deploy assets → Web server: deploys · Deployment assets support the web frontend stack
- Deploy assets → Kafka transport: provisions · Deployment includes Kafka and related service config
