Skip to content
Kaiov0.8.0

Overview

Kaio follows Hexagonal / Clean Architecture: a shared core crate holds all business logic, a thin server crate exposes it over HTTP, a cli crate consumes that HTTP API, and an mcp crate turns the same core into tools for AI agents. The React bundle is compiled into the server binary, so the process that answers /api is also the one that serves the page calling it.

flowchart TD
subgraph clients [Clients]
  web["React front<br/>Tailwind, Monaco"]
  term["CLI and TUI<br/>comfy-table"]
  agent["AI agent<br/>MCP client"]
end

web -- "REST, SSE, WS" --> server
server -. "the bundle it was built with" .-> web
term -- "REST, SSE" --> server
agent -- "MCP, streamable HTTP" --> server

server["server crate<br/>Axum, thin HTTP layer<br/>one access check per call"] --> mcp
server --> core
mcp["mcp crate<br/>tools at /mcp"] --> core
core["core crate<br/>rules, use cases, read models<br/>stacks, scans, events, db"] <--> db[("SQLite, WAL")]
core -. "TypeScript types, generated" .-> web

core --> sync["Docker sync worker"]
core --> checker["Update checker<br/>skopeo"]
core --> files["./data/stacks<br/>compose and env"]

sync --> sock["/var/run/docker.sock"]
checker --> registries["Registries"]
Every client talks to the same server, which delegates every decision to core.

Every request crosses one layer in the server before any handler runs. It collects the facts of the request, the address it came from, its headers, its method and path, and hands them to core::access as plain values, which decides who the caller is and whether their level reaches the route. core knows no web framework: it takes those facts in, and gives back data or an error with a stable code, which the server alone turns into an HTTP status and body. The same decision serves the REST API, the WebSocket shell and /mcp, so the web UI, the CLI, the TUI and an agent share one permission model. Sensitive actions are written to the audit log from the same place. See Security.

Kaio drives the daemon of the host it runs on, and nothing else. Operating several hosts means running Kaio on each and having them join one another.

flowchart TD
subgraph cp ["Control plane, the server you open"]
  cpcore["core"]
  cpdb[("SQLite<br/>cluster, nodes")]
  cpcore <--> cpdb
  cpsock["/var/run/docker.sock"]
  cpcore --> cpsock
end

subgraph n1 ["Node: prod-01"]
  n1core["core"]
  n1sock["/var/run/docker.sock"]
  n1core --> n1sock
end

subgraph n2 ["Node: prod-02"]
  n2core["core"]
  n2sock["/var/run/docker.sock"]
  n2core --> n2sock
end

n1core -- "1. join: token, and the node's key" --> cpcore
cpcore -. "control plane's public key" .-> n1core
cpcore -- "2. GET /api/health" --> n1core
cpcore == "3. signed: /api/nodes/prod-01/proxy/..." ==> n1core
n2core -- "4. leave: DELETE /api/nodes/prod-02" --> cpcore
A node enrols itself and the two trade public keys, the control plane probes it and then forwards to it on request, every call signed for that node with the caller inside, and a node that leaves asks to be dropped and forgets the key.

There is no agent. A node runs an ordinary Kaio, and the HTTP API it already exposes is the protocol the control plane speaks to it. Nothing is installed on a node that is not installed on a single-host install.

The token is checked at step 1 and never again. It is not a credential the two keep presenting to each other: what binds them afterwards is the key each one pinned for the other, and every call of step 3 is signed with the control plane’s. A row going away closes the route; cluster leave makes the node forget the key.

Both are initiated by the node, from the machine that is joining or leaving, and both reach across:

The node does The control plane ends up with
join presents the token and its own identity a row: name, URL, and the probe that follows
leave asks for its row to be dropped nothing, and the route closes with it

A node that cannot reach its control plane still leaves, locally, and says what is left to do. Decommissioning a server does not depend on another one being up.

The control plane can also evict with node rm, which drops the row without telling the node. Either side can end it; only the node’s own command leaves both in agreement.

Membership lives in a one-row cluster table on both sides, and the registry in a nodes table on the control plane:

Table On the control plane On a node
cluster its own identity and signing key its own identity and signing key, which cluster it joined, and that control plane’s public key
join_tokens the hashes of the tokens it minted and nobody has spent empty
nodes one row per joined server, with the key it joined with empty

Leaving clears the node’s three membership columns and deletes the control plane’s row. The identities on both sides are untouched: a server keeps the same one across joins, which is what makes it recognisable if it comes back.

A server’s identity is a UUID minted on first use and kept for the life of its data/. It is the id of the node row, which is what makes a moved server recognisable: rejoining from a new address corrects the row instead of adding a second one. It is also how a control plane refuses to enrol itself, and how a probe tells a node apart from a stranger that took over its address.

/api/nodes/{name}/proxy/{*path} forwards to {node url}/{path}. It is what lets one dashboard drive any node, and what kaio-cli node prod-01 run uses: the name is resolved against the registry, so a node that is not in it has no route. Responses are streamed rather than buffered, so a followed log arrives line by line, and a WebSocket upgrade is bridged socket to socket, so the container terminal works across the hop.

Every call the gateway relays is signed with the control plane’s Ed25519 key, for that node, with the caller’s user and level inside the signature. The node holds the call to that level and records that user, so a node needs no open port to be driven, and routes kept for the control plane stay shut through the gateway.

The registry says where each server is and whether it answers. It schedules nothing: there is no placement, no failover, no workload moved between hosts. Membership is also what a node trusts: once joined, it accepts calls signed by its control plane, and cluster leave ends that.

Crate Role
core Every rule and use case: stack lifecycle, what a stack is and what state it is in, what needs attention, who may act on what, vulnerability scanning, event recording; the read models every client shows (stack groups, overview, stack detail); Docker integration and all database access. No web framework: requests arrive as plain facts, errors leave with a code
server Axum REST API and SSE: turns a request into facts for core, and a core error into an HTTP status and body. Decides nothing itself, permissions included
mcp The /mcp endpoint: tools over core, filtered by the caller’s level
cli Command-line interface and TUI, a thin client over the server API

Centralising the rules in core is what keeps a stack’s state, what needs attention, a stack started outside Kaio or a refusal identical in the web UI, the CLI, the TUI and on the MCP endpoint: each computes nothing of its own, and the web UI’s TypeScript types are generated from core’s models. See Where code goes.

  • Backend in Rust: Axum, SQLx, Bollard, Tokio
  • Frontend: React, TypeScript, Tailwind CSS, Monaco Editor and Xterm.js (both lazy-loaded)
  • Database: SQLite via SQLx, WAL mode
  • Typography: Courier Prime
  • Connection pooling: a single Docker client connection is reused across all API requests and background workers.
  • Smart metrics collection: the poller only fetches expensive stats (CPU/IO) for running or paused containers.
  • Parallel I/O: registry checks and metric collection run concurrently on Tokio; nothing blocking sits on a request path.
  • Frontend: code splitting for xterm.js and monaco-editor (≈50 % off the initial bundle), and useMemo on the heavy aggregations so hundreds of containers stay fluid.
  • Clippy with -D warnings, rustfmt enforced in CI
  • End-to-end type safety: Rust on the backend, TypeScript on the frontend
  • make verify runs the whole gate locally

Kaio, built by Régis Gaidot