# mahavishnu-k/ore-kernel architecture

> Architecture diagram of the GitHub repository mahavishnu-k/ore-kernel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mahavishnu-k/ore-kernel
- Repository: https://github.com/mahavishnu-k/ore-kernel

## Overview

#### Purpose and Entry Points
ORE is a Rust workspace implementing a local LLM kernel: it mediates application access to inference, agent memory, collaboration, and tool execution. The persistent HTTP daemon starts at `ore-server/src/main.rs`; its Axum routes are implemented under `ore-server/src/handlers/`. The user-facing client and interactive workflows start at `ore-cli/src/main.rs`. Workspace composition is defined by `Cargo.toml`.

#### Server Bootstrap and Shared Kernel State
At startup, the server resolves configuration/base directories, loads manifests, selects an inference driver, creates shared kernel state, generates a session token, installs authentication middleware, and starts background cleanup. Shared state and configuration live in `ore-server/src/state.rs`; request authorization is in `ore-server/src/middleware.rs`; route payload contracts are in `ore-server/src/payloads.rs`. The daemon binds locally and is the principal boundary between clients and kernel subsystems.

#### Manifest-Centered Policy Boundary
Every agent/application is identified by a TOML manifest loaded into the in-memory registry. The registry supplies O(1) application policy lookup to inference, IPC, and execution paths, covering model access, quotas, paging, filesystem/network permissions, execution permissions, and IPC targets/pipes. Core implementation: `ore-core/src/registry.rs`; installed policy inputs: `manifests/openclaw.toml`, `manifests/terminal_user.toml`; system defaults: `ore.toml`.

#### Secured Inference Pipeline
Inference handlers accept authenticated requests, resolve the caller manifest, apply quota/security controls, restore state when enabled, acquire scheduling capacity, invoke the configured driver, and stream or return output. The prompt firewall detects injection patterns and redacts PII before model access in `ore-core/src/firewall.rs`. Per-agent token budgets and IPC facilities share `ore-core/src/ipc.rs`. Inference request orchestration is in `ore-server/src/handlers/inference.rs`.

#### Scheduling and Persistent Agent State
The GPU scheduler uses Tokio semaphore-based RAII leases to serialize/arbitrate active inference and optimize reuse: same model/agent, agent context swap, or model replacement. It is implemented in `ore-core/src/scheduler.rs`. Memory management pages chat histories and physical KV caches between RAM/VRAM and SSD, restores them on later requests, and compacts stale state; implementation is `ore-core/src/memory.rs` with native KV ownership in `ore-core/src/native/kv_manager.rs`. This is the key scaling boundary for concurrent, stateful agents.

#### Driver HAL and Native/External Engines
Application logic depends on the `InferenceDriver` abstraction in `ore-core/src/driver.rs`, allowing backend selection without handler changes. `ore-core/src/external/ollama.rs` proxies a running Ollama daemon over HTTP. The native backend in `ore-core/src/native/mod.rs` uses Candle to load GGUF models, detect CPU/CUDA/Metal hardware, stream generation, and provide local embeddings; runtime model routing resides in `ore-core/src/native/engine.rs`. Native model implementations include Llama/Qwen and BERT/Nomic embedding architectures under `ore-core/src/native/models/`.

#### Agent Collaboration and Tool Execution
IPC provides direct per-agent message queues plus semantic-memory pipes backed by embeddings, shared caches, similarity search, TTL cleanup, and manifest-enforced pipe permissions. The server boundary is `ore-server/src/handlers/ipc.rs`; kernel implementation is `ore-core/src/ipc.rs`. Tool execution is separately routed through `ore-core/src/sandbox.rs`: precompiled WASM tools execute with Wasmtime fuel limits, capability-scoped filesystem mounts, trapped I/O, and manifest checks. Shell execution is an explicit unsafe bypass; network/tool policies remain manifest-controlled.

#### Client and External Infrastructure
The CLI communicates with the authenticated local daemon and handles initialization, model lifecycle, manifests, interactive chat, and WASM tool compilation. Its command surface is organized in `ore-cli/src/cli.rs` and interactive UI in `ore-cli/src/interactive.rs`. Material dependencies are Tokio/Axum for async server/streaming, Candle for local inference, Wasmtime/cap-std for sandboxing, Hugging Face Hub for native model downloads, and optional Ollama as an external local inference service.

Main entry points: [`ore-server/src/handlers/inference.rs`](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/handlers/inference.rs) (Inference API), [`ore-core/src/registry.rs`](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/registry.rs) (Policy Registry), [`ore-cli/src/main.rs`](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-cli/src/main.rs) (ORE CLI), [`ore-server/src/main.rs`](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/main.rs) (HTTP Daemon)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client Access"]
  node_cli["ORE CLI<br/>client<br/>[main.rs]"]
  node_interactive["Interactive UI<br/>CLI UI<br/>[interactive.rs]"]
end

subgraph group_server["Local Daemon"]
  node_daemon["HTTP Daemon<br/>Axum server<br/>[main.rs]"]
  node_auth["Auth Middleware<br/>[middleware.rs]"]
  node_inference_api["Inference API<br/>route handler<br/>[inference.rs]"]
  node_ipc_api["IPC API<br/>route handler<br/>[ipc.rs]"]
  node_state["Shared Kernel State<br/>server state<br/>[state.rs]"]
end

subgraph group_kernel["Kernel Core"]
  node_manifests["App Manifests<br/>policy inputs<br/>[openclaw.toml]"]
  node_registry["Policy Registry<br/>manifest registry<br/>[registry.rs]"]
  node_firewall["Prompt Firewall<br/>security filter<br/>[firewall.rs]"]
  node_scheduler["GPU Scheduler<br/>capacity scheduler<br/>[scheduler.rs]"]
  node_memory["Agent Memory<br/>state paging<br/>[memory.rs]"]
  node_ipc["Agent IPC<br/>message and semantic memory<br/>[ipc.rs]"]
  node_sandbox["Tool Sandbox<br/>WASM executor<br/>[sandbox.rs]"]
end

subgraph group_backends["Inference Backends"]
  node_driver["Inference Driver HAL<br/>driver abstraction<br/>[driver.rs]"]
  node_native_engine["Native Candle Engine<br/>local inference engine<br/>[engine.rs]"]
  node_ollama["Ollama Proxy<br/>external driver<br/>[ollama.rs]"]
  node_ollama_daemon["Ollama Daemon<br/>external service"]
end

node_workspace["Rust Workspace<br/>[Cargo.toml]"]

node_workspace -->|"builds"| node_cli
node_workspace -->|"builds"| node_daemon
node_cli -->|"hosts"| node_interactive
node_cli -->|"authenticated local HTTP"| node_daemon
node_daemon -->|"protects routes with"| node_auth
node_auth -->|"authorizes"| node_inference_api
node_auth -->|"authorizes"| node_ipc_api
node_daemon -->|"initializes and shares"| node_state
node_manifests -->|"loaded into"| node_registry
node_state -->|"holds"| node_registry
node_inference_api -->|"resolves caller policy"| node_registry
node_inference_api -->|"filters prompts"| node_firewall
node_inference_api -->|"restores and persists state"| node_memory
node_inference_api -->|"acquires lease"| node_scheduler
node_scheduler -->|"invokes"| node_driver
node_state -->|"selects"| node_driver
node_driver -->|"native implementation"| node_native_engine
node_driver -->|"external implementation"| node_ollama
node_ollama -->|"HTTP"| node_ollama_daemon
node_memory -->|"supplies restored context"| node_scheduler
node_ipc_api -->|"serves"| node_ipc
node_ipc -->|"enforces pipe permissions"| node_registry
node_sandbox -->|"enforces tool permissions"| node_registry
node_cli -.->|"compiles WASM tools"| node_sandbox

click node_workspace "https://github.com/mahavishnu-k/ore-kernel/blob/main/Cargo.toml"
click node_cli "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-cli/src/main.rs"
click node_interactive "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-cli/src/interactive.rs"
click node_daemon "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/main.rs"
click node_auth "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/middleware.rs"
click node_inference_api "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/handlers/inference.rs"
click node_ipc_api "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/handlers/ipc.rs"
click node_state "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/state.rs"
click node_manifests "https://github.com/mahavishnu-k/ore-kernel/blob/main/manifests/openclaw.toml"
click node_registry "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/registry.rs"
click node_firewall "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/firewall.rs"
click node_scheduler "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/scheduler.rs"
click node_memory "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/memory.rs"
click node_ipc "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/ipc.rs"
click node_sandbox "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/sandbox.rs"
click node_driver "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/driver.rs"
click node_native_engine "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/native/engine.rs"
click node_ollama "https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/external/ollama.rs"

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_cli,node_interactive toneBlue
class node_daemon,node_auth,node_inference_api,node_ipc_api,node_state toneAmber
class node_manifests,node_registry,node_firewall,node_scheduler,node_memory,node_ipc,node_sandbox toneMint
class node_driver,node_native_engine,node_ollama,node_ollama_daemon toneRose
class node_workspace toneNeutral
```

## Components

### Client Access

- [ORE CLI](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-cli/src/main.rs): client · Commands and interactive local workflows. · `ore-cli/src/main.rs`
- [Interactive UI](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-cli/src/interactive.rs): CLI UI · `ore-cli/src/interactive.rs`

### Local Daemon

- [HTTP Daemon](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/main.rs): Axum server · Authenticated local boundary for kernel access. · `ore-server/src/main.rs`
- [Auth Middleware](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/middleware.rs): middleware · `ore-server/src/middleware.rs`
- [Inference API](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/handlers/inference.rs): route handler · `ore-server/src/handlers/inference.rs`
- [IPC API](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/handlers/ipc.rs): route handler · `ore-server/src/handlers/ipc.rs`
- [Shared Kernel State](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-server/src/state.rs): server state · Configuration, selected driver, registry, and session state. · `ore-server/src/state.rs`

### Kernel Core

- [App Manifests](https://github.com/mahavishnu-k/ore-kernel/blob/main/manifests/openclaw.toml): policy inputs · Per-application permissions, quotas, model, IPC, and tool policy. · `manifests/openclaw.toml`
- [Policy Registry](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/registry.rs): manifest registry · In-memory O(1) policy lookup. · `ore-core/src/registry.rs`
- [Prompt Firewall](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/firewall.rs): security filter · Detects injection patterns and redacts PII before inference. · `ore-core/src/firewall.rs`
- [GPU Scheduler](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/scheduler.rs): capacity scheduler · RAII leases arbitrate active inference and model/context reuse. · `ore-core/src/scheduler.rs`
- [Agent Memory](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/memory.rs): state paging · Pages histories and KV state across RAM, VRAM, and SSD. · `ore-core/src/memory.rs`
- [Agent IPC](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/ipc.rs): message and semantic memory · Queues, embedding-backed pipes, caches, and TTL cleanup. · `ore-core/src/ipc.rs`
- [Tool Sandbox](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/sandbox.rs): WASM executor · Wasmtime fuel and capability-scoped tool execution. · `ore-core/src/sandbox.rs`

### Inference Backends

- [Inference Driver HAL](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/driver.rs): driver abstraction · Backend-independent inference interface. · `ore-core/src/driver.rs`
- [Native Candle Engine](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/native/engine.rs): local inference engine · Routes GGUF models across CPU, CUDA, or Metal. · `ore-core/src/native/engine.rs`
- [Ollama Proxy](https://github.com/mahavishnu-k/ore-kernel/blob/main/ore-core/src/external/ollama.rs): external driver · HTTP proxy to an optional local Ollama daemon. · `ore-core/src/external/ollama.rs`
- **Ollama Daemon**: external service

### Other components

- [Rust Workspace](https://github.com/mahavishnu-k/ore-kernel/blob/main/Cargo.toml): workspace · `Cargo.toml`

## Connections

- Rust Workspace → ORE CLI: builds
- Rust Workspace → HTTP Daemon: builds
- ORE CLI → Interactive UI: hosts
- ORE CLI → HTTP Daemon: authenticated local HTTP
- HTTP Daemon → Auth Middleware: protects routes with
- Auth Middleware → Inference API: authorizes
- Auth Middleware → IPC API: authorizes
- HTTP Daemon → Shared Kernel State: initializes and shares
- App Manifests → Policy Registry: loaded into
- Shared Kernel State → Policy Registry: holds
- Inference API → Policy Registry: resolves caller policy
- Inference API → Prompt Firewall: filters prompts
- Inference API → Agent Memory: restores and persists state
- Inference API → GPU Scheduler: acquires lease
- GPU Scheduler → Inference Driver HAL: invokes
- Shared Kernel State → Inference Driver HAL: selects
- Inference Driver HAL → Native Candle Engine: native implementation
- Inference Driver HAL → Ollama Proxy: external implementation
- Ollama Proxy → Ollama Daemon: HTTP
- Agent Memory → GPU Scheduler: supplies restored context
- IPC API → Agent IPC: serves
- Agent IPC → Policy Registry: enforces pipe permissions
- Tool Sandbox → Policy Registry: enforces tool permissions
- ORE CLI → Tool Sandbox: compiles WASM tools
