Skip to main content
Spacedrive’s data model powers a Virtual Distributed File System (VDFS) that unifies files across all your devices. It enables instant organization, content deduplication, and powerful semantic search while maintaining performance at scale.

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::File structure represents several database models such as entities::entry, entities::content_identity, and entities::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.
The code examples in this document generally refer to the database entity models to accurately represent what is stored on disk. The domain models provide a convenient abstraction over this raw data.

SdPath

The SdPath enum is the universal addressing system for files across all storage backends:
This enum enables transparent operations across local filesystems, cloud storage, content-addressed files, and derivative data. The 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:
The addressing system uses:
  • 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
See Unified Addressing for complete details on URI formats and resolution.

Entry

The Entry 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)
This ensures files sync only after proper content identification, while allowing the UI to cache and track all entries from the moment they’re discovered.

Hierarchical Queries

A closure table enables efficient ancestor/descendant queries:
This structure allows instant queries like “find all files under this directory” without recursion.

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 verification

Deduplication

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 content

Semantic 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:
Examples:
  • Parent/Child: “Animals” → “Dogs” → “Puppies”
  • Synonyms: “Car” “Automobile”
  • Related: “Photography” “Camera”
Tag hierarchies use closure tables for efficient ancestor/descendant queries, similar to entries.

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
Volumes serve as the ownership anchor for entries. The 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

  1. SQL Queries - Direct database queries with JOINs and indexes
  2. Foreign Keys - Referential integrity enforced by database
  3. Unified Organization - Extension data can be tagged and searched
  4. 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:
Find duplicate files:

Performance Optimizations

  1. Closure Tables - O(1) hierarchical queries
  2. Directory Path Table - The full path for every directory is stored in a dedicated directory_paths table. 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.
  3. Aggregate Columns - Pre-computed size/count fields
  4. Deterministic UUIDs - Consistent references across devices
  5. Integer PKs - Fast local joins, UUIDs only for sync
The data model provides a foundation for powerful file management that scales from single devices to complex multi-device networks.