Sync System Overview

The mental model behind Oalo's offline-first data sync, its core concepts, and how the TypeScript and Dart client libraries are layered.

How Oalo's data sync works, and the mental model a developer needs before reading sync-api-reference.md, sync-http-fallback.md, and sync-scopes.md.

The idea in one paragraph

Every app keeps a local SQLite database on the device and mirrors it to the server. Reads and writes hit the local database first, so the app is fast and works offline. Changes flow both ways: the client pushes local writes up and pulls server changes down. This is the offline-first spine that every Oalo app, dashboard, chatbot, and automation shares, so they all see one source of truth.

You never write networking, caching, or conflict code. The sync library does it.

Core concepts

  • Store. The local SQLite database (SynclibStore in TS, an opened db in Dart). Persisted (IndexedDB in the browser, a file on native) so data survives restarts.
  • Client. The object that connects to the server and runs the sync protocol.
  • Channel. A named subscription to a slice of server data, identified by a topic (for example sync:app:app_builder or sync:user:<id>). A channel lists the tables it syncs and a role (push, pull, or bidirectional).
  • Cursor / seqnum. Each synced row has a monotonic seqnum. The client remembers the highest seqnum it has seen per sync unit, so the next pull only asks for what is newer. Cursors are durable and shared across transports.
  • Transport. Normally a WebSocket. When the socket cannot be held the client falls back to plain HTTP. See sync-http-fallback.md.
  • Scope. An optional filter so a channel pulls only part of a table (one screen's worth) instead of the whole thing. See sync-scopes.md.

The library layering

There are two client stacks, one per language, and they are shaped differently. Getting this right saves confusion.

TypeScript (web + React Native)

@synclib-io/client   →  SynclibClient   ← the surface you hold
      wraps
@synclib-io/sync     →  SyncClient      (lower-level core)
@synclib-io/core                        (shared merkle + native bits)
@synclib-io/react    →  SynclibProvider, hooks  (React bindings)

You construct SynclibClient from @synclib-io/client. It dynamically imports and wraps the lower-level SyncClient. The transport fallback is built into the wrapper, so in TS it is transparent.

Current versions: @synclib-io/sync 0.7.1, @synclib-io/client 0.7.1, @synclib-io/react 0.5.0, @synclib-io/core 0.1.2. React peer-deps @synclib-io/client >=0.3.0 <1.0.0, @tanstack/react-query ^5, react ^18||^19.

Dart (Flutter)

synclib_sync      →  SyncClient        ← the client
                     SyncManager       ← the transport-fallback helper (separate)
synclib_flutter   →  shared merkle + native

Key difference: in Dart the transport fallback is not inside SyncClient. It lives in a separate SyncManager you wrap around the client and attach(). A Dart consumer holds two objects. Dart packages are consumed as git dependencies (ref: main), not from pub.dev, and both synclib_sync and its synclib_flutter dependency are pinned to a git ref, so Dart has no version numbers to pin.

What is automatic vs your job

Automatic:

  • Socket auto-reconnect on network blips.
  • Per-write push (debounced) when syncOnWrite is on.
  • Applying snapshots and server broadcasts.
  • The transport flip to HTTP and back, with isSyncLive tracking.
  • Cursor bookkeeping, so pulls resume cleanly across a transport flip.

Your job (the consumer):

  • Construct the store and client, and call connect() once.
  • Call syncUnified() to catch up. In TS the wrapper does not auto-push on reconnect, so when connection state flips to connected you should call syncUnified() yourself. (Dart has autoSyncOnConnect, which does this for you.)
  • While degraded (HTTP mode) there are no live broadcasts, so poll syncUnified() on a timer and use on-demand fetch for screens. See sync-http-fallback.md.
  • Supply a valid JWT (getToken in TS, connect(token:) in Dart).

Where to go next

  • connect-your-own-frontend.md: building your own web app against your Base, step by step (sign-in, socket URL, channel, reads and writes).
  • sync-api-reference.md: exact construction, config, lifecycle, on-demand fetch.
  • sync-http-fallback.md: the degraded-network story and what you must do.
  • sync-scopes.md: whole-app vs per-screen sync, and the two scope APIs.
Start with Oalo

Your own Base, with every feature, from $99 a month.

get started