Skip to content

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.

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.

  • anastroctl → API: dials a node’s UDP 7444 iroh endpoint using the device key. machined drops un-enrolled peers after the handshake, handles anastro/node/1 directly, and forwards anastro/api/1 streams over a Unix socket to apid (prefixing the peer endpoint ID). Each stream is one HTTP/1.1 connection into apid’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 .localhost loopback port and proxy requests over iroh as your device—apid never accepts browser cookies.
  • Control plane → machine: apid doesn’t hold an iroh endpoint. It asks machined over a local socket to dial the worker’s hostagent (anastro/host/1), which forwards commands/terminals to anastro-guest over vsock. Workers also hold a persistent anastro/agent/1 stream to the control plane, heartbeating status and receiving desired machine state.
  • Threads: apid dispatches threads over loopback to anastro-agents, which calls back into apid for tools and routes model calls through the inference gateway.
  • Config updates: anastroctl cluster apply signs per-node configs and pushes them to machined, which verifies the signature, saves /var/lib/anastro-node/config.json, renders service configs, restarts only affected units, and reconciles every 10 seconds.

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.

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.