How It Works
Graft operates on database data files at the filesystem level. It never needs to understand SQL, table structures, or database internals.The Core Idea
Database engines store data in a structured directory on disk. For Postgres, this isPGDATA at /var/lib/postgresql/data/. Graft copies this directory faithfully, treating the entire state as a single unit that can be snapshotted, branched, and restored.
Storage Architecture
Host Filesystem
Branch data is stored on the host under~/.graft/<project>/:
Content-Addressable Storage
When you rungraft commit, Graft:
- Stops the container — Postgres must be at rest for a consistent snapshot
- Walks the branch directory — Every file is hashed with BLAKE3
- Stores blobs — Each file goes into
objects/<prefix2>/<hash62>keyed by its BLAKE3 digest - Builds a Merkle tree — Sorted leaves, pair-hashed up to a single root
- Inserts into SQLite — Commit record + tree entries + ref update
Merkle DAG
Each commit records:- A 7-character BLAKE3 commit hash
- The parent commit hash (forming a chain)
- The Merkle tree root (cryptographic fingerprint of every file)
- A verified flag
- A message and timestamp
Container Lifecycle
Bind Mount Mode
Graft manages the container lifecycle by recreating it with a host bind mount:Smart Lifecycle
Graft captures whether the container was running before any operation. If it was already stopped, the stop/start steps are skipped. This meansgraft commit on a stopped container is instant after the filesystem work completes.
Branch Operations
Checkout (New Branch)
Checkout (Existing Branch)
Rollback
Integrity Verification
On-Demand Verify
Verify Output
--verbose, per-file details are shown: