Get started
How it works, in 5 pictures
The whole idea in two minutes. No sync theory needed.
1. Each user gets a copy of their data
Your data stays in your Postgres, as it is today. When someone opens your app, clientdb downloads the rows they are allowed to see into their browser (or iPhone) and keeps them there, saved to disk so the next visit starts instantly, even offline.
You choose what comes up front: small models, such as a user's projects and todos, arrive when the app opens. Bigger ones, such as comments, arrive the first time something reads them, and stay.
Alice and Bob get different copies: each one only ever receives what your permissions say they may read.
2. Reading is instant, because the data is already there
Usual app
With clientdb
Your components read from that local copy, like reading a variable:
import { useLive } from "@clientdb/react";
import { db } from "@/sync/db";
const todos = useLive(() => {
return db.todo.where({ projectId }).orderBy("createdAt", "desc").all;
});No request, no loading state, no cache to manage. Filtering and sorting happen in memory and stay fast with 100,000 rows. When the data changes, the component re-renders on its own.
For data that isn't on the device yet, the same read starts loading it, and the component shows what's there until the rest arrives.
3. Writing is instant too, and your server still decides
todo.update({ title: "Fix the login redirect" });The change shows on screen immediately and is sent to your server in the background. The server checks it against your permissions file. If it's allowed, it's saved to Postgres. If not, the change is undone on the user's screen and you get an error you can show. Nobody can write around your rules from the browser.
This is why you don't need API routes per feature: one route serves everything, and one permissions file says who may read and write what.
4. Changes reach everyone who can see them
Once a change is saved, clientdb sends it to every other device that is allowed to see it. Open tabs pick it up on their next sync (on load, on focus and after each write), or within milliseconds with live updates turned on. A device that was offline catches up when it reconnects, getting only what changed while it was away.
Changes your own server code makes with Prisma or SQL sync the same way: small database triggers notice them, so that code doesn't change.
5. When permissions change, data appears and disappears correctly
Permissions aren't fixed. People get promoted, removed from projects, todos get marked private. When that happens, clientdb works out who just gained access and who just lost it, sends the newly visible rows to the first group and tells the second to remove theirs. You write no code for this; it follows from the same permissions file.
That's the whole model
- Your Postgres is the source of truth, unchanged.
- One permissions file decides what each user can read and write.
- Each device holds a copy of its user's data, reads it instantly and writes to it instantly.
- clientdb keeps every copy in sync and correct.
Ready to try it on your app? Go to the quick start. Want the ideas that shape your code? Read Thinking in clientdb. Curious how it works inside? See Under the hood.