Offline-first sync for every platform

Sequence numbers for speed. Merkle trees for correctness. Real-time bidirectional database sync over Phoenix channels.

app.ts
import { SyncClient } from 'synclib-sync';

const sync = new SyncClient({
  db,
  serverUrl: 'wss://api.example.com/socket',
  clientId: 'user-123',
  channels: [{
    topic: 'sync:user:user-123',
    role: 'bidirectional',
    tables: [{ name: 'todos' }],
  }],
});

await sync.initialize();
await sync.connect(authToken);

Start syncing in minutes

Initialize a sync client, connect, and your local database stays in sync automatically.

import { SyncClient } from 'synclib-sync';

const sync = new SyncClient({
  db,
  serverUrl: 'wss://api.example.com/socket',
  clientId: 'user-123',
  channels: [{
    topic: 'sync:user:user-123',
    role: 'bidirectional',
    tables: [{ name: 'todos' }],
  }],
});

await sync.initialize();
await sync.connect(authToken);
final sync = SyncClient(
  config: SyncClientConfig(
    db: db,
    serverUrl: 'wss://api.example.com/socket',
    clientId: 'user-123',
    channels: [
      SyncChannel(
        topic: 'sync:user:user-123',
        role: ChannelRole.bidirectional,
        tables: [SyncTable(name: 'todos')],
      ),
    ],
  ),
);

await sync.initialize();
await sync.connect(authToken);

Two-layer sync

Fast incremental updates and cryptographic correctness guarantees, working together.

Sequence numbers visualized as glowing hexagonal platforms filling in sequentially Layer 1

Sequence Numbers → Speed

  • Every local write gets a monotonically increasing sequence number
  • Sync only sends changes since the last acknowledged seqnum
  • Only new changes travel over the wire

Fast incremental sync

Merkle tree with glowing neon hash nodes Layer 2

Merkle Trees → Correctness

  • Periodic Merkle root comparison between client and server
  • Block-level hashes pinpoint exactly which rows drifted
  • Automatic repair fixes drift without full re-sync

Cryptographic consistency guarantee

Built for real apps

Everything you need to ship offline-capable, multi-platform applications.

Offline-First

Local SQLite database with automatic change tracking. Works without a connection, syncs when online.

Bidirectional Sync

Push, pull, or bidirectional per channel. Configure each channel's sync direction independently.

Schema Management

Server-driven schema migrations. Clients stay in sync with the latest database structure.

Multi-Platform

TypeScript/JavaScript for web and Node.js. Dart/Flutter for iOS, Android, and desktop.

Phoenix Channels

Built on Elixir's Phoenix framework for scalable, fault-tolerant real-time communication.

🔒

Access Control

JWT authentication on every connection. Server-side row filtering ensures no data crosses the wire unless the user is authorized to see it.

🎙

Beyond Database Sync

The same Phoenix channels carry any real-time data — livestreaming, live events, WebRTC signaling, chat, and custom app messages.

Extensible Protocol

Handle custom message types with hooks. Add app-specific events without forking the library.

Architecture

Clients sync with the server over persistent WebSocket connections.

Client
SQLite
←→
Phoenix Channel
WebSocket
←→
Server
PostgreSQL
1
Local writes tracked with sequence numbers
2
Changes pushed over WebSocket channel
3
Server applies and broadcasts to other clients
4
Merkle trees verify consistency periodically

Repositories

Open source, MIT licensed. Each library is independently usable.

Migrating from Firebase?

Keep your Firestore API calls — swap the backend to local SQLite with sync. Change one import and your existing code just works.

// Before:
import { getFirestore } from 'firebase/firestore';

// After:
import { FirebaseFirestore } from 'synclib-firestore';

// Your code stays the same:
const doc = await firestore.collection('todos').doc('abc').get();

Need help getting started?

synclib is fully open source and self-hostable. But if you'd rather not manage infrastructure yourself, we offer hosted sync backends and hands-on deployment support — from initial setup to production.

Managed Hosting

We run the sync server, PostgreSQL, and infrastructure for you. Connect your client apps and start syncing.

Deployment Support

We help you deploy synclib on your own infrastructure — cloud or on-prem — and stick around until it's running smoothly.

Contact us → contact@synclib.io