Expand description
batpak: Event Sourcing Runtime with DAG Causation Tracking.
Batpak provides a complete event sourcing platform with:
- Event Sourcing: Immutable event log with hash chain integrity
- DAG Causation: Tracks causation relationships between events
- Gate Evaluation: Pluggable policy enforcement before event commitment
- Persistent Storage: Segment-based append-only store with fast querying
The core pattern: acquire a Proposal, evaluate it through
Gate instances, then commit to
the Store.
use batpak::prelude::*;
let store = Store::open(StoreConfig::new("./my-store"))?;
let gates: GateSet<()> = GateSet::new();
let pipeline = Pipeline::new(gates);
let coord = Coordinate::new("entity:1", "scope:test")?;
let kind = EventKind::custom(0xF, 1);
let payload = serde_json::json!({"hello": "world"});
let proposal = Proposal::new(payload.clone());
let receipt = pipeline.evaluate(&(), proposal)?;
let committed = pipeline.commit(receipt, |p| -> Result<_, StoreError> {
let r = store.append(&coord, kind, &p)?;
Ok(Committed { payload: p, event_id: r.event_id, sequence: r.sequence, hash: [0u8; 32] })
})?;Reading order:
coordinate: Identify entities and scopesevent: Structure your eventsguard: Build policy gatespipeline: Propose and commitstore: Persist and query
Modules§
- coordinate
- Entity and scope addressing for events.
- event
- Event types, headers, and sourcing traits.
- guard
- Policy gate evaluation before event commitment.
- id
- UUID v7 identifier generation.
- outcome
- Result-like type for pipeline operations.
- pipeline
- Propose-evaluate-commit workflow.
- prelude
- Common re-exports for convenient use.
- store
- Persistent event storage and querying.
- typestate
- Compile-time state machine transitions.
- wire
- Module declarations in DEPENDENCY ORDER: wire → coordinate → outcome → event → guard → pipeline → store → typestate → id → prelude [SPEC:src/lib.rs — Module declarations in DEPENDENCY ORDER] Serde serialization helpers.
Macros§
- define_
entity_ id - define_entity_id!: Layer 1+ macro. Uses generate_v7_id() helper. Downstream crates do NOT need uuid as a direct dependency.
- define_
state_ machine - define_state_machine!: generates a sealed marker trait + zero-sized state structs. [SPEC:src/typestate/mod.rs — 99 LOC of macros]
- define_
typestate - define_typestate!: generates a PhantomData wrapper for typed state machines. [SPEC:src/typestate/mod.rs]