How muni-town/leaf works
Main Components
• Core API / SDK (src/index.ts and related utility functions): This is the heart of Leaf SDK that ties together CRDT functionality.
• Storage Abstraction Layer (src/storage folder): Contains multiple implementations for local persistence and retrieval. Notice the modules such as deno-fs, deno-kv, and indexed-db. This layer ensures that storage choices can be switched or extended.
• Synchronization Module (src/sync1 folder): Contains protocol definitions (proto.ts) plus WebSocket client and server implementations (ws-client.ts and ws-server.ts) to enable peer-to-peer or client-server synchronization using CRDTs.
• Framework / UI Integration Module: The svelte.ts file indicates integration with Svelte, which helps frontend applications easily bind to the SDK.
• Examples & Documentation: The examples folder and the docs folder (with typedoc configuration) demonstrate usage and provide API documentation. Although not runtime components, they are essential for understanding how to integrate and extend the system.
Out Relationships and Data Flows
• The Core API ties directly to:
• The Storage Abstraction Layer for handling local data persistence.
• The Synchronization Module for keeping state consistent across peers or over network boundaries.
• The Svelte integration layer that lets UI components react to state changes.
• In the synchronization part, the WebSocket client and server components communicate with each other to propagate CRDT state across instances.
• The Core API is the hub – all external application layers (e.g., Svelte-based UIs or other frontend components) interact with it.
Architectural Patterns and Key Design Principles
• Abstraction and Adapter Pattern: The multiple storage options (Deno’s filesystem, KV storage, IndexedDB) suggest an abstraction layer that can adapt to different backends. Represent this as interchangeable storage adapter components.
• Modular Design: Separate modules for storage, synchronization, and integration show a clear separation of concerns.
• Local-First Philosophy: Emphasize that the design is tailored for offline-first or local-first applications, and the synchronization module is built to reconcile changes in a distributed environment.
Relevant Technologies, Frameworks, and Tools
• Deno Ecosystem: With files like deno.lock and tsconfig files, it’s clear that the project is built on Deno.
• CRDT Tools: Although not explicitly detailed in the file names, the core purpose implies underlying CRDT operations.
• WebSocket for real-time communication (ws-client.ts, ws-server.ts).
• Svelte: The svelte.ts file indicates a tight coupling for UI integration.
• TypeDoc: The extensive docs folder pointing to typedoc configurations shows automated documentation generation.