Skip to main content
The API infrastructure is under active development. Some features described here are planned but not yet fully implemented. This document reflects both current implementation and planned architecture.
The API infrastructure provides a secure, unified entry point for all Spacedrive operations. It handles authentication, authorization, session management, and request routing across CLI, Tauri desktop app, and native applications.

Architecture Overview

All API requests flow through a common pipeline:
This design enforces security policies consistently while providing rich context to operations.

Session Management

Sessions encapsulate all request context, replacing simple parameter passing with structured metadata:
Sessions include: Authentication Info: Device or user credentials and authorization level. Library Context: Currently selected library for scoped operations. Permission Set: Granular permissions for the session. Request Metadata: Tracking information for auditing and debugging.

API Dispatcher

The dispatcher provides a unified interface for all operations:
The dispatcher automatically:
  • Validates session permissions
  • Ensures library context for library operations
  • Tracks request metadata
  • Converts errors to API errors

Permission System

Permissions control access to specific operations:
Each category has granular permissions:

Permission Enforcement

Configure enforcement behavior:

Authorization Levels

Four hierarchical levels provide increasing access: None: No authentication required (public operations only). Device: Authenticated device with basic permissions. User: Authenticated user with full library access. Admin: System administrator with all permissions. Higher levels inherit permissions from lower levels.

Error Handling

API errors provide structured information for clients:
Errors automatically map to HTTP status codes for REST endpoints.

Middleware Pipeline

Middleware pipeline is partially implemented. The infrastructure exists but middleware chaining is not yet active.
Cross-cutting concerns are handled through composable middleware:

Logging Middleware

Tracks all requests with timing information:

Metrics Middleware

Records operation metrics for monitoring:
  • Request count by operation
  • Response times (p50, p90, p99)
  • Error rates by type
  • Active request count

Request Sources

Track where API calls originate:
Tauri desktop app currently uses Other("tauri") or Internal. A dedicated Tauri variant is planned.
This enables source-specific behavior like CLI-friendly error messages.

API Discovery

API discovery is a planned feature, not yet implemented.
Applications will be able to query available operations:
This will power dynamic UI generation and permission checking.

Integration Examples

CLI Integration

Tauri Integration

The Tauri desktop app integrates with the core through Rust FFI:
The Tauri app can run the daemon in two modes:
  • In-Process: Daemon runs within the Tauri app process
  • Background Process: Daemon runs as a separate system process (requires macOS entitlements)
See apps/tauri/DAEMON_SETUP.md for configuration details.

Swift Integration

Security Best Practices

Always use strict permissions in production: Development warnings help identify missing permissions during development. Validate library context: Library operations must have current_library_id set in the session. Track request metadata: Use request IDs for debugging distributed operations. Handle errors appropriately: Convert internal errors to user-friendly messages at the boundary.

Future Enhancements

Planned improvements include: User Authentication: OAuth and session token support. Rate Limiting: Per-user and per-operation limits. Request Caching: Smart caching for read operations. WebSocket Support: Real-time operation subscriptions.
The API infrastructure is designed to be transport-agnostic. While examples show Rust usage, the same patterns apply to REST endpoints and FFI boundaries.