ADR 22: Drive Lexicon and Persistence
Status: Accepted Date: 2026-05-01
Context
In Substratum, a Drive is the user-scoped storage root (see ADR 16). Initially, drives were hardcoded in the gateway for the MVP. To support user-created drives and maintain the "sovereign metadata" principle, we need a way to:
- Define a canonical schema for drive metadata using AT Protocol lexicons.
- Persist this metadata in a way that is both queryable (for the UI) and verifiable (via content-addressing).
- Support the creation of empty folders (directories) within these drives.
Decision
We have implemented the following architectural changes:
1. Drive Lexicon
A new lexicon type DriveMetadata is added to substratum_lexicons. This record contains:
version: Lexicon version (e.g.,1.0.0).id: The deterministic drive UUID.owner_did: The DID of the drive owner.name: The display name of the drive.created_at: ISO 8601 timestamp.updated_at: ISO 8601 timestamp.access_control: List of DIDs with access to the drive.receipt_cid: Optional CID of the latest sharing receipt.description: Optional drive description.
2. Dual Persistence Strategy
When a drive is created via POST /api/v1/drives:
- Content-Addressed Storage (Swarm): The
DriveMetadatarecord is serialized and stored in the retrieval swarm. This ensures the metadata is immutable and verifiable. - Relational Database (PostgreSQL): The drive metadata is also persisted in the
drivetable. This allows for efficient listing and filtering using native Postgres features like Row-Level Security (RLS).
3. Drive Listing and Sharing
- Listing: The
GET /api/v1/drivesendpoint queries the database usingsubstratum_resolution::rls::list_drives_for_current_did. This ensures that users only see drives they own or have access to. - Sharing: Drives are sharable via
PATCH /api/v1/drives/{drive_id}/nodes/access_controlwith an empty path. This updates theaccess_controlandreceipt_cidfields in thedrivetable and stores aReceiptlexicon in the swarm.
4. Directory Creation and Path Handling
- Directory Creation: A new endpoint
POST /api/v1/drives/{drive_id}/directoriesallows creating empty folders, persisted asdrive_entryrows withis_directory: true. - Root Path Handling: Path sanitization logic has been updated to support empty strings, representing the drive root, enabling sharing and other operations on the drive itself.
Consequences
- Positive:
- Drives are now user-creatable and persistent across sessions.
- Metadata is verifiable via CIDs while remaining efficiently queryable via SQL.
- Native RLS ensures strict multi-tenant isolation for drive listings.
- Support for empty directories improves the user experience in the file explorer.
- Negative:
- Increased complexity in the drive creation flow (dual-write to swarm and DB).
- Requires careful synchronization if drive metadata (like the name) is updated in the future.