How automerge/automerge-repo works
Main Components
a. Core Layer:
• Automerge-repo (central component)
• Document handling system (DocHandle, DocSynchronizer)
• Repository management (Repo)
• Synchronization system (Synchronizer, CollectionSynchronizer)
b. Adapter Layers:
• Storage Adapters
• IndexedDB (browser storage)
• NodeFS (filesystem storage)
• Network Adapters
• WebSocket (client/server communication)
• MessageChannel (cross-tab communication)
• BroadcastChannel (tab-to-tab sync)
• Frontend Framework Adapters
• React Hooks
• Svelte Store
┌─ Application Layer ─────────────────────┐
• React/Svelte Applications │
• Framework Integration Layer ───────────┤
• React Hooks / Svelte Store │
• Core Layer ──────────────────────────┤
• Automerge Repo │
• ┌─────────────┐ ┌─────────────┐ │
• Doc Handling │ │Synchronizer │ │
• ┘ └─────────────┘ │
• Adapter Layer ────────────────────────┤
• ┌─────────┐ ┌─────────┐ ┌──────────┐ │
• Storage │ │Network │ │Frontend │ │
• Adapters │ │Adapters │ │Adapters │ │
• ┘ └─────────┘ └──────────┘ │
• ┘
Important Details
a. Core Functionality:
• Document synchronization flows
• CRDT operations
• Event dispatch system
b. Storage Layer:
• IndexedDB for browser storage
• NodeFS for server storage
• Abstract storage interface
c. Network Layer:
• WebSocket connections
• Cross-tab communication
• Peer-to-peer sync capabilities
d. Framework Integration:
• React hooks interface
• Svelte store implementation