Architecture
Devices operate across three layers:Identity Layer
Manages device configuration and cryptographic keys.- macOS:
~/Library/Application Support/com.spacedrive/device.json - Linux:
~/.config/spacedrive/device.json - Windows:
%APPDATA%/Spacedrive/device.json
Domain Layer
Provides the rich device model used throughout the application.The
devices table is the source of truth for sync state within a
library. It tracks which devices are online, when they were last seen, and
their sync watermarks.Device Slugs for Unified Addressing
Each device has a unique slug used in Spacedrive’s unified addressing scheme. The slug is a URL-safe identifier generated from the device name:Network Layer
Handles P2P connections and device pairing through Iroh.The network layer uses mDNS for local discovery and QUIC for encrypted
communication.
Device Pairing
Pairing establishes trust between devices using a cryptographic handshake.Pairing Flow
1
Generate Code
Device A generates a pairing code valid for 5 minutes.
2
Enter Code
Device B joins using the pairing code.
3
Establish Trust
Devices exchange cryptographic signatures and derive session keys for future communication.
Paired Device States
- Discovered: Found via mDNS but not paired
- Pairing: Authentication in progress
- Paired: Trusted and persisted
- Connected: Active P2P connection
- Disconnected: Paired but offline
Library Participation
After pairing, devices must register with libraries to enable sync.Registration Process
- Paired devices discover each other’s libraries
- User selects which libraries to join
- Device records are created in each library’s database
- Sync begins automatically
Device-Owned Data
Ownership flows through volumes. Each device owns its volumes, and volumes own the locations and entries on them:- Volumes: Physical drives attached to the device
- Locations: Filesystem paths on a volume
- Entries: Files and folders within those locations
See Library Sync for details on the ownership chain and portable volume handling.
Sync Participation
Spacedrive uses a leaderless sync model. All devices are peers with no central
authority.
devices table tracks device state within a library:
- Connection State:
is_online,last_seen_attrack real-time availability - Sync Enablement:
sync_enabledcontrols whether a device participates - Last Sync:
last_sync_atrecords when the device last synced
How Devices Participate in Sync
Devices sync data using two protocols based on ownership:- Device-owned data (volumes, locations, entries): Owner broadcasts state, peers apply. Entries inherit ownership through their volume’s device. Tracked via
last_state_watermark. - Shared resources (tags, collections): Any device can modify. Changes ordered via HLC. Tracked via
last_shared_watermark.
Sync State Management
Query sync-enabled devices in a library:Incremental Sync
When devices reconnect after being offline, they use watermarks to determine what data needs synchronization, avoiding full re-sync. Watermarks are tracked per-resource in sync.db. See Library Sync for implementation details.API Reference
List Paired Devices
Device Events
Devices emit events when their state changes:Platform Considerations
Mobile Devices
iOS and Android require special initialization:Device Types
- Desktop: Windows, Linux desktops
- Laptop: MacBooks, portable computers
- Mobile: iOS, Android devices
- Server: Headless installations
Security
Each device maintains:- Ed25519 key pair: Unique cryptographic identity
- Session keys: Derived after pairing for encrypted communication
- Trust levels: Verified (paired) or blocked
Troubleshooting
Pairing Issues
If devices won’t pair:- Verify both devices are on the same network
- Check firewall settings for mDNS (port 5353)
- Ensure pairing code hasn’t expired (5 minute timeout)
- Restart the application on both devices
Sync Not Working
If changes aren’t syncing between devices:- Confirm devices are paired (check paired device list)
- Verify both devices have joined the library
- Check
devices.is_onlinestatus in the library database - Verify
devices.sync_enabled = 1for both devices - Compare watermarks to check if sync is progressing
- Check network connectivity between devices
- Review sync status in the UI
Debug Commands
Implementation Details
Global Device ID Cache
For performance, the current device ID is cached globally:Device Registration Query
Watermarks for incremental sync are stored in sync.db, not the devices table. See Library Sync for watermark tracking details.
Connection State Management
The sync system subscribes to network connection events and updates thedevices table automatically:
devices table is the single source of truth - the network layer updates it, and the sync layer queries it to determine which peers to sync with.
You can also check real-time connection status via the DeviceRegistry:
Related Documentation
- Sync System - How devices synchronize data
- Libraries - Multi-device library management
- Networking - P2P connection details
