The Two-Layer Data Model
Beads’ core design provides a distributed, git-backed issue tracker with two synchronized layers:CLI Layer
All commands (bd create, bd list, bd update, bd close, etc.) interface directly with the database:
- Built with Cobra framework in
cmd/bd/ - All commands support
--jsonfor programmatic use - Direct database access (server mode or embedded mode)
- No special sync commands needed
Dolt Database
Storage backend at.beads/dolt/:
- Version-controlled SQL database with cell-level merge
- Server mode (multi-writer) or embedded mode (single-writer)
- Fast queries with indexes and foreign keys
- Stores issues, dependencies, labels, comments, events
- Automatic Dolt commits on every write
- Native push/pull to Dolt remotes
Remote Sync
Dolt remotes (DoltHub, S3, GCS, filesystem):- All collaborators share the same issue database
- Cell-level merge for automatic conflict resolution
- Protected branch support via separate sync branch
- No special sync server needed
Why This Design?
Dolt for Versioned SQL
Queries complete in milliseconds with full SQL support. Dolt adds native version control:- Every write automatically committed to Dolt history
- Complete audit trail
- Cell-level merge resolves conflicts automatically
Dolt for Distribution
- Native push/pull to Dolt remotes
- Issues travel with your code
- Offline work just works
- No special sync server needed
Import/Export for Portability
bd import and bd export support JSONL format for:
- Data migration
- Bootstrapping new clones
- Interoperability with other systems
Write Path
When you create or modify an issue:- Command executes:
bd create "New feature"writes to Dolt immediately - Dolt commit: Every write is automatically committed to Dolt history
- Sync: Use
bd dolt pushto share changes with Dolt remotes
Read Path
All queries run directly against the local Dolt database:- Query: Commands read from fast local Dolt database via SQL
- Sync: Use
bd dolt pullto fetch updates from Dolt remotes
Hash-Based Collision Prevention
The key insight enabling distributed operation: content-based hashing for deduplication.The Problem
Sequential IDs (bd-1, bd-2, bd-3) cause collisions when multiple agents create issues concurrently:
The Solution
Hash-based IDs derived from random UUIDs ensure uniqueness:How It Works
This eliminates the need for central coordination while ensuring all machines converge to the same state.
See
COLLISION_MATH.md for birthday paradox calculations on hash length vs collision probability.Server Architecture
Each workspace can run its own Dolt server for multi-writer access:- Server Mode
- Embedded Mode
Connects to
dolt sql-server for multi-writer, high-concurrency access:- PID file at
.beads/dolt/sql-server.pid - Logs at
.beads/dolt/sql-server.log - Protocol defined in
internal/rpc/protocol.go
Data Types
Core types defined ininternal/types/types.go:
| Type | Description | Key Fields |
|---|---|---|
| Issue | Work item | ID, Title, Description, Status, Priority, Type |
| Dependency | Relationship between issues | FromID, ToID, Type (blocks/related/parent-child/discovered-from) |
| Label | Tag/category | Name, Color, Description |
| Comment | Discussion thread | IssueID, Author, Content, Timestamp |
| Event | Audit trail entry | IssueID, Type, Data, Timestamp |
Issue Status Flow
- open: Ready to work on
- in_progress: Actively being worked on
- closed: Completed
- blocked: Has open blocking dependencies
- deferred: Postponed for later
Directory Structure
Key Code Paths
| Area | Files |
|---|---|
| CLI entry | cmd/bd/main.go |
| Storage interface | internal/storage/storage.go |
| Dolt implementation | internal/storage/dolt/ |
| RPC protocol | internal/rpc/protocol.go, server_*.go |
| Export logic | cmd/bd/export.go |
| Import logic | cmd/bd/import.go |
Related Documentation
Dependencies
Learn about dependency types and how they affect workflow
Workflows
Understand contributor, stealth, and maintainer modes
Memory
Persistent agent knowledge across sessions
Dolt Backend
Deep dive into Dolt configuration and features