Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Building on the sync engine

Every developer who builds a multi-device app ends up solving the same things: where to store data, who is allowed to change it, how to merge edits, how to get it to the other devices. The sync engine is a library so you don’t have to, and you can use it without running the Atomic app. You write against a local store, and identity, signing, permissions, history and sync come with it.

Coming from Supabase or Firebase? See Atomic vs Supabase and Firebase.

In the browser or Node: @tomic/lib

@tomic/lib runs the same Rust core as the app, compiled to WebAssembly, on top of OPFS in the browser.

  • Build a local-first app is the guided path: an identity, a local Drive, persistence, syncing to a server and a second device.
  • Point a store at a server with store.setServerUrl(url). Track progress with the StoreEvents.SyncStatusChanged event, which reports whether the server is connected and how many edits are still pending.
  • Store, Agent and Resource are the reference pages. resource.save() applies a change locally first and queues it for delivery.
  • @tomic/react and @tomic/svelte wrap the store in hooks and components.

In Rust: atomic_lib

atomic_lib provides the store, the signed commits and the sync engine. The transports are Cargo features: ws for WebSocket clients, iroh for peer-to-peer, discovery for the pkarr lookup. AtomicNode is a convenience facade with local saves that go to the outbox and commit ingestion policies. See atomic_lib and the crate README. The Flutter SDK wraps the same crate. See Flutter / Dart.

What the engine does not decide

The engine converges copies and enforces who may write. It can’t know what your data means. As the overview says, merging does not check business rules, so your app still decides:

  • what counts as the same record, and how rejected or ambiguous changes are reviewed;
  • key backup and recovery, since an identity is a key;
  • how to migrate data when your model changes.

See Choose transports and design for offline edits and Migrating from PostgreSQL.

If you need to speak the protocol yourself

The wire protocol documents every frame, and lib/src/sync/protocol_vectors.json holds golden vectors that the Rust and TypeScript encoders are tested against.