# Architecture ## Workspace Karapace is a Cargo workspace of 9 crates. ``` karapace-schema Manifest parsing, normalization, lock file, identity hashing karapace-store Content-addressable object store, layers, metadata, WAL, GC karapace-runtime Container backends, image cache, security policy, prerequisites karapace-core Engine: orchestrates the full environment lifecycle karapace-cli CLI binary (23 commands, clap) karapace-dbus D-Bus service (org.karapace.Manager1, zbus) karapace-tui Terminal UI (ratatui, crossterm) karapace-remote Remote store client: HTTP backend, registry, push/pull karapace-server Reference HTTP server for remote store (tiny_http) ``` ## Dependency graph ``` karapace-cli ──┬──> karapace-core ──┬──> karapace-schema │ ├──> karapace-store │ ├──> karapace-runtime │ └──> karapace-remote ├──> karapace-runtime └──> karapace-store karapace-dbus ────> karapace-core karapace-tui ─────> karapace-core karapace-remote ──> karapace-store karapace-server ──> karapace-remote, karapace-store ``` ## Engine lifecycle `karapace-core::Engine` is the central orchestrator. All state transitions go through it. ``` ┌─────────┐ build() ───> │ Defined │ └────┬────┘ │ resolve → lock → build v ┌─────────┐ │ Built │ <── rebuild() └──┬──┬───┘ enter() │ │ │ freeze() v │ v ┌─────────┐ ┌─────────┐ │ Running │ │ Frozen │ └─────────┘ └────┬────┘ │ archive() v ┌──────────┐ │ Archived │ └──────────┘ ``` State transitions are validated in `karapace-core/src/lifecycle.rs`. Invalid transitions return `CoreError`. ### Build pipeline `Engine::build(manifest_path)` executes: 1. Parse manifest (`karapace-schema::parse_manifest_file`) 2. Normalize (`ManifestV1::normalize`) — sort packages, deduplicate, lowercase backend 3. Select runtime backend (`karapace-runtime::select_backend`) 4. Resolve — backend downloads base image, computes content digest, queries package manager for exact versions → `ResolutionResult` 5. Create lock file (`LockFile::from_resolved`) with pinned versions and content digest 6. Compute identity (`LockFile::compute_identity`) → `env_id` (blake3) 7. Store manifest as object, create layers, write metadata 8. Backend builds the environment filesystem 9. Write lock file to disk ### Identity computation Defined in `karapace-schema/src/lock.rs::LockFile::compute_identity()`. Input fed to blake3 in order: - `base_digest:` - `pkg:@` for each resolved package (sorted) - `app:` for each app (sorted) - `hw:gpu` / `hw:audio` if enabled - `mount: