Architecture
Graft is a Go CLI that orchestrates three subsystems: the Docker lifecycle manager, the content-addressable storage (CAS) layer, and the state manager.System Diagram
Subsystems
Docker Lifecycle
Theinternal/docker package wraps the Docker Engine SDK. It handles:
- Container inspection (capturing image, env, ports, networks)
- Graceful stop and start
- Container removal and recreation with host bind mounts
- Smart lifecycle (only restart if container was originally running)
CAS Layer (DAG)
Theinternal/dag package contains three components:
| Component | File | Responsibility |
|---|---|---|
| Store | store.go | SQLite CRUD for commits, tree_entries, refs |
| Merkle | merkle.go | BLAKE3 hashing, leaf building, tree construction |
| Object | object.go | Blob pool (Put, Get, Has, Materialize) |
| Verify | verify.go | Branch integrity checking |
State Manager
Theinternal/state package manages config.json — the lightweight state file at ~/.graft/<project>/. It tracks:
- Schema version (for migration safety)
- Target container ID
- Active branch
- Project root path
- Operation mode (snapshot vs bind)
- Container configuration (image, env, ports, network)
- Branch metadata (name, path, size, timestamps)