# clientdb > clientdb: your Postgres, right in the client. Instant, and safe by one set of permission rules. A type-safe, local-first sync engine for Postgres apps. Clients hold a live, offline-capable replica of exactly the rows they may read, derived from typed permission rules. Prisma integration, a Next.js route handler with no sockets, React/MobX and Swift clients. The full docs as one file: https://clientdblib.vercel.app/llms-full.txt ## Get started - [What is clientdb?](https://clientdblib.vercel.app/docs): A data layer that makes your app feel instant, and lets you delete most of your API code. - [How it works, in 5 pictures](https://clientdblib.vercel.app/docs/how-it-works): The whole idea in two minutes. No sync theory needed. - [Quick start: Next.js + Prisma](https://clientdblib.vercel.app/docs/quick-start): Add clientdb to the Next.js + Prisma app you already have. Everything runs inside your app; nothing else to host. - [Thinking in clientdb](https://clientdblib.vercel.app/docs/thinking-in-clientdb): The mental model in seven ideas: a local replica your UI reads and writes instantly, and a server that has the final say. - [Public API overview](https://clientdblib.vercel.app/docs/public-api-overview): Every part of clientdb's public API in one example app: schema, permissions, sessions, the server, clients, reads, writes and operations. - [Installation](https://clientdblib.vercel.app/docs/installation): Install the clientdb packages from npm. ## Guides - [Reading data](https://clientdblib.vercel.app/docs/client/queries): Synchronous, typed, reactive reads: lookups, filters, relations, lazy loads, server queries and eviction. - [Writing data](https://clientdblib.vercel.app/docs/client/mutations): Create, update, edit-then-save, delete and server logic with $action. Every write is optimistic and returns a handle you can await. - [Transactions and undo](https://clientdblib.vercel.app/docs/client/transactions): Group writes into one atomic server transaction, undo and redo them, and handle rejections. - [React: keeping components up to date](https://clientdblib.vercel.app/docs/client/reactivity): Built-in fine-grained signals with useLive, or MobX-native observability with one option. Same types either way. - [Permissions](https://clientdblib.vercel.app/docs/server/permissions): One file per model that says who may see and change what: read rules, restricted fields, write rules with field groups, server query rules and claims. - [Permission recipes](https://clientdblib.vercel.app/docs/guides/permission-recipes): Copy-paste read and write rules for the common shapes: team membership, roles, owner-only, inherited access, public and signed-in data, staff claims, restricted fields and deny lists. - [Writes made outside clientdb](https://clientdblib.vercel.app/docs/guides/untracked-rows): Rows your app writes outside clientdb (Prisma Client, seed scripts, SQL, other services) reach clients through Postgres triggers, with engine.reconcile() as the safety net. - [Offline and multiple tabs](https://clientdblib.vercel.app/docs/storage): Keep the data and unsaved changes in the browser, so the app opens instantly and works offline, and let tabs share one connection. - [Deploying on Vercel and Neon](https://clientdblib.vercel.app/docs/guides/deploy-vercel-neon): A serverless deployment with no background process: connection strings, the release step, and what to watch. - [Security checklist](https://clientdblib.vercel.app/docs/guides/security): What clientdb protects on its own, and the settings and habits a production app needs on top: sessions and tokens, cookies and other sites, rules, limits and devices. - [Testing](https://clientdblib.vercel.app/docs/guides/testing): Test client code against an in-memory server with createTestClient, and permissions end to end with testEngine on a real Postgres. - [Swift client](https://clientdblib.vercel.app/docs/swift): A native client for iOS 17 and macOS 14+: SwiftPM codegen from your schema, @Observable models, live queries, SQLite storage and SwiftUI helpers. ## Reference - [Schema in TypeScript](https://clientdblib.vercel.app/docs/schema): Define models, fields and relations once; the schema types every read, write and permission rule, on the server and in the browser. - [Prisma as the source of truth](https://clientdblib.vercel.app/docs/schema/prisma): Build a fully typed clientdb schema from schema.prisma with fromPrisma, run on Prisma's tables, and sync the writes your app makes with Prisma Client. - [The engine](https://clientdblib.vercel.app/docs/server/engine): createEngine ties your permissions and your database together: its options, hooks and retention, its lifecycle from install to prune, and writing from your server. - [HTTP: pull and push (no sockets)](https://clientdblib.vercel.app/docs/transports/http): Sync over plain HTTP: the Next.js route handler and its session callback, read-only routes, a fetch-standard handler for any runtime, the endpoints, and when the client syncs. - [Node.js servers: node:http, Express, Fastify and Hono](https://clientdblib.vercel.app/docs/transports/node): Run the sync endpoints and the realtime WebSocket on a plain Node.js server: node:http, Express, Fastify or Hono, with CORS, body limits and graceful shutdown. - [WebSocket: realtime](https://clientdblib.vercel.app/docs/transports/websocket): Instant updates over a WebSocket, with catch-up on reconnect, sync tokens for a socket on another host, and sessions checked again while the socket is open. - [Migrations](https://clientdblib.vercel.app/docs/server/migrations): Schema and permission changes roll out with clientdb migrate: a dry run first, then versioned migrations, online re-routing, recomputed memberships and pruning. Old clients reload. - [Archive vs hard delete](https://clientdblib.vercel.app/docs/server/archive-delete): Archive hides a row everywhere and keeps it, reversibly, until retention deletes it; hard delete removes the row and the rows that cascade from it, and can still be undone. - [Errors and warnings](https://clientdblib.vercel.app/docs/reference/errors): Every error code and development warning clientdb produces, what it means and how to fix it. - [Benchmarks](https://clientdblib.vercel.app/docs/reference/benchmarks): Scale, server, socket-free, Prisma and client numbers: single machine, local Postgres 16, Node 22. - [FAQ and limits](https://clientdblib.vercel.app/docs/reference/faq): Common questions, and what clientdb deliberately doesn't do (yet). ## Under the hood - [The sync model](https://clientdblib.vercel.app/docs/concepts): How clientdb keeps every device's copy correct: one ordered log of changes, access groups, versions per row, and pending local changes. - [Groups and routing](https://clientdblib.vercel.app/docs/server/groups): How read rules compile into groups, how rows and viewers are tagged, and which rules the compiler rejects (and why). - [When access changes (move-in and move-out)](https://clientdblib.vercel.app/docs/server/access-changes): When someone gains or loses access, the engine sends exactly the rows to add and the ids to remove. No data ever reaches a device whose user may not read it. - [Optimistic writes, conflicts and rejections](https://clientdblib.vercel.app/docs/server/conflicts): Pending writes are replayed on top of newer server data; conflicts resolve per field in commit order; refused transactions roll back cleanly. - [Outbox and sequencer](https://clientdblib.vercel.app/docs/server/outbox): How writes get a gap-free, commit-ordered sync id without replication slots: a transactional outbox drained by one sequencer. - [Postgres, Neon and serverless](https://clientdblib.vercel.app/docs/server/postgres): Runs on any Postgres 14+, including Neon with scale-to-zero and branch restores. Pooling, the tables clientdb adds, tenancy, row-level security and the snapshot cache. - [Protocol and spec](https://clientdblib.vercel.app/docs/reference/protocol): The language-neutral contract between the server and every client: wire protocol v2, sessions, load keys, server queries, replica semantics, the schema IR and conformance vectors.