Skip to main content

Module sync

Module sync 

Source
Expand description

Data Synchronization Abstraction Layer

This module provides a unified interface for CRDT-based data synchronization, enabling Peat Protocol to work with multiple sync engines without changing business logic.

§Architecture

The abstraction consists of four core traits:

  1. DocumentStore - CRUD operations, queries, and live observers
  2. PeerDiscovery - Finding and connecting to other nodes
  3. SyncEngine - Controlling synchronization behavior
  4. DataSyncBackend - Lifecycle management and trait composition

§Supported Backends

  • Automerge + Iroh - Open-source CRDT with QUIC-based P2P transport

§Usage Example

use peat_protocol::sync::{DataSyncBackend, BackendConfig};
use peat_protocol::storage::AutomergeBackend;

// Create backend
let backend = AutomergeBackend::new();

// Initialize with config
let config = BackendConfig {
    app_id: "my-app".to_string(),
    persistence_dir: "/tmp/data".into(),
    // ...
};
backend.initialize(config).await?;

// Start peer discovery and sync
backend.peer_discovery().start().await?;
backend.sync_engine().start_sync().await?;

// Use document store
let doc_store = backend.document_store();
let doc = Document::new(fields);
doc_store.upsert("collection", doc).await?;

// Cleanup
backend.shutdown().await?;

§Testing

The abstraction enables testing without real backends:

use peat_protocol::sync::mock::MockBackend;

let backend = MockBackend::new();
// Test Peat protocol logic with mock backend

§Design Rationale

See ADR-005 for full context on why this abstraction exists:

  • Eliminate vendor lock-in with proprietary sync engines
  • Enable open-source alternatives for DoD/NATO deployments
  • Support multiple sync strategies (Ditto, Automerge, custom)
  • Simplify testing (mocks, no real Ditto instances needed)

Re-exports§

pub use traits::*;
pub use types::*;

Modules§

automerge
Automerge-based implementation of DataSyncBackend
traits
Re-exported from peat-mesh. See peat_mesh::sync::traits.
types
Re-exported from peat-mesh. See peat_mesh::sync::types.