Core Design
The system separates concerns into distinct entities:- SdPath - Address any file; local, peer device, cloud, or by content ID
- Entry - File and directory representation
- ContentIdentity - Unique file content for deduplication
- UserMetadata - Organization data (tags, notes, favorites)
- Location - Monitored directories
- Device - Individual machines in your network
- Volume - Real storage volumes, local, external and cloud
- Sidecar - Derivative and associated data
Domain vs. Database Entity Models
It is critical to understand the distinction between two data modeling layers in Spacedrive:- Domain Models: These are the rich objects used throughout the application’s business logic. They contain computed fields and methods that provide a powerful, high-level interface to the underlying data. For example, the
domain::Filestructure represents several database models such asentities::entry,entities::content_identity, andentities::user_metadata. - Database Entity Models: These are simpler structs that map directly to the database tables (e.g.,
entities::entry). They represent the raw, persisted state of the data and are optimized for storage and query performance.
SdPath
TheSdPath enum is the universal addressing system for files across all storage backends:
Physical variant handles traditional filesystem paths, Cloud manages cloud storage locations, Content enables deduplication-aware operations by referencing files by their content, and Sidecar addresses generated derivative data like thumbnails and embeddings.
Unified Addressing
Spacedrive displays paths using a unified addressing scheme that matches industry standards:- Device slugs for local paths (e.g.,
local://jamies-macbook/path) - Service-native URIs for cloud storage (e.g.,
s3://,gdrive://,onedrive://) - Content UUIDs for location-independent references
Entry
TheEntry is the core entity representing a file or directory. The database entity (entities::entry::Model) stores the fundamental hierarchy and metadata.
Expandable
Ownership via Volume
Entries inherit sync ownership from their volume, not directly from a device. When you plug a portable drive into a different machine, updating the volume’s device reference instantly transfers ownership of all entries on that volume. No bulk updates needed. This design enables portable storage to move seamlessly between devices while maintaining correct sync behavior.UUID Assignment
All entries receive UUIDs immediately during indexing for UI caching compatibility. However, sync readiness is determined separately:- Directories - Sync ready immediately (no content to identify)
- Empty files - Sync ready immediately (size = 0)
- Regular files - Sync ready only after content identification (content_id present)
Hierarchical Queries
A closure table enables efficient ancestor/descendant queries:ContentIdentity
ContentIdentity represents unique file content, enabling deduplication across your entire library:Expandable
Two-Stage Hashing
Content Hash - Fast sampling for deduplication Integrity Hash - Full file hash for verificationDeduplication
Multiple entries can point to the same ContentIdentity. When you have duplicate files, they all reference a single ContentIdentity record.UserMetadata
UserMetadata stores how you organize your files:Expandable
Metadata Scoping
UserMetadata can be scoped two ways: Entry-Scoped - Applies to a specific file instance Content-Scoped - Applies to all instances of the same contentSemantic Tags
Spacedrive uses a graph-based tagging system that understands context and relationships:Expandable
Polymorphic Naming
The same name can mean different things in different contexts:Tag Relationships
Tags form hierarchies and semantic networks:- Parent/Child: “Animals” → “Dogs” → “Puppies”
- Synonyms: “Car” “Automobile”
- Related: “Photography” “Camera”
Location
Locations are directories that Spacedrive monitors:Expandable
Index Modes
- Shallow - Metadata only (fast, no content hashing)
- Content - Metadata + deduplication
- Deep - Full analysis including media extraction
Device
Devices represent machines in your Spacedrive network:Expandable
Volume
Volumes track physical drives and partitions:Expandable
device_id field determines which device owns all entries on this volume. When a portable drive moves between machines, updating this single field transfers ownership of the entire volume’s contents. See Library Sync for details on portable volume handling.
Sidecar
Sidecars store generated content like thumbnails:Expandable
Sidecars link to ContentIdentity, not Entry. This means one thumbnail serves
all duplicate files.
Extension Models
Extensions create custom tables at runtime to store domain-specific data. These integrate seamlessly with core tagging and organization.The extension system is currently a work in progress. The API and
implementation details described here are subject to change.
Table Naming
Extension tables use prefixed naming:Model Definition
Extensions define models using SDK macros:Integration Benefits
- SQL Queries - Direct database queries with JOINs and indexes
- Foreign Keys - Referential integrity enforced by database
- Unified Organization - Extension data can be tagged and searched
- Type Safety - Compile-time schema validation
Sync Architecture
Device-Owned Resources
Entities: Device, Volume, Location, Entry Ownership flows through volumes. A device owns its volumes. Locations and entries reference a volume, inheriting ownership from the volume’s device. This indirection enables portable storage: when a drive moves between machines, updating the volume’s device reference transfers ownership of all associated entries instantly. Only the owning device can modify these resources. Last state wins.Shared Resources
Entities: Tag, UserMetadata, TagRelationship, ContentIdentity Any device can modify shared resources. Changes are ordered using Hybrid Logical Clocks for consistency across devices.Foreign Key Mapping
During sync, integer IDs map to UUIDs for wire format, then back to local IDs on receiving devices.Query Patterns
Find files with a specific tag:Performance Optimizations
- Closure Tables - O(1) hierarchical queries
- Directory Path Table - The full path for every directory is stored in a dedicated
directory_pathstable. This is the source of truth for directory paths and avoids storing redundant path information on every file entry, making path-based updates significantly more efficient. - Aggregate Columns - Pre-computed size/count fields
- Deterministic UUIDs - Consistent references across devices
- Integer PKs - Fast local joins, UUIDs only for sync
