Skip to content

Architecture & Development ​

This section covers how Kompile's processes, persona boundaries, extension composition, release distributions, and distributed crawl clusters are designed — followed by contributor guides for building Kompile from source.

In this section ​

GroupPagesWhat it covers
System ArchitectureArchitecture Overview (this page) · App Persona Boundary · CLI Extension Composition · Release Distributions · Distributed Crawl Cluster · Distributed Crawl HardeningProcess boundaries (kompile-server, kompile-chat, kompile-crawl-manager, kompile-model-staging), extension loading, distribution packaging, and cluster crawls
Building & ContributingDevelopment Guide · Build Your Own Dist · kompile-cli · kompile-app · kompile-pipelines · Anserini · tokenizers-rust · Model ImportersCompiling from source, GraalVM native images, custom distribution builds, and per-module internals

System overview ​

Kompile separates the standalone developer harness (kompile CLI + optional local-runtime) from the distributed collaboration server platform (kompile-app + kompile-model-staging). Most individual coding workflows only need the harness; teams and larger distributed deployments add kompile-app.

  ┌─────────────────────────────────────────────────────────────────────────┐
  │  Standalone Harness: kompile (CLI & Web Harness)                        │
  │  - Persistent chat ledgers, memory, code index/graph, audit trails      │
  │  - Local Web UI (kompile chat --web), MCP stdio/daemon, ACP v1          │
  │  - Enforcer, Judge, Subagents, Extensions, Spins, TLS Peer Sync         │
  │  - Optional local-runtime overlay: local RAG, .kgraph, local LLMs/OCR   │
  └───────────────────────────────┬─────────────────────────────────────────┘
                                  │  (opt-in for distributed systems & teams)
          ┌───────────────────────┴───────────────────────┐
          ▼                                               ▼
  ┌─────────────────────────────────────────┐   ┌───────────────────────────┐
  │  kompile-app (3 isolated personas)      │   │  kompile-model-staging    │
  │  • kompile-server        (:8080 admin)  │◄─►│  (:8090 model lifecycle)  │
  │  • kompile-chat          (:8081 team)   │   │  • HF download & convert  │
  │  • kompile-crawl-manager (:8082 crawls) │   │  • LoRA/PEFT training     │
  │                                         │   │  • .karch & hot-reload    │
  │  Shared DBs (pgvector/Chroma/Vespa/     │   └───────────────────────────┘
  │  Neo4j), distributed crawl clusters,    │
  │  scheduled sync, inbound team channels, │
  │  collaborative fact sheets & REST/SSE   │
  └───────────────────┬─────────────────────┘
                      │ subprocess (--subprocess=TYPE)
            ┌─────────┴──────────┐
            ▼                    ▼
     ┌─────────────┐     ┌────────────────┐
     │ ingest      │     │ vector / graph │
     │ (load+chunk)│     │ (embed+index)  │
     └─────────────┘     └────────────────┘

Harness vs. kompile-app vs. kompile-model-staging ​

kompile (Standalone CLI & Web Harness) is complete on its own. It owns local persistence (conversation ledgers, persistent memory, code index & code graph, credentials, enforcer/judge configs, audit trails), hosts a local browser workspace (kompile chat --web), serves MCP tools (mcp-stdio / kompile serve), syncs with peers (kompile peer), and — with the optional local-runtime overlay — runs single-machine document crawling, hybrid RAG, .kgraph reasoning, and local LLM serving without any server processes.

kompile-app (Distributed Server & Team Collaboration Stack) is for larger distributed systems and multi-user collaboration. It splits into three classpath-isolated Spring Boot + Angular persona processes (see App Persona Boundary):

  • kompile-app-main (:8080, bin/kompile-server) — Admin console, KClaw browser agent hub, inbound team messaging channels (Slack, Telegram, Discord, WhatsApp, email), A2A endpoints, graph maintenance/evaluation/simulation, and cluster/GPU operations.
  • kompile-app-chat (:8081, bin/kompile-chat) — End-user multi-user RAG chat, project browsing, read-only fact sheets, and graph viewing over shared team knowledge bases.
  • kompile-app-crawl-manager (:8082, bin/kompile-crawl-manager) — Scheduled Quartz crawls, distributed multi-node crawl clusters with worker heartbeats and failover (Distributed Crawl Cluster), enterprise cloud-source OAuth connectors, collaborative fact sheets, and index management over shared external stores (pgvector, Chroma, Vespa, Neo4j).

kompile-model-staging (:8090) handles shared model lifecycle operations for server deployments: downloading and converting formats (ONNX, GGUF, TensorFlow → SameDiff), LoRA/PEFT training, .karch archive management, OpenAI-compatible serving, and notifying kompile-app nodes to hot-reload after promotion. For single-machine local models without a server, use kompile local-models with local-runtime instead.

Data flow ​

Indexing ​

Your documents
  |
  [Crawl] -> [Load] -> [Preprocess] -> [Route]
                                          |
                         +----------------+----------------+
                         |                                 |
                    [Text pipeline]                  [VLM pipeline]
                         |                                 |
                     [Chunk]                           [OCR]
                         |                                 |
                         +----------------+----------------+
                                          |
                                   [Graph extract]  (optional)
                                          |
                                   [Entity resolve] (optional)
                                          |
                                      [Embed]
                                          |
                                      [Index]
                                          |
                               +----------+----------+
                               |                     |
                        Vector store          Knowledge graph

See Crawl Jobs and Ingestion Pipeline for details.

Querying ​

User question
  |
  [Query transform]  (optional: HyDE, multi-query, step-back)
  |
  [Embed query]
  |
  +---[Vector search]---+---[BM25 search]---+---[Graph RAG]---+
  |                     |                   |                  |
  +---------------------+-------------------+------------------+
  |
  [Merge + dedup + rerank]
  |
  [Assemble context]  (+ fact sheet facts)
  |
  [LLM generation]
  |
  Response with source attribution

See Information Retrieval for the full retrieval architecture.

Subprocess model ​

Compute-heavy work runs as isolated subprocesses — the same binary re-launched with --subprocess=TYPE. This provides:

  • Memory isolation: A subprocess OOM doesn't crash the web server
  • Responsiveness: The web server stays fast while embedding runs
  • Resource control: Each subprocess has its own heap size and timeout
Subprocess typeWhat it does
ingestLoad and chunk documents
vector-populationEmbed chunks and write to vector store
embeddingStandalone embedding computation
model-initModel download and initialization
pipeline-servingReusable stdio runtime for all model-backed pipeline steps, including VLM/OCR
trainingModel training jobs

Subprocesses are launched with --subprocess=TYPE. Configuration lives in subprocess-ingest-config.json. The web server monitors subprocess health via RSS tracking.

Model-staging is a separate orchestrator that uses nd4j-native only (CPU). It never loads CUDA itself — it launches subprocesses with CUDA backends for GPU work. This separation prevents GPU memory conflicts.

Plugin architecture ​

The server's behavior changes based on which modules are on the classpath:

java
@Component
@ConditionalOnProperty(name = "kompile.vectorstore.type", havingValue = "pgvector")
public class PgVectorStoreImpl implements VectorStore { ... }

Every major component (embeddings, vector stores, LLMs, loaders, chunkers, graph backends) is an interface with pluggable implementations. Spring Boot's conditional bean loading activates only the implementations that match your configuration.

This means:

  • The full binary contains all modules, but only configured ones are active
  • Custom builds (kompile build app) can exclude unused modules entirely
  • Swapping a component (e.g., Anserini -> pgvector) is a config change, not a code change

Configuration flow ​

All runtime configuration lives in JSON files at ~/.kompile/config/:

CLI wizards  ---+
                +--->  ~/.kompile/config/*.json  --->  Server reads on
Web UI       ---+                                     startup (and reloads
REST API     ---+                                     on change)

Spring properties (application.properties) exist only for bootstrap defaults — port numbers, paths, which providers are enabled/disabled. The JSON config files always take precedence at runtime. This is intentional: config should be manageable through the UI and CLI, not buried in properties files.

See Configuration for the full config reference.

Native image compilation ​

GraalVM native image compilation produces a single binary with no JVM dependency. Class initialization is split:

  • Build-time: Logging (SLF4J, Logback), static configs, Picocli command metadata
  • Run-time: ND4J, JNI (JavaCPP, Bytedeco), JGit, Netty Epoll, dynamic proxy generation

Platform-specific native libraries are included/excluded via Maven profiles that auto-detect the build platform. The kompile build dist command builds all three binaries (CLI, server, model-staging) into a distribution tarball.

Key design decisions ​

Why subprocess isolation instead of thread pools? Native memory (ND4J, CUDA) is hard to reclaim once allocated. Subprocess isolation guarantees cleanup — when the subprocess exits, the OS reclaims all memory. Thread-pool approaches risk native memory leaks and GPU memory fragmentation.

Why JSON config instead of Spring properties? Properties files are developer-facing. JSON config files can be read and written by the web UI, CLI wizards, and the REST API. The same config is editable through three interfaces. Properties files would require server restarts; JSON files are hot-reloaded.

Why separate model-staging? Model operations (download, convert, train) need CPU-only orchestration with GPU work delegated to subprocesses. If the server loaded models directly, a model conversion OOM could crash the web UI. Separation also enables hot-reload: staging promotes a model and sends an HTTP callback to the server, which loads the new model without restarting.

Why a single binary for subprocesses? Instead of separate binaries for ingestion, embedding, and indexing, one binary handles all subprocess types via --subprocess=TYPE. This simplifies deployment (one binary per component), ensures version consistency (subprocess always matches server), and works naturally with native image compilation.

Released under the Apache-2.0 License.