Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

Source: this chapter rests on the library survey (survey/library.md, the crate map and re-export surface at checkout 1ccb4a19457), the CLI survey (survey/cli.md, the command and feature-gate surface), and the web and configuration survey (survey/web-config.md, the web, Worker and MCP surfaces). The design-record survey (survey/design-records.md) is the source for which parts of the older documents are stale.

One workspace, one public surface

The system lives in pkgs/id/ in the developing-today/code repository. The root Cargo.toml is two things at once: the package id at version 0.1.0 (edition 2024, rust-version 1.96) and the workspace root. The workspace has 17 members: the root package plus 16 crates under pkgs/id/crates/. Default members are 15: the root plus 14 crates. id-native-shell and id-hw-shell are members but not default members, so a plain cargo build in pkgs/id/ never acquires the Bevy desktop dependencies or the hardware-shell code.

Library consumers use one public surface: the root crate, imported as id::. The split crates are internal. A consumer who names a split crate directly uses an internal path, with two recorded exceptions: id-config, id-currency-registry, id-render and id-import-notion are not exposed at id:: at all, so a consumer who wants them names those crates directly (library survey §2).

The facade is not a re-export shim. pkgs/id/src/ owns 26 modules of first-party code, including backup, conversion, currency, device_bridge, didit, encryption, fileops, grant_service, grants, groups, hosted_binding, hosted_export, hosted_ingest, references and serve_proxy. Several facade modules sit at historical paths over code that now lives in a split crate: src/groups/mod.rs re-exports from id-events, id-groups and id-worlds; src/fileops.rs, src/store_traits.rs, src/envelope_net.rs, src/envelope_outbox.rs, src/blob_gate.rs and src/pull_policy.rs do the same over id-store, id-sync, id-groups, id-events and id-worlds. The facade header in src/lib.rs also carries the family-wide signing contract from design #6487: sign only what receipt would accept, with four decidability classes (a) intrinsic, (b) signer-relative, (c) seam-extended, (d) receiver-state.

The split history is recorded in the crate doc headers. The code was one crate and was split under umbrella #3447: Phase 1 id-core (#3447), step 1 id-caps (#4403), steps 2a/2b id-store and id-events (#4405), step 3 id-sync (#4406), step 4 id-groups (#4407), step 5 id-worlds (#4408), steps 6b/6c id-directory and id-web (#4409), step 7b id-cli (#4411). Four crates are not split products: id-config (slice 9111-01, #10178), id-currency-registry (F1/F2 of #2062, #2317/#2318), id-render (#7918) and id-import-notion (slice 1, #8419), plus the two shells.

The crate map

Dependency direction is one-way. id-core depends on nothing in the workspace and everything depends on it. The full production edge list, from the library survey §0:

CrateOwnsDepends on
id-coreFoundation leaves: hashes, frames, tuple encoding, canonical CBOR, discovery, membership, signed envelopes, the graph record modelnothing
id-capsCapability catalog, execution limits, the declarative world manifestid-core
id-storeBlob store, the signed event-header chain, documents, tags, tag claims, searchid-core
id-eventsEvent store, group projection and fold, writer sets, sync gatingid-core, id-store
id-groupsGroup policy and enforcement remainder: blob gate, group encryption, group actions and logid-core, id-events, id-store
id-syncLog sync, the meta protocol wire half, file operations, envelopes, signed artifacts, transfer, federationid-core, id-events, id-store
id-directoryHome-server directory, views, auth, mail, invites, seitan admission, keysets and recoveryid-caps, id-core, id-events, id-sync
id-worldsWorld runtime, sessions, the wasmtime sandbox, the shell contract, program bundles and galleryid-caps, id-core, id-directory, id-events, id-groups, id-store, id-sync
id-webHTTP and WebSocket server, routes, templates, markdown, collaborative editingid-caps, id-core, id-directory, id-events, id-groups, id-store, id-sync, id-worlds
id-cliThe application layer: argument parsing, subcommand implementations, the REPL, server configid-caps, id-core, id-directory, id-events, id-groups, id-store, id-sync, id-worlds, optional id-web
id (facade)The public surface, the id binary entry point, and the 26 facade-owned modulesid-caps, id-cli, id-core, id-currency-registry, id-directory, id-events, id-groups, id-store, id-sync, id-worlds, optional id-web
id-configThe versioned configuration contract: the V2 ConfigDocument, hard invariants, the deterministic resolvernothing; no production crate depends on it
id-currency-registryCurrency control-plane registry: the ledger-u32 allocator, currency and account recordsnothing
id-renderRendering pipeline compiler core: parse, validate, compose, lower, emitnothing; no dependents
id-import-notionNotion importer manifest and inventory primitivesnothing; no dependents
id-native-shellBevy native reference shell for the shell contractthe facade, with features ["world"]
id-hw-shellESP32-class hardware shell spike: presence, journal head, confirm/actthe facade, with features ["world"]

Three boundary facts follow from the map. First, the group model lives in id-events, not in id-groups: model, fold, policy, friendship and writer-set vocabulary are id-events property, and id-groups is the enforcement remainder over it (library survey §1.9). Second, id-directory never depends on id-worlds; the edge runs the other way, because WorldCore in id-worlds holds a directory::Directory as persisted state (library survey §1.7). Third, id-config has no production dependent: the facade names it only under [dev-dependencies], for its invariant tests. The configuration contract is a test-enforced contract, not a runtime dependency. The design history of the split is carried in Design: foundations — objects, graph and the file core.

Feature gates cut across the map. The facade default is default = ["sandbox", "world"]. The web feature adds the optional id-web dependency. The ssh feature forwards to id-worlds/ssh and id-cli/ssh. The dht feature forwards to id-sync/dht and id-cli/dht. The Nix packages are id-web (features web, sandbox, ssh, world) and id-lib (features sandbox, world; no web, no ssh). The per-command consequences are in The id command line.

The surfaces

The CLI is the primary surface. Two binaries ship: id (root package, pkgs/id/src/main.rs, parser in id-cli) and id-native-shell (its own crate, hand-rolled argument parser, no clap). The id parser defines 32 top-level commands and 113 leaf commands. Running id with no subcommand starts the REPL. Full detail is in The id command line.

The REPL is a second parser, not a skin over clap. A line is whitespace-split and matched against literal patterns in crates/id-cli/src/repl/runner.rs. It has commands the CLI does not have (delete, rename, copy, gethash as one word) and it lacks serve, world, group, doc, claim, key and keyset. Its input language adds heredocs, here-strings, the |> pipe-in operator and $(…) command substitution. See The interactive REPL.

The web surface is the id-web crate: an Axum server with embedded assets, ProseMirror collaborative editing over WebSockets, a world session bridge at /ws/world, a program gallery surface and a script-free directory explorer at /explore. The main router has 54 distinct paths and 58 method bindings; the program-only router has 10 paths. Every router passes through one security layer: loopback bind by default (--bind default 127.0.0.1), a Host allow-list on loopback binds, a same-origin check on requests carrying Origin, and an optional gate token from --web-token or ID_WEB_TOKEN. See The web UI: pages and HTTP API.

The hosted Worker is a scaffold, not a deployed service. pkgs/id/hosted-worker/ carries a wrangler.toml whose header states it is local only, with no account-level deployment authorized, gated on #2285 and #3403. Locally, the app worker fails closed with 503 jurisdiction_unavailable for every fully valid request, by design, because local workerd does not implement jurisdiction restrictions. pkgs/id/worker-poc/ is a proof of concept for #2271: one example world running unmodified in a Worker isolate, with journal equality against the native wasmtime host as its acceptance test. Neither package is a production path. The design for a deployed edition is in Design: hosted and serverless editions, and the scaffold’s routes are in The hosted Worker API.

The shells are clients of one contract. The shell contract of record is pkgs/id/contract/shell-contract.v1.json: contract id-shell, version 1, revision 15, ALPN /id-world/1. Four shells are named in its conformance suite: terminal, browser, native and hardware. The native shell is the Bevy crate id-native-shell; the hardware shell is the single-file crate id-hw-shell (996 lines, no submodules). Both consume the facade as library consumers, with default-features = false, features = ["world"]. See Shells: terminal, web, native and hardware and Worlds and the Roc guest runtime.

The MCP bridge is a library surface, not a server. No standalone MCP server binary, no stdio or HTTP MCP transport and no JSON-RPC tools/list implementation exists in pkgs/id. id_caps::mcp_bridge translates one MCP tool call into a shell-contract client frame, and id_caps::mcp_policy is the host-side policy point. See Agents in worlds: the MCP bridge and policy.

Data flow of a file

A file enters through FileOps, the single put/rename/copy/delete implementation in id-sync that the CLI, the REPL, the meta protocol and the web layer all call (web-config survey §5.4). FileOps writes the bytes into the blob store: iroh-blobs FsStore in .iroh-store/, or an in-memory store under id serve --ephemeral. The blob is immutable and content-addressed; its hash is its identity. FileOps then binds a name to the hash. A name is an iroh-blobs tag pointing at the hash, and metadata tags for the name live in the tag store. The model is stated in The file core: content addressing, names and tags.

Reads run local or remote through one chooser. MetaClient in id-cli (an enum at crates/id-cli/src/meta_client.rs:31) picks between a running serve process and the in-process local node. The serve lock file .iroh-serve.lock in the data directory is the signal that a local serve is running. On the wire, the meta protocol ALPN is /iroh-meta/3 (META_ALPN = b"/iroh-meta/3" in id-sync). For remote file commands, a first positional argument of 64 hex characters is consumed as the remote node ID and the rest of the command operates on that node. Server-to-server copy (id send) moves no bytes through the client: the source server pushes with its own identity. Replication and transfer rules are in Sync, replication and FileOps.

Data flow of a world

A world exists only on a host. id serve --world is the only hosting command; every id world subcommand is a client (the F13.8 boundary, stated in the serve long help and the world command docs). The host loads a guest program: a precompiled Wasm module from --world-module, a Roc source install, or a module installed by a client with the admin token. Guests are import-free Wasm modules. The host runner is id_worlds::sandbox::{Sandbox, WorldInstance} on wasmtime: Sandbox::compile(wasm, SandboxLimits), then Sandbox::instantiate(seed).

Inside the host, the flow is a loop over a journal. A client shell sends an input frame under the shell contract. The host appends the input to the world journal and calls the guest update. The guest returns its new model plus a wants document naming capability requests. The host resolves each request against the capability catalog, the world’s grants and the server ceiling, and answers with a participant-0 event fed back through update. Host events are journaled, so replay feeds the same events back and reaches the same state. The host renders view and sends view frames to every connected shell. Checkpoints come from the guest snapshot function; id serve --world-checkpoint-every defaults to 1000, and 0 never trims. The runtime contract is in Worlds and the Roc guest runtime; the enforcement point for capability requests is in Capabilities, ceilings and providers.

Where the older documents disagree

Two disagreements matter for a reader of this chapter. LIB-13 and DES-1: the root Cargo.toml description, the src/lib.rs title and the README lead all describe a peer-to-peer file sharing CLI. The compiled surface also includes the world runtime, the directory, group encryption, the currency registry and the rendering compiler. The file-sharing description covers the file core and none of the platform layers. LIB-3: the facade’s own doc header still presents the pre-split single-crate module list and shows no worlds, sync, events, directory or currency layer. The crate map in this chapter follows the code at 1ccb4a19457, not either document.