# Live Sync Module
`live_sync.rs` (905 lines) — bidirectional file synchronization between a local folder and Proton Drive.
## Architecture: Bidirectional Sync
graph TB
subgraph "Local"
FS[Filesystem
Sync Folder]
WATCHER[notify Watcher
inotify/kqueue]
end
subgraph "Remote"
PROTON[Proton Drive API]
end
subgraph "LiveSyncManager"
EVENTS[Local Events]
POLLER[Remote Poller
30s interval]
SUPPRESS[Suppression Cache
30s TTL]
BRIDGE[Sync Bridge
Tauri IPC]
end
FS --> WATCHER
WATCHER --> EVENTS
EVENTS --> SUPPRESS
SUPPRESS --> BRIDGE
BRIDGE --> PROTON
PROTON --> POLLER
POLLER --> SUPPRESS
SDB[(sync_db.rs
SQLite)]
EVENTS --> SDB
POLLER --> SDB
## How It Works
### Local → Remote
1. `notify::RecommendedWatcher` monitors the sync folder for filesystem events (create, modify, delete)
2. Events are deduplicated via a suppression cache with a 30-second TTL (max 4096 entries)
3. Changes are serialized as `LiveSyncEvent` and emitted to the WebView frontend via Tauri IPC
4. The frontend uploads changed files through Proton's API
### Remote → Local
1. A background poller thread runs at a configurable interval (default: 30 seconds)
2. Polls the Proton API for remote changes via `RemoteSyncChange` structs
3. `RemoteSyncChange` contains: `relative_path`, `action` (string), and optional `content_base64`
4. Remote changes are applied to the local filesystem
### Sync Database Integration
Every change (local or remote) updates the `sync_db` SQLite database. On restart, the sync manager reads persisted state from `sync_db` to resume without re-scanning.
## Key Structures
| Struct | Purpose |
|---|---|
| `LiveSyncManager` | Core manager: watcher, poller, worker threads, known-files cache |
| `LiveSyncEvent` | Serialized event emitted to WebView: `kind`, `paths`, `root_path`, `source` |
| `LiveSyncStatus` | Status snapshot: `enabled`, `folder_path`, `poll_interval_seconds` |
| `RemoteSyncChange` | Incoming remote change: `relative_path`, `action`, `content_base64` |
## Suppression Logic
The suppression cache prevents echo loops: when remote changes are applied to disk, the local watcher would detect them as "new" changes. The 30-second TTL suppression window catches these echoes before they loop back to the server.