kanban-persistence
Persistence trait layer for the kanban workspace. Pure trait definitions — all I/O lives in the backend crates. Defines the interfaces implemented by kanban-persistence-json and kanban-persistence-sqlite, plus shared serialization types used across all persistence crates.
Traits
PersistenceStore
savetakes aStoreSnapshotand returns the persistedPersistenceMetadata. Implementations must guarantee an atomic write — either the full snapshot is written or the store is left unchanged.loadreturns the current snapshot and its associated metadata. Returns an error if the store has never been saved.existsreturnstrueif the backing store has been written at least once.pathreturns the file path or backing location.instance_idis a stableUuidthat identifies this store handle across saves. Used for conflict detection between concurrent writers.
StoreFactory
Backend plugins implement StoreFactory and register themselves with StoreRegistry.
namereturns the canonical backend identifier used in CLI--backendflags andStoreRegistry::create_storelookups (e.g."json","sqlite").matches_contentreceives the first 32 bytes of an existing file. Returntrueif those bytes indicate your format. Used for automatic backend detection when no explicit backend is specified. Defaults tofalse.createinstantiates aPersistenceStorefor the given locator (file path or connection string).
StoreRegistry
The registry holds a prioritized list of StoreFactory implementations.
registerappends a factory. Registration order matters:detect_backendreturns the first factory whosematches_contentreturnstrue.detect_backendreads the first 32 bytes of an existing file and returns the name of the matching factory, orNoneif no factory claims it.create_storelooks up the factory bynameand callsfactory.create(locator).
ChangeDetector trait
Provides file-watching capability for detecting external changes.
Serializer<T> trait
MigrationStrategy trait
Shared Types
StoreSnapshot
PersistenceMetadata
FormatVersion
Current shipped version is V6 (introduced by KAN-504): splits the dependency
graph from a single edge-type-tagged list into three typed sub-graphs
(parent_child, blocks, relates) keyed by relation kind. The JSON
backend chains V1→V2→V3→V4→V5→V6 migrations on load; the SQLite backend
ships the per-kind tables directly. See kanban-persistence-json's
migration/split_graph.rs for the JSON V6 transform.
PersistenceError
Helper Functions
;
;
Used by backends and the service layer to serialize/deserialize the domain Snapshot.
Writing a Third-Party Backend
This section walks through implementing a custom storage backend and plugging it into the CLI or MCP server without forking the repo.
Step 1 — Add dependencies
In your crate's Cargo.toml:
[]
= { = "0.3", = ["json", "sqlite"] } # or kanban-mcp
= { = "0.3" }
= "0.1"
= { = "1", = ["full"] }
= { = "1", = ["v4"] }
[]
= { = "0.3", = ["test-helpers"] }
= { = "0.3", = ["test-helpers"] }
= "3"
= { = "1", = ["full"] }
Step 2 — Implement PersistenceStore
use async_trait;
use ;
use ;
use Uuid;
Step 3 — Implement StoreFactory
use ;
use Arc;
;
Step 4 — Validate with the contract test suite
Add a test file (e.g. tests/contract.rs) to your crate:
Run with:
All 8 Tier 1 tests must pass before the backend is usable. Tier 2 tests verify the full service layer works on top of your store.
Step 5 — Own main() and register your backend
CLI binary
use CliApp;
async
MCP server binary
use McpServer;
async
Both builders accept any number of .register_backend() calls. Factories registered before the built-in ones take priority in content-sniffing; factories registered after are checked last.
To ship a binary with only your backend (no built-in JSON or SQLite), use CliApp::default() / McpServer::default() and register exclusively your factory:
default
.register_backend
.run
.await
Dependencies
| Crate | Purpose |
|---|---|
kanban-core |
KanbanError, KanbanResult |
kanban-domain |
Snapshot type |
serde + serde_json |
Serialization |
async-trait |
Async trait methods |
chrono |
Timestamps in metadata |
thiserror |
Error derivation |
uuid |
Instance IDs |