Architecture
Overview
Briefcase AI is a layered system. The Python package you install (briefcase-ai) is the SDK surface — the @capture decorator, configuration, and pure-Python feature modules. Underneath, a PyO3 binding crate exposes a native extension module (briefcase._native) backed by a fast Rust core (~11K lines, the briefcase-core crate) that provides high-performance decision tracking, replay, drift, cost, sanitization, and SQLite storage.
graph TD
A[Python package: briefcase-ai] --> B[PyO3 bindings: briefcase._native]
B --> C[Rust core: briefcase-core]
C --> D[SQLite storage backend]
Rust Core (briefcase-core)
The core crate lives in crates/briefcase-core and exposes feature-gated modules:
models-DecisionSnapshot,Input,Output,ModelParameters, and related typesstorage- the SQLite storage backend (SqliteBackend)replay- the deterministic replay enginedrift- drift and consistency calculationcost- token-cost estimation and budget checkssanitization- PII detection and redaction
Feature flags (recording, async, storage, replay, drift, sanitize, otel, tokens, and others) control which modules compile. The Python extension is built with the full feature set.
PyO3 Bindings (briefcase._native)
The bindings/python crate (briefcase-python, library name briefcase_native) uses PyO3 and maturin to compile the Rust core into the briefcase._native extension module. The native-backed Python modules (briefcase.cost, briefcase.drift, briefcase.sanitize, briefcase.storage, briefcase.replay) import their classes from this extension.
Python Package (briefcase-ai)
The Python layer adds:
- the
@capturedecorator, which records a lightweight decision dict and ships it through an exporter - configuration via
setup(),init(), andBriefcaseConfig - pure-Python feature modules: validation, guardrails, RAG versioning, correlation, events, external-data tracking, routing, bitemporal primitives, and audit bundles
- an optional lakeFS integration (
briefcase.integrations.lakefs) — one bundled versioned-data source; others plug in through the generic VCS protocol
Capture and Replay Flow
The @capture decorator and the native runtime layer are separate paths. @capture records a dict and hands it to an exporter; persistence and replay use the native DecisionSnapshot objects directly.
sequenceDiagram
participant App
participant Capture as capture decorator
participant Exporter
App->>Capture: call function
Capture->>App: function result
Capture->>Exporter: export decision dict
sequenceDiagram
participant App
participant Storage as SqliteBackend
participant Replay as ReplayEngine
App->>Storage: save_decision(snapshot)
Storage-->>App: decision_id
App->>Replay: replay(decision_id, mode)
Replay->>Storage: load snapshot
Replay-->>App: ReplayResult