Concepts

Architecture

A control API, a copy-on-write clone per branch, and one engine process per branch — all on a server you run.

Client and server

The CLI is a thin client. It submits a command to the server as an authenticated job over HTTP, waits, and prints the result. Database files and engine processes live entirely on the server. Without ANYBRANCH_SERVER the client fails; it never falls back to a local copy.

On-disk layout

Everything lives under ANYBRANCH_HOME/<name>/ on the server:

engine       postgres | mysql | sqlite | mongodb
parent       optional — the branch this was cloned from
source       optional production URL (mode 0600) — makes this a synced root
data/        the engine data directory — this is what gets cloned
run/         ports, pids, sockets, logs, tailer state — never cloned

Copy-on-write branching

A branch is a clone of the parent’s data/ directory made with the platform’s file-clone primitive — clonefile on macOS/APFS, reflink on Linux (Btrfs, XFS, bcachefs). No bytes are copied until a page changes, so branch time and initial disk are independent of database size. Branching a running parent holds it, stops it, clones, and restarts it, because a per-file clone is only a consistent snapshot while nothing is writing.

Replica and branches

A synced root replicates from production using the engine’s own replication (Postgres logical replication, MySQL GTID, MongoDB change streams). Branches are always cut from the replica, never from production, so branch activity never touches your primary. A fresh branch inherits the parent’s replication config and is detached on first start — the subscription is removed and, for Postgres, sequences are advanced past the copied rows so inserts do not collide.

Ports and suspend

Every branch has a stable public port owned by a small in-process proxy, plus an engine port behind it. Idle branches stop their engine after ANYBRANCH_IDLE_MINUTES (default 5) and resume on the next connection — the URL never changes. Synced roots never suspend, because they must keep replicating.