# boxlite-ai/boxlite architecture

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

- Interactive diagram: https://gitdiagram.com/boxlite-ai/boxlite
- Repository: https://github.com/boxlite-ai/boxlite

## Overview

#### Purpose and primary entry points
BoxLite is a Rust micro-VM runtime for persistent OCI-image workloads, exposed as embedded SDKs, a CLI/REST server, and an optional multi-tenant cloud control plane. Core local entry points are the runtime crate at `src/boxlite/src/lib.rs`, CLI binary at `src/cli/src/main.rs`, and REST serving commands under `src/cli/src/commands/serve/`. Language bindings wrap the same native runtime in `sdks/python/src/lib.rs`, `sdks/node/src/lib.rs`, `sdks/go/runtime.go`, and `sdks/c/src/lib.rs`.

#### Local runtime orchestration
The runtime coordinates box identity, configuration, persistence, lifecycle, and backend selection. `src/boxlite/src/runtime/core.rs` and `src/boxlite/src/runtime/rt_impl.rs` expose runtime operations; `src/boxlite/src/litebox/manager.rs` owns box lifecycle. A box creation path prepares an OCI-derived root filesystem and disk, launches a VM, then establishes a host-to-guest control channel; stop/restart preserves local state.

#### VM, guest, and execution boundary
Each box is a VM controlled by the host runtime through the VMM abstraction in `src/boxlite/src/vmm/engine.rs` and platform-specific libkrun implementation in `src/boxlite/src/vmm/krun/engine.rs`. Inside the guest, `src/guest/src/main.rs` starts services; `src/guest/src/service/server.rs` serves the shared protocol defined by `src/shared/proto/boxlite/v1/service.proto`. The guest manages OCI-container lifecycle and commands in `src/guest/src/container/` and `src/guest/src/service/exec/`, returning streamed execution state across this boundary.

#### Isolation, storage, images, and networking
Host-side jailer construction applies OS sandboxing, credentials, cgroups/rlimits, and syscall controls through `src/boxlite/src/jailer/builder.rs`, `src/boxlite/src/jailer/seccomp.rs`, and `src/boxlite/src/jailer/sandbox/`. OCI images are fetched, verified/unpacked, cached, and converted to usable disks by `src/boxlite/src/images/manager.rs` and `src/boxlite/src/images/archive/`. Persistent box data uses QCOW2/ext4 and volume layers in `src/boxlite/src/disk/`, `src/boxlite/src/db/`, and `src/boxlite/src/volumes/`. Network forwarding and egress policy integrate through `src/boxlite/src/net/gvproxy/`.

#### CLI, SDK, and standalone REST surfaces
The CLI dispatches local or remote lifecycle, exec, image, file, and auth operations from `src/cli/src/cli.rs` and `src/cli/src/commands/`. Server mode maps HTTP/WebSocket requests to runtime actions via `src/cli/src/commands/serve/handlers/`. SDKs present idiomatic APIs but bind to the Rust engine; the C SDK is the FFI foundation for Go, while Python and Node build native extension layers. Remote REST support is also implemented inside the runtime under `src/boxlite/src/rest/`.

#### Cloud control plane and fleet runner
The cloud stack separates a TypeScript/NestJS control plane from Go runners that host BoxLite workloads. The API boots at `apps/api/src/main.ts`; box desired state, jobs, runners, volumes, and adapters are centered in `apps/api/src/box/services/box.service.ts`, `apps/api/src/box/managers/box.manager.ts`, and `apps/api/src/box/runner-adapter/`. Runners start at `apps/runner/cmd/runner/main.go`, poll/execute work in `apps/runner/pkg/runner/v2/`, and invoke local BoxLite through `apps/runner/pkg/boxlite/`. This is the principal control-plane-to-compute trust and scheduling boundary.

#### Cloud clients, identity, observability, and infrastructure
The dashboard is a React/Vite client rooted at `apps/dashboard/src/main.tsx`, using generated control-plane clients under `apps/libs/api-client/src/`. Authentication supports JWT/API-key and runner-specific guards in `apps/api/src/auth/`; organization and region tenancy are enforced in `apps/api/src/organization/` and `apps/api/src/region/`. Material services indicated by adapters/modules include PostgreSQL/TypeORM, Redis locks and notifications, Kafka audit transport, ClickHouse telemetry, OpenSearch audit storage, S3/CloudWatch observability, PostHog/OpenFeature, OIDC/Dex, and Svix webhooks. AWS/Cloudflare deployment is defined by `apps/infra/sst.config.ts`; OpenTelemetry collection is a separate Go-based image/service in `apps/otel-collector/`.

Main entry points: [`src/boxlite/src/litebox/manager.rs`](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/litebox/manager.rs) (Box lifecycle), [`src/boxlite/src/runtime/core.rs`](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/runtime/core.rs) (Runtime core), [`apps/api/src/main.ts`](https://github.com/boxlite-ai/boxlite/blob/main/apps/api/src/main.ts) (Control-plane API), [`src/boxlite/src/vmm/engine.rs`](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/vmm/engine.rs) (VMM abstraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_local["Local BoxLite"]
  node_runtime["Runtime core<br/>Rust runtime<br/>[core.rs]"]
  node_box_manager["Box lifecycle<br/>lifecycle manager<br/>[manager.rs]"]
  node_images[("OCI image pipeline<br/>image manager<br/>[manager.rs]")]
  node_storage[("Persistent storage<br/>disk and volumes<br/>[mod.rs]")]
  node_jailer{{"Host isolation<br/>jailer<br/>[builder.rs]"}}
  node_vmm{{"VMM abstraction<br/>VM engine<br/>[engine.rs]"}}
  node_krun{{"libkrun backend<br/>platform VMM<br/>[engine.rs]"}}
  node_network["Network forwarding<br/>gvproxy integration<br/>[mod.rs]"]
end

subgraph group_guest["VM Guest"]
  node_protocol["Shared control protocol<br/>protobuf API<br/>[service.proto]"]
  node_guest_server["Guest service<br/>guest server<br/>[server.rs]"]
  node_containers["Guest containers<br/>OCI execution<br/>[mod.rs]"]
end

subgraph group_interfaces["Developer Surfaces"]
  node_cli["CLI<br/>Rust binary<br/>[main.rs]"]
  node_rest_server["Standalone REST server<br/>HTTP/WebSocket handlers<br/>[mod.rs]"]
  node_sdks["Language SDKs<br/>native bindings<br/>[lib.rs]"]
end

subgraph group_cloud["Cloud Platform"]
  node_control_api["Control-plane API<br/>NestJS API<br/>[main.ts]"]
  node_identity_tenancy{{"Identity and tenancy<br/>auth guards<br/>[auth.module.ts]"}}
  node_cloud_data[("Cloud data services<br/>state and messaging<br/>[runnerAdapter.ts]")]
  node_runner["Fleet runner<br/>Go worker<br/>[main.go]"]
  node_runner_boxlite["Runner BoxLite adapter<br/>local runtime client<br/>[client.go]"]
  node_dashboard["Dashboard<br/>React client<br/>[main.tsx]"]
  node_api_client["Generated API client<br/>TypeScript client<br/>[index.ts]"]
  node_infrastructure["Cloud deployment<br/>AWS/Cloudflare infrastructure<br/>[sst.config.ts]"]
end

node_cli -->|"local commands"| node_runtime
node_rest_server -->|"runtime actions"| node_runtime
node_sdks -->|"native bindings"| node_runtime
node_runtime -->|"lifecycle"| node_box_manager
node_box_manager -->|"prepare rootfs"| node_images
node_box_manager -->|"preserve state"| node_storage
node_box_manager -->|"sandbox VM"| node_jailer
node_box_manager -->|"launch VM"| node_vmm
node_vmm -->|"platform backend"| node_krun
node_box_manager -->|"configure forwarding"| node_network
node_vmm -->|"hosts guest"| node_guest_server
node_runtime -->|"control channel"| node_protocol
node_protocol -->|"serves"| node_guest_server
node_guest_server -->|"lifecycle and exec"| node_containers
node_dashboard -->|"uses"| node_api_client
node_api_client -->|"control requests"| node_control_api
node_control_api -->|"authorize and scope"| node_identity_tenancy
node_control_api -->|"state, jobs, events"| node_cloud_data
node_control_api -->|"desired state and jobs"| node_runner
node_runner -->|"execute locally"| node_runner_boxlite
node_runner_boxlite -.->|"host workloads"| node_runtime
node_infrastructure -.->|"deploys"| node_control_api
node_infrastructure -.->|"deploys"| node_runner

click node_runtime "https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/runtime/core.rs"
click node_box_manager "https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/litebox/manager.rs"
click node_images "https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/images/manager.rs"
click node_storage "https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/disk/mod.rs"
click node_jailer "https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/jailer/builder.rs"
click node_vmm "https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/vmm/engine.rs"
click node_krun "https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/vmm/krun/engine.rs"
click node_network "https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/net/gvproxy/mod.rs"
click node_protocol "https://github.com/boxlite-ai/boxlite/blob/main/src/shared/proto/boxlite/v1/service.proto"
click node_guest_server "https://github.com/boxlite-ai/boxlite/blob/main/src/guest/src/service/server.rs"
click node_containers "https://github.com/boxlite-ai/boxlite/blob/main/src/guest/src/container/mod.rs"
click node_cli "https://github.com/boxlite-ai/boxlite/blob/main/src/cli/src/main.rs"
click node_rest_server "https://github.com/boxlite-ai/boxlite/blob/main/src/cli/src/commands/serve/handlers/mod.rs"
click node_sdks "https://github.com/boxlite-ai/boxlite/blob/main/sdks/c/src/lib.rs"
click node_control_api "https://github.com/boxlite-ai/boxlite/blob/main/apps/api/src/main.ts"
click node_identity_tenancy "https://github.com/boxlite-ai/boxlite/blob/main/apps/api/src/auth/auth.module.ts"
click node_cloud_data "https://github.com/boxlite-ai/boxlite/blob/main/apps/api/src/box/runner-adapter/runnerAdapter.ts"
click node_runner "https://github.com/boxlite-ai/boxlite/blob/main/apps/runner/cmd/runner/main.go"
click node_runner_boxlite "https://github.com/boxlite-ai/boxlite/blob/main/apps/runner/pkg/boxlite/client.go"
click node_dashboard "https://github.com/boxlite-ai/boxlite/blob/main/apps/dashboard/src/main.tsx"
click node_api_client "https://github.com/boxlite-ai/boxlite/blob/main/apps/libs/api-client/src/index.ts"
click node_infrastructure "https://github.com/boxlite-ai/boxlite/blob/main/apps/infra/sst.config.ts"

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_runtime,node_box_manager,node_images,node_storage,node_jailer,node_vmm,node_krun,node_network toneBlue
class node_protocol,node_guest_server,node_containers toneAmber
class node_cli,node_rest_server,node_sdks toneMint
class node_control_api,node_identity_tenancy,node_cloud_data,node_runner,node_runner_boxlite,node_dashboard,node_api_client,node_infrastructure toneRose
```

## Components

### Local BoxLite

- [Runtime core](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/runtime/core.rs): Rust runtime · Coordinates identity, configuration, persistence, lifecycle, and backend selection. · `src/boxlite/src/runtime/core.rs`
- [Box lifecycle](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/litebox/manager.rs): lifecycle manager · Creates, stops, and restarts persistent boxes. · `src/boxlite/src/litebox/manager.rs`
- [OCI image pipeline](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/images/manager.rs): image manager · Fetches, verifies, unpacks, caches, and converts images. · `src/boxlite/src/images/manager.rs`
- [Persistent storage](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/disk/mod.rs): disk and volumes · QCOW2/ext4 box state and volume layers. · `src/boxlite/src/disk/mod.rs`
- [Host isolation](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/jailer/builder.rs): jailer · Applies sandboxing, credentials, limits, and syscall controls. · `src/boxlite/src/jailer/builder.rs`
- [VMM abstraction](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/vmm/engine.rs): VM engine · `src/boxlite/src/vmm/engine.rs`
- [libkrun backend](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/vmm/krun/engine.rs): platform VMM · `src/boxlite/src/vmm/krun/engine.rs`
- [Network forwarding](https://github.com/boxlite-ai/boxlite/blob/main/src/boxlite/src/net/gvproxy/mod.rs): gvproxy integration · Provides forwarding and egress policy. · `src/boxlite/src/net/gvproxy/mod.rs`

### VM Guest

- [Shared control protocol](https://github.com/boxlite-ai/boxlite/blob/main/src/shared/proto/boxlite/v1/service.proto): protobuf API · Host-to-guest control and streamed execution contract. · `src/shared/proto/boxlite/v1/service.proto`
- [Guest service](https://github.com/boxlite-ai/boxlite/blob/main/src/guest/src/service/server.rs): guest server · Starts guest services and serves the shared protocol. · `src/guest/src/service/server.rs`
- [Guest containers](https://github.com/boxlite-ai/boxlite/blob/main/src/guest/src/container/mod.rs): OCI execution · Manages container lifecycle and commands. · `src/guest/src/container/mod.rs`

### Developer Surfaces

- [CLI](https://github.com/boxlite-ai/boxlite/blob/main/src/cli/src/main.rs): Rust binary · Dispatches local or remote lifecycle, exec, image, file, and auth operations. · `src/cli/src/main.rs`
- [Standalone REST server](https://github.com/boxlite-ai/boxlite/blob/main/src/cli/src/commands/serve/handlers/mod.rs): HTTP/WebSocket handlers · Maps server-mode requests to runtime actions. · `src/cli/src/commands/serve/handlers/mod.rs`
- [Language SDKs](https://github.com/boxlite-ai/boxlite/blob/main/sdks/c/src/lib.rs): native bindings · Python, Node, Go, and C APIs expose the native runtime. · `sdks/c/src/lib.rs`

### Cloud Platform

- [Control-plane API](https://github.com/boxlite-ai/boxlite/blob/main/apps/api/src/main.ts): NestJS API · Owns desired state, jobs, runners, volumes, and adapters. · `apps/api/src/main.ts`
- [Identity and tenancy](https://github.com/boxlite-ai/boxlite/blob/main/apps/api/src/auth/auth.module.ts): auth guards · JWT/API-key and runner guards enforce organization and region boundaries. · `apps/api/src/auth/auth.module.ts`
- [Cloud data services](https://github.com/boxlite-ai/boxlite/blob/main/apps/api/src/box/runner-adapter/runnerAdapter.ts): state and messaging · PostgreSQL, Redis, Kafka, audit, telemetry, and object-service integrations. · `apps/api/src/box/runner-adapter/runnerAdapter.ts`
- [Fleet runner](https://github.com/boxlite-ai/boxlite/blob/main/apps/runner/cmd/runner/main.go): Go worker · Polls and executes scheduled workload operations. · `apps/runner/cmd/runner/main.go`
- [Runner BoxLite adapter](https://github.com/boxlite-ai/boxlite/blob/main/apps/runner/pkg/boxlite/client.go): local runtime client · Invokes BoxLite on runner hosts. · `apps/runner/pkg/boxlite/client.go`
- [Dashboard](https://github.com/boxlite-ai/boxlite/blob/main/apps/dashboard/src/main.tsx): React client · `apps/dashboard/src/main.tsx`
- [Generated API client](https://github.com/boxlite-ai/boxlite/blob/main/apps/libs/api-client/src/index.ts): TypeScript client · `apps/libs/api-client/src/index.ts`
- [Cloud deployment](https://github.com/boxlite-ai/boxlite/blob/main/apps/infra/sst.config.ts): AWS/Cloudflare infrastructure · Deploys platform services and observability components. · `apps/infra/sst.config.ts`

## Connections

- CLI → Runtime core: local commands
- Standalone REST server → Runtime core: runtime actions
- Language SDKs → Runtime core: native bindings
- Runtime core → Box lifecycle: lifecycle
- Box lifecycle → OCI image pipeline: prepare rootfs
- Box lifecycle → Persistent storage: preserve state
- Box lifecycle → Host isolation: sandbox VM
- Box lifecycle → VMM abstraction: launch VM
- VMM abstraction → libkrun backend: platform backend
- Box lifecycle → Network forwarding: configure forwarding
- VMM abstraction → Guest service: hosts guest
- Runtime core → Shared control protocol: control channel
- Shared control protocol → Guest service: serves
- Guest service → Guest containers: lifecycle and exec
- Dashboard → Generated API client: uses
- Generated API client → Control-plane API: control requests
- Control-plane API → Identity and tenancy: authorize and scope
- Control-plane API → Cloud data services: state, jobs, events
- Control-plane API → Fleet runner: desired state and jobs · Control-plane-to-compute scheduling boundary.
- Fleet runner → Runner BoxLite adapter: execute locally
- Runner BoxLite adapter → Runtime core: host workloads
- Cloud deployment → Control-plane API: deploys
- Cloud deployment → Fleet runner: deploys
