How haierkeys/obsidian-fast-note-sync works
Purpose and Runtime
Fast Note Sync is an Obsidian plugin that synchronizes a vault’s notes, attachments, and optionally configuration with a separately deployed Fast Note Sync Service. It targets Obsidian desktop/mobile and is written in TypeScript, bundled for plugin distribution.
Plugin metadata and build output contract are defined by manifest.json, package.json, and esbuild.config.mjs. The runtime entry point is src/main.ts.
Plugin Bootstrap and Obsidian Integration
src/main.ts owns the Obsidian plugin lifecycle: loading settings/runtime state, registering vault/event integrations, and wiring sync, UI, and service clients. It is the boundary between Obsidian APIs and the plugin’s internal synchronization system.
Settings are presented and persisted through src/setting.tsx, src/views/settings-view.tsx, and the local persistence layer in src/lib/storage/local_storage_manager.ts.
Sync Orchestration
The synchronization core is organized around operators that apply remote/local changes by resource type. src/lib/sync/operator.ts coordinates work; src/lib/sync/operator_file.ts, src/lib/sync/operator_folder.ts, and src/lib/sync/operator_note.ts handle file, directory, and note-specific operations.
src/lib/sync/sync_state.ts and src/lib/sync/runtime_config.ts maintain lifecycle and effective sync state. src/lib/sync/concurrency_limiter.ts constrains parallel operations, while src/lib/sync/lock_manager.ts prevents conflicting local/remote work.
Remote Service Protocols
The plugin communicates with the external Fast Note Sync Service over HTTP and WebSocket. REST-style requests are centralized in src/lib/api/http_api_service.ts. Real-time remote actions and connection lifecycle are handled by src/lib/sync/websocket_client.ts, src/lib/sync/websocket_manager.ts, and src/lib/sync/websocket_action.ts.
Protocol payloads use generated protobuf artifacts in src/pb/v1/sync.js and mapping logic in src/pb/protobuf_mapper.ts. This creates a clear transport boundary: sync operators consume mapped domain data rather than directly managing wire encoding.
Change Detection, Reconciliation, and Persistence
Local/remote reconciliation relies on durable comparison metadata: src/lib/storage/file_hash_manager.ts tracks file content identity, src/lib/storage/folder_snapshot_manager.ts captures directory state, and src/lib/storage/config_hash_manager.ts supports configuration synchronization.
src/lib/sync/config_manager.ts and src/lib/sync/operator_config.ts apply the separate configuration-sync path. These stores allow offline changes and deletions to be detected and reconciled after a connection returns.
User-Facing Sync Operations
Operational feedback is tracked by src/lib/sync/sync_progress_tracker.ts and persisted/displayed through src/lib/sync/sync_log_manager.ts and src/views/sync-log-view.tsx. Status and sharing affordances are integrated into Obsidian UI via src/lib/ui/status_bar_manager.ts, src/lib/ui/menu_manager.ts, and src/lib/ui/share_indicator_manager.ts.
Conflict and recovery workflows are explicit UI boundaries: src/views/conflict-list-modal.tsx, src/views/conflict-resolve-modal.ts, and src/views/recycle-bin-modal.ts. Historical version inspection/restoration is implemented under src/views/note-history/history-modal.tsx and src/views/note-history/history-detail.tsx.
Cloud Features and External Boundaries
Attachment cloud-preview behavior is represented by src/lib/storage/file_cloud_preview.ts; sharing flows are exposed through src/views/share-modal.ts and src/views/share-manage-modal.ts. The plugin depends on the separately deployed Fast Note Sync Service for authorization, synchronization, history, backup, sharing, and collaboration—not an in-repository backend.
Localization is runtime-facing and centralized in src/i18n/lang.ts with locale catalogs such as src/i18n/locales/en.ts and src/i18n/locales/zh-CN.ts.
Main entry points: operator.ts Sync operator · main.ts Plugin bootstrap · http_api_service.ts HTTP API client · setting.tsx Settings UI
Components 22
Plugin & Obsidian UI
- Obsidian APIs · Desktop/mobile vault and UI integration boundary.
- Plugin bootstrap · Owns lifecycle and wires plugin subsystems.
src/main.ts - Settings UI · Edits and persists plugin settings.
src/setting.tsx - Settings view
src/views/settings-view.tsx - Status, menus & sharing UI
src/lib/ui/status_bar_manager.ts - Conflict & recovery UI
src/views/conflict-list-modal.tsx - Note history UI
src/views/note-history/history-modal.tsx - Sync feedback UI
src/views/sync-log-view.tsx - Localization
src/i18n/lang.ts
Sync Engine
- Sync operator · Coordinates reconciliation and resource operations.
src/lib/sync/operator.ts - File, folder & note operators
src/lib/sync/operator_file.ts - Sync state & runtime config
src/lib/sync/sync_state.ts - Concurrency & locking · Limits parallel work and prevents conflicting operations.
src/lib/sync/concurrency_limiter.ts - Configuration sync
src/lib/sync/operator_config.ts - Progress & sync log
src/lib/sync/sync_progress_tracker.ts
Service Transport
- WebSocket sync channel · Manages remote actions and connection lifecycle.
src/lib/sync/websocket_manager.ts - HTTP API client
src/lib/api/http_api_service.ts - Protobuf mapping · Maps generated wire payloads to domain data.
src/pb/protobuf_mapper.ts - Fast Note Sync Service · Provides authorization, sync, history, backup, sharing, and collaboration.
State & Reconciliation
- Local settings storage
src/lib/storage/local_storage_manager.ts - Hash & snapshot metadata · Durable file, folder, and config comparison state.
src/lib/storage/file_hash_manager.ts - Attachment cloud preview
src/lib/storage/file_cloud_preview.ts
Connections 25
- Obsidian APIs → Plugin bootstrap: hosts
- Plugin bootstrap → Settings UI: opens
- Settings UI → Settings view: renders
- Settings UI → Local settings storage: persists
- Plugin bootstrap → Sync operator: starts sync
- Plugin bootstrap → Status, menus & sharing UI: registers
- Plugin bootstrap → Localization: loads
- Sync operator → Sync state & runtime config: updates
- Sync operator → File, folder & note operators: dispatches
- Sync operator → Concurrency & locking: coordinates through
- Sync operator → Configuration sync: runs
- Sync operator → Hash & snapshot metadata: compares against
- Sync operator → Progress & sync log: reports
- Progress & sync log → Sync feedback UI: displays in
- Sync operator → WebSocket sync channel: uses realtime sync
- File, folder & note operators → HTTP API client: uses requests
- Configuration sync → HTTP API client: syncs via
- HTTP API client → Protobuf mapping: maps payloads
- WebSocket sync channel → Protobuf mapping: maps actions
- HTTP API client → Fast Note Sync Service: HTTP
- WebSocket sync channel → Fast Note Sync Service: WebSocket
- Status, menus & sharing UI → Fast Note Sync Service: sharing flows
- Conflict & recovery UI → Sync operator: resolves through
- Note history UI → Fast Note Sync Service: inspects history
- Attachment cloud preview → Fast Note Sync Service: retrieves previews