Architecture for contributors
A quick map of where everything lives in the codebase and how requests flow through it. For the full
design, see docs/spec.md.
Node services
Section titled “Node services”All Rust node services compile into one multi-call binary, anastrod (crates/anastrod/src/main.rs),
running as separate systemd units managed by machined:
| Service | Responsibility | Runs on | Code |
|---|---|---|---|
machined |
Owns UDP 7444 iroh endpoint and node API; persists signed config, renders /run/anastro, manages units, upgrades, backups, and unseal |
Every node | crates/anastrod/src/machined.rs, crates/api/src/node |
apid |
Cluster API, dwfs/1, inference gateway, embedded web UI; watches enrolled peers in Postgres |
Control plane (active-active) | crates/anastrod/src/apid.rs, crates/api/src/cluster, crates/api/src/auth |
schedd |
Machine placement, reconcilers, idle spin-down, workspace GC, repacking | Control plane (one leader via Postgres advisory lock) | crates/anastrod/src/schedd.rs, crates/scheduler, crates/dwfs-control |
secretd |
Holds cluster KEK in locked memory and serves encrypted secret store on local Unix socket | Control plane (with KEK) | crates/secretd |
keyd |
Built-in DWFS workspace key provider | Control plane (with filesystem on) | crates/keyd |
opd |
Resolves and saves 1Password secrets for apid |
Control plane (with 1Password on) | crates/integrations |
relay |
Private iroh relay for enrolled endpoints | Control plane (iroh.run_relay) |
crates/anastrod/src/relay.rs, crates/iroh-transport |
hostagent |
Runs Linux machines under Cloud Hypervisor | Workers (worker role) |
crates/hostagent |
dwfsd |
Mounts machine workspaces via FUSE | Workers (with filesystem on) | crates/dwfsd, crates/dwfs-engine, crates/dwfs-frontends |
anastro-agents |
Pi Durable sidecar (TypeScript) driving threads via Postgres leases | Control plane ([pidurable] on) |
agents/ |
Alongside anastrod, the image ships pinned third-party binaries: PostgreSQL (plus Patroni and
etcd in HA), WAL-G, Cloud Hypervisor, and virtiofsd. Inside every Linux microVM, anastro-guest
(crates/guest) runs as PID 1.
Request flows
Section titled “Request flows”anastroctl→ API: dials a node’s UDP 7444 iroh endpoint using the device key.machineddrops un-enrolled peers after the handshake, handlesanastro/node/1directly, and forwardsanastro/api/1streams over a Unix socket toapid(prefixing the peer endpoint ID). Each stream is one HTTP/1.1 connection intoapid’s axum router, where the auth gate resolves caller → org → project → Cedar before running against Postgres.- Browser → API:
anastroctl ui(and native apps) bind a random.localhostloopback port and proxy requests over iroh as your device—apidnever accepts browser cookies. - Control plane → machine:
apiddoesn’t hold an iroh endpoint. It asksmachinedover a local socket to dial the worker’shostagent(anastro/host/1), which forwards commands/terminals toanastro-guestovervsock. Workers also hold a persistentanastro/agent/1stream to the control plane, heartbeating status and receiving desired machine state. - Threads:
apiddispatches threads over loopback toanastro-agents, which calls back intoapidfor tools and routes model calls through the inference gateway. - Config updates:
anastroctl cluster applysigns per-node configs and pushes them tomachined, which verifies the signature, saves/var/lib/anastro-node/config.json, renders service configs, restarts only affected units, and reconciles every 10 seconds.
Node lifecycle
Section titled “Node lifecycle”Every node boots the same unconfigured Nix image (.#nixosConfigurations.node-<arch>.config.system.build.{image,installer,iso,release}).
Without a config, machined starts in maintenance mode, prints a ticket, and accepts a
self-signed initial config over the network (cluster apply --maintenance) or via an ANASTROCFG
disk (cluster config sign). Booted from the installer, it writes itself to node.install_disk,
seals /var to the TPM, and reboots keeping its key.
If required secrets are missing, the node stays sealed (node API only) until cluster unseal or
a control-plane peer supplies them. All subsequent updates must be signed by a key in the running
cluster.operator_keys.
The test and dev harnesses exercise every bootstrap path: single VM test installs over the
network, iso installs from CD-ROM, ha boots from ANASTROCFG disks, and local dev clusters
seed configs via ANASTRO_CONFIG_SEED.
Reading docs/spec.md
Section titled “Reading docs/spec.md”docs/spec.md covers both built
behavior and planned design. Most sections end with two short blocks:
- What’s built so far: ground truth for what exists today (often down to endpoints, migrations, and tests). Trust this over earlier design prose whenever they differ.
- Not yet: parts of the design not implemented yet.
When your PR changes what’s built, update those notes in the same commit—the user docs follow them.