Overview
The event bus enables reactive UI updates by notifying clients when data changes. The system uses:- Generic Resource Events: A single event type (
ResourceChanged) handles all database entities - Path-Scoped Subscriptions: Subscribe to events affecting specific directories or files
- Infrastructure Events: Specialized events for jobs, sync, and system lifecycle
- Automatic Emission: Events are emitted automatically by the TransactionManager - no manual calls needed
Event Types
Resource Events
Generic events that work for ALL resources (files, tags, albums, locations, etc.):file- Files and directories (Entry entity)tag- User tagscollection- File collectionslocation- Indexed locationsdevice- Devices in the networkvolume- Storage volumes (replaces deprecated volume events)sidecar- Generated thumbnails and metadatauser_metadata- User-added metadata (notes, favorites, etc.)content_identity- Deduplicated content records
Volume events (
VolumeAdded, VolumeUpdated, etc.) and indexing events (IndexingStarted, IndexingProgress, etc.) are deprecated. Use ResourceChanged for volumes and job events for indexing progress.Infrastructure Events
Specialized events for system operations: Core Lifecycle:CoreStarted,CoreShutdown- Daemon lifecycle
LibraryCreated,LibraryOpened,LibraryClosed,LibraryDeletedRefresh- Invalidate all frontend caches
JobQueued,JobStarted,JobProgress,JobCompleted,JobFailed,JobCancelled
SyncStateChanged- Sync state transitionsSyncActivity- Peer sync activitySyncConnectionChanged- Peer connectionsSyncError- Sync errors
ResourceChanged with resource_type: "volume"):
VolumeAdded,VolumeRemoved,VolumeUpdatedVolumeMountChanged,VolumeSpeedTested
IndexingStarted,IndexingProgress,IndexingCompleted,IndexingFailed
FsRawChange- Raw filesystem watcher events (before database resolution)
Event Emission
Automatic Emission (Recommended)
Events are emitted automatically when using the TransactionManager:ResourceChanged after successful commits, ensuring:
- ✅ Events always match database state
- ✅ No forgotten emissions
- ✅ Automatic sync log integration
Manual Emission (Infrastructure Only)
Only use manual emission for infrastructure events:Path-Scoped Subscriptions
Subscribe to events affecting specific directories or files:ResourceMetadata field includes affected_paths that indicate which directories/files changed:
- Physical paths: Match by device slug + path prefix
- Content IDs: Match by content identifier
- Cloud paths: Match by service + bucket + path
- Sidecar paths: Match by content ID
Client Integration
TypeScript (useNormalizedQuery)
TheuseNormalizedQuery hook automatically subscribes to resource events and updates the cache:
- Subscribes to
ResourceChangedevents matching the resource type - Deserializes the JSON resource using generated TypeScript types
- Updates the local cache
- Triggers React re-renders
Swift
CLI Event Monitoring
Monitor events in real-time using the CLI:-t, --event-type- Comma-separated event types (e.g.,ResourceChanged,JobProgress)-l, --library-id- Filter by library UUID-j, --job-id- Filter by job ID-d, --device-id- Filter by device UUID--timestamps- Show event timestamps-v, --verbose- Show full event JSON-p, --pretty- Pretty-print JSON output
Implementation Reference
Event enum:core/src/infra/event/mod.rs
core/src/infra/event/mod.rs
Benefits
Backend
- Zero Manual Emission: TransactionManager handles all resource events
- Type Safety: Events always match actual resources
- Centralized: Single point of emission prevents drift
- Scalable: Adding new resources requires no event code
Frontend
- Zero Boilerplate: One event handler for all resource types
- Type Registry: Automatic deserialization via generated types
- Path Scoping: Subscribe only to relevant directory changes
- Cache Integration:
useNormalizedQueryhandles subscriptions automatically
Developer Experience
- No Event Variants: ~40 variants eliminated → 3 generic events
- No Manual Calls: Never call
event_bus.emit()for resources - No Client Changes: Adding a 100th resource type = zero event handling updates
- CLI Debugging: Monitor events in real-time with filtering
Related Documentation
- Sync System: See sync.md for event emission during sync
- Normalized Cache: See normalized_cache.md for client-side event handling
- TransactionManager: See transactions.md for automatic event emission
