# anbukumaran1/kernalgemma architecture

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

- Interactive diagram: https://gitdiagram.com/anbukumaran1/kernalgemma
- Repository: https://github.com/anbukumaran1/kernalgemma

## Overview

KernelGemma combines a synthetic eBPF training-data generator with an interactive eBPF control CLI. The main documented workflow creates natural-language intents and verifier-safe XDP/kprobe C, validates and persists accepted rows plus provenance, and can resume interrupted generation. Separately, the CLI turns operator intents into programs, verifies and attaches them, and presents live telemetry; Ollama is its fallback. The README also documents a Colab QLoRA fine-tuning workflow. Some internal call paths are not visible in the excerpts, so those links are omitted or marked unverified.

Main entry points: [`dataset_engine.py`](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py) (Generation Engine), [`cli.py`](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py) (Interactive CLI), [`kernelgemma_dataset.jsonl`](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/kernelgemma_dataset.jsonl) (JSONL Dataset), [`kernelgemma_dataset.jsonl.meta.jsonl`](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/kernelgemma_dataset.jsonl.meta.jsonl) (Provenance Manifest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["Dataset Generation"]
  node_dataset_engine["Generation Engine<br/>[dataset_engine.py]"]
  node_job_specs["Job Specs and Templates<br/>[dataset_engine.py]"]
  node_intent_code["Intent and C Generator<br/>[dataset_engine.py]"]
end

subgraph group_validation["Verification and State"]
  node_validator["eBPF Validator<br/>[dataset_engine.py]"]
  node_clang["Optional Clang Check<br/>[dataset_engine.py]"]
  node_dataset_file["JSONL Dataset"]
  node_manifest["Provenance Manifest"]
end

subgraph group_control["eBPF Control CLI"]
  node_cli["Interactive CLI<br/>[cli.py]"]
  node_intent_router["Intent Routing<br/>[cli.py]"]
  node_code_prep["Code Preparation<br/>[cli.py]"]
  node_telemetry["Packet Telemetry HUD<br/>[cli.py]"]
end

subgraph group_training["Model Fine-Tuning"]
  node_colab["Fine-Tuning Workflow"]
end

node_operator(("Operator"))
node_gemini["Gemini API"]
node_ollama["Ollama"]
node_bcc["BCC Runtime"]
node_kernel["Linux eBPF Hooks"]

node_operator -->|"configures generation"| node_dataset_engine
node_dataset_engine -.->|"creates job specs"| node_job_specs
node_job_specs -.->|"supplies templates"| node_intent_code
node_dataset_engine -.->|"generates samples"| node_intent_code
node_dataset_engine -->|"requests generation"| node_gemini
node_dataset_engine -->|"validates samples"| node_validator
node_dataset_engine -->|"optionally compiles"| node_clang
node_dataset_engine -->|"writes accepted rows"| node_dataset_file
node_dataset_engine -->|"records provenance"| node_manifest
node_operator -->|"enters security intent"| node_cli
node_cli -.->|"routes intent"| node_intent_router
node_intent_router -->|"requests fallback"| node_ollama
node_cli -->|"prepares program"| node_code_prep
node_code_prep -->|"compiles and verifies"| node_bcc
node_bcc -.->|"loads hooks"| node_kernel
node_kernel -.->|"emits trace events"| node_telemetry
node_dataset_file -->|"loads training data"| node_colab

click node_dataset_engine "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py"
click node_job_specs "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py"
click node_intent_code "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py"
click node_validator "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py"
click node_clang "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py"
click node_dataset_file "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/kernelgemma_dataset.jsonl"
click node_manifest "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/kernelgemma_dataset.jsonl.meta.jsonl"
click node_cli "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py"
click node_intent_router "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py"
click node_code_prep "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py"
click node_telemetry "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py"
click node_colab "https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/KernelGemma_Unsloth_Trainer.ipynb"

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_dataset_engine,node_job_specs,node_intent_code toneBlue
class node_validator,node_clang,node_dataset_file,node_manifest toneAmber
class node_cli,node_intent_router,node_code_prep,node_telemetry,node_gemini toneMint
class node_colab toneRose
class node_operator,node_ollama,node_bcc,node_kernel toneIndigo
```

## Components

### Dataset Generation

- [Generation Engine](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py): `dataset_engine.py`
- [Job Specs and Templates](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py): `dataset_engine.py`
- [Intent and C Generator](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py): `dataset_engine.py`

### Verification and State

- [eBPF Validator](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py): `dataset_engine.py`
- [Optional Clang Check](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/dataset_engine.py): `dataset_engine.py`
- [JSONL Dataset](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/kernelgemma_dataset.jsonl): `kernelgemma_dataset.jsonl`
- [Provenance Manifest](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/kernelgemma_dataset.jsonl.meta.jsonl): `kernelgemma_dataset.jsonl.meta.jsonl`

### eBPF Control CLI

- [Interactive CLI](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py): `cli.py`
- [Intent Routing](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py): `cli.py`
- [Code Preparation](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py): `cli.py`
- [Packet Telemetry HUD](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/cli.py): `cli.py`

### Model Fine-Tuning

- [Fine-Tuning Workflow](https://github.com/anbukumaran1/kernalgemma/blob/AnbuTesting1/KernelGemma_Unsloth_Trainer.ipynb): `KernelGemma_Unsloth_Trainer.ipynb`

### Other components

- **Operator**
- **Gemini API**
- **Ollama**
- **BCC Runtime**
- **Linux eBPF Hooks**

## Connections

- Operator → Generation Engine: configures generation (evidence: `README.md`)
- Generation Engine → Job Specs and Templates: creates job specs (evidence: `dataset_engine.py`)
- Job Specs and Templates → Intent and C Generator: supplies templates (evidence: `dataset_engine.py`)
- Generation Engine → Intent and C Generator: generates samples (evidence: `dataset_engine.py`)
- Generation Engine → Gemini API: requests generation (evidence: `README.md`)
- Generation Engine → eBPF Validator: validates samples (evidence: `README.md`)
- Generation Engine → Optional Clang Check: optionally compiles (evidence: `README.md`)
- Generation Engine → JSONL Dataset: writes accepted rows (evidence: `README.md`)
- Generation Engine → Provenance Manifest: records provenance (evidence: `README.md`)
- Operator → Interactive CLI: enters security intent (evidence: `cli.py`)
- Interactive CLI → Intent Routing: routes intent (evidence: `cli.py`)
- Intent Routing → Ollama: requests fallback (evidence: `cli.py`)
- Interactive CLI → Code Preparation: prepares program (evidence: `cli.py`)
- Code Preparation → BCC Runtime: compiles and verifies (evidence: `cli.py`)
- BCC Runtime → Linux eBPF Hooks: loads hooks
- Linux eBPF Hooks → Packet Telemetry HUD: emits trace events
- JSONL Dataset → Fine-Tuning Workflow: loads training data (evidence: `README.md`)
