# proffaro/kshark architecture

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

- Interactive diagram: https://gitdiagram.com/proffaro/kshark
- Repository: https://github.com/proffaro/kshark

## Overview

KShark is a hybrid eBPF security platform: a Go agent collects kernel telemetry, a Python engine evaluates behavioral rules and ML detections, and results are persisted and exposed through an API and desktop GUI. The graph follows that workflow and includes the GUI’s event-analysis layer. Several agent, probe, and GUI implementation files were not sampled; their connections are shown only where the README or source index supports them.

Main entry points: [`ml_engine/inference/realtime_engine.py`](https://github.com/proffaro/kshark/blob/main/ml_engine/inference/realtime_engine.py) (Realtime ingestion), [`main.py`](https://github.com/proffaro/kshark/blob/main/main.py) (System orchestrator), [`agent/cmd/agent/main.go`](https://github.com/proffaro/kshark/blob/main/agent/cmd/agent/main.go) (Go eBPF agent), [`kshark/main_window.py`](https://github.com/proffaro/kshark/blob/main/kshark/main_window.py) (KShark desktop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Kernel collection"]
  node_agent["Go eBPF agent<br/>[main.go]"]
  node_probes["eBPF probes"]
  node_agentws["Agent WebSocket<br/>[websocket.go]"]
end

subgraph group_analysis["Detection and storage"]
  node_ingestion["Realtime ingestion<br/>[realtime_engine.py]"]
  node_features["Feature extraction"]
  node_lineage["Process lineage<br/>[process_graph.py]"]
  node_behavior["Behavioral rules"]
  node_falco["Falco rules<br/>[falco_engine.py]"]
  node_detector["ML detector<br/>[detector.py]"]
  node_alerts["Alert dispatch"]
  node_storage[("DuckDB and SQLite<br/>[db_manager.py]")]
  node_storage_models["Storage models<br/>[models.py]"]
end

subgraph group_interfaces["API and operations"]
  node_orchestrator["System orchestrator<br/>[main.py]"]
  node_api["REST API<br/>[server.py]"]
  node_routes["API routes<br/>[routes.py]"]
end

subgraph group_desktop["Desktop analysis"]
  node_gui["KShark desktop<br/>[main_window.py]"]
  node_event_model["Event table model"]
  node_filter["Display filters<br/>[filter_engine.py]"]
  node_coloring["Event coloring<br/>[coloring_engine.py]"]
  node_syscalls["Syscall lookup<br/>[syscall_table.py]"]
  node_theme["Theme settings<br/>[theme.py]"]
end

node_operator(("Security operator"))
node_kernel(("Linux kernel"))

node_operator -->|"starts system"| node_orchestrator
node_orchestrator -->|"starts agent"| node_agent
node_agent -.->|"loads probes"| node_probes
node_kernel -.->|"emits telemetry"| node_probes
node_agent -.->|"streams events"| node_agentws
node_agentws -->|"sends telemetry"| node_ingestion
node_orchestrator -->|"starts engine"| node_ingestion
node_ingestion -->|"extracts features"| node_features
node_ingestion -->|"updates lineage"| node_lineage
node_ingestion -->|"evaluates events"| node_behavior
node_behavior -->|"evaluates rules"| node_falco
node_ingestion -->|"scores features"| node_detector
node_ingestion -->|"dispatches alerts"| node_alerts
node_ingestion -->|"persists events"| node_storage
node_storage -->|"uses models"| node_storage_models
node_orchestrator -->|"starts API"| node_api
node_api -->|"mounts routes"| node_routes
node_routes -->|"queries storage"| node_storage
node_operator -->|"opens desktop"| node_gui
node_gui -->|"presents events"| node_event_model
node_event_model -->|"colors rows"| node_coloring
node_coloring -->|"matches rules"| node_filter
node_filter -->|"resolves names"| node_syscalls
node_coloring -->|"reads theme"| node_theme
node_gui -->|"sets appearance"| node_theme

click node_agent "https://github.com/proffaro/kshark/blob/main/agent/cmd/agent/main.go"
click node_probes "https://github.com/proffaro/kshark/tree/main/bpf/probes"
click node_agentws "https://github.com/proffaro/kshark/blob/main/agent/server/websocket.go"
click node_orchestrator "https://github.com/proffaro/kshark/blob/main/main.py"
click node_ingestion "https://github.com/proffaro/kshark/blob/main/ml_engine/inference/realtime_engine.py"
click node_features "https://github.com/proffaro/kshark/blob/main/ml_engine/preprocessing/feature_extractor.py"
click node_lineage "https://github.com/proffaro/kshark/blob/main/ml_engine/preprocessing/process_graph.py"
click node_behavior "https://github.com/proffaro/kshark/blob/main/ml_engine/rules/behavioral_engine.py"
click node_falco "https://github.com/proffaro/kshark/blob/main/ml_engine/rules/falco_engine.py"
click node_detector "https://github.com/proffaro/kshark/blob/main/ml_engine/models/detector.py"
click node_alerts "https://github.com/proffaro/kshark/blob/main/ml_engine/detection/alert_dispatcher.py"
click node_storage "https://github.com/proffaro/kshark/blob/main/ml_engine/storage/db_manager.py"
click node_storage_models "https://github.com/proffaro/kshark/blob/main/ml_engine/storage/models.py"
click node_api "https://github.com/proffaro/kshark/blob/main/ml_engine/api/server.py"
click node_routes "https://github.com/proffaro/kshark/blob/main/ml_engine/api/routes.py"
click node_gui "https://github.com/proffaro/kshark/blob/main/kshark/main_window.py"
click node_event_model "https://github.com/proffaro/kshark/blob/main/kshark/models/event_table_model.py"
click node_filter "https://github.com/proffaro/kshark/blob/main/kshark/core/filter_engine.py"
click node_coloring "https://github.com/proffaro/kshark/blob/main/kshark/core/coloring_engine.py"
click node_syscalls "https://github.com/proffaro/kshark/blob/main/kshark/core/syscall_table.py"
click node_theme "https://github.com/proffaro/kshark/blob/main/kshark/core/theme.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_agent,node_probes,node_agentws toneBlue
class node_ingestion,node_features,node_lineage,node_behavior,node_falco,node_detector,node_alerts,node_storage,node_storage_models toneAmber
class node_orchestrator,node_api,node_routes toneMint
class node_gui,node_event_model,node_filter,node_coloring,node_syscalls,node_theme toneRose
class node_operator,node_kernel toneIndigo
```

## Components

### Kernel collection

- [Go eBPF agent](https://github.com/proffaro/kshark/blob/main/agent/cmd/agent/main.go): `agent/cmd/agent/main.go`
- [eBPF probes](https://github.com/proffaro/kshark/tree/main/bpf/probes): `bpf/probes`
- [Agent WebSocket](https://github.com/proffaro/kshark/blob/main/agent/server/websocket.go): `agent/server/websocket.go`

### Detection and storage

- [Realtime ingestion](https://github.com/proffaro/kshark/blob/main/ml_engine/inference/realtime_engine.py): `ml_engine/inference/realtime_engine.py`
- [Feature extraction](https://github.com/proffaro/kshark/blob/main/ml_engine/preprocessing/feature_extractor.py): `ml_engine/preprocessing/feature_extractor.py`
- [Process lineage](https://github.com/proffaro/kshark/blob/main/ml_engine/preprocessing/process_graph.py): `ml_engine/preprocessing/process_graph.py`
- [Behavioral rules](https://github.com/proffaro/kshark/blob/main/ml_engine/rules/behavioral_engine.py): `ml_engine/rules/behavioral_engine.py`
- [Falco rules](https://github.com/proffaro/kshark/blob/main/ml_engine/rules/falco_engine.py): `ml_engine/rules/falco_engine.py`
- [ML detector](https://github.com/proffaro/kshark/blob/main/ml_engine/models/detector.py): `ml_engine/models/detector.py`
- [Alert dispatch](https://github.com/proffaro/kshark/blob/main/ml_engine/detection/alert_dispatcher.py): `ml_engine/detection/alert_dispatcher.py`
- [DuckDB and SQLite](https://github.com/proffaro/kshark/blob/main/ml_engine/storage/db_manager.py): `ml_engine/storage/db_manager.py`
- [Storage models](https://github.com/proffaro/kshark/blob/main/ml_engine/storage/models.py): `ml_engine/storage/models.py`

### API and operations

- [System orchestrator](https://github.com/proffaro/kshark/blob/main/main.py): `main.py`
- [REST API](https://github.com/proffaro/kshark/blob/main/ml_engine/api/server.py): `ml_engine/api/server.py`
- [API routes](https://github.com/proffaro/kshark/blob/main/ml_engine/api/routes.py): `ml_engine/api/routes.py`

### Desktop analysis

- [KShark desktop](https://github.com/proffaro/kshark/blob/main/kshark/main_window.py): `kshark/main_window.py`
- [Event table model](https://github.com/proffaro/kshark/blob/main/kshark/models/event_table_model.py): `kshark/models/event_table_model.py`
- [Display filters](https://github.com/proffaro/kshark/blob/main/kshark/core/filter_engine.py): `kshark/core/filter_engine.py`
- [Event coloring](https://github.com/proffaro/kshark/blob/main/kshark/core/coloring_engine.py): `kshark/core/coloring_engine.py`
- [Syscall lookup](https://github.com/proffaro/kshark/blob/main/kshark/core/syscall_table.py): `kshark/core/syscall_table.py`
- [Theme settings](https://github.com/proffaro/kshark/blob/main/kshark/core/theme.py): `kshark/core/theme.py`

### Other components

- **Security operator**
- **Linux kernel**

## Connections

- Security operator → System orchestrator: starts system (evidence: `main.py`)
- System orchestrator → Go eBPF agent: starts agent (evidence: `main.py`)
- Go eBPF agent → eBPF probes: loads probes
- Linux kernel → eBPF probes: emits telemetry
- Go eBPF agent → Agent WebSocket: streams events
- Agent WebSocket → Realtime ingestion: sends telemetry
- System orchestrator → Realtime ingestion: starts engine (evidence: `main.py`)
- Realtime ingestion → Feature extraction: extracts features (evidence: `ml_engine/inference/realtime_engine.py`)
- Realtime ingestion → Process lineage: updates lineage (evidence: `ml_engine/inference/realtime_engine.py`)
- Realtime ingestion → Behavioral rules: evaluates events (evidence: `ml_engine/inference/realtime_engine.py`)
- Behavioral rules → Falco rules: evaluates rules (evidence: `ml_engine/rules/behavioral_engine.py`)
- Realtime ingestion → ML detector: scores features (evidence: `ml_engine/inference/realtime_engine.py`)
- Realtime ingestion → Alert dispatch: dispatches alerts (evidence: `ml_engine/inference/realtime_engine.py`)
- Realtime ingestion → DuckDB and SQLite: persists events (evidence: `ml_engine/inference/realtime_engine.py`)
- DuckDB and SQLite → Storage models: uses models (evidence: `ml_engine/storage/db_manager.py`)
- System orchestrator → REST API: starts API (evidence: `main.py`)
- REST API → API routes: mounts routes (evidence: `ml_engine/api/server.py`)
- API routes → DuckDB and SQLite: queries storage (evidence: `ml_engine/api/routes.py`)
- Security operator → KShark desktop: opens desktop
- KShark desktop → Event table model: presents events (evidence: `kshark/main_window.py`)
- Event table model → Event coloring: colors rows (evidence: `kshark/models/event_table_model.py`)
- Event coloring → Display filters: matches rules (evidence: `kshark/core/coloring_engine.py`)
- Display filters → Syscall lookup: resolves names (evidence: `kshark/core/filter_engine.py`)
- Event coloring → Theme settings: reads theme (evidence: `kshark/core/coloring_engine.py`)
- KShark desktop → Theme settings: sets appearance (evidence: `kshark/main_window.py`)
