Client and live UI
@protobase/client is a typed fetch client for /api/v1; @protobase/ui wraps it in TanStack Query hooks (src/data) and runs the admin on both (src/app). Everything runs in the browser (or anywhere with fetch) and imports only @protobase/schema and @protobase/layout’s types.
import { createClient } from '@protobase/client'import { where } from '@protobase/schema'
const api = createClient({ baseUrl: '/api/v1', onMetaVersion: (version) => { /* refetch meta when it changes */ } })
const page = await api.list(orders, { filter: where.eq('status', 'draft'), orderBy: 'created_at desc', pageSize: 50, fields: ['id', 'number'] })const { record, etag } = await api.get(orders, id)await api.update(orders, id, { status: 'shipped' }, etag) // 412 rejects with PreconditionFailedErrorPass a resource builder to get its record type (InferRecord), or a name for loose records. Filters are AIP-160 text or where results (printed with printFilter), and a list whose query string passes 4,000 characters goes by :search. Errors are ApiError (status, slug, errors, filterErrors with spans, blockedBy for a delete other records point at), which isApiError(error) tells apart. Also: search, create, remove, facets, series, histogram, batchAggregates(resource, { facets?, histograms?, series? }) (several of those reads in one :batchAggregates request, answered as each would be), map(resource, { latitude, longitude, zoom, filter?, orderBy?, fields? }) (the records in a map’s view, or buckets of them, see :map), seek, reveal(resource, key, field) (a sensitive field’s value), generate(resource, key, action) (runs an AI action and resolves to the record as written), meta(etag?, { signal? }), invoke(name, { body?, method?, path?, query?, cache? }) (one of the app’s API functions; its answer as parsed JSON, text, or a Blob for any other type), history(resource, key, { pageSize?, pageToken? }) (a page of a record’s changes, newest first), comments(resource, key, { pageSize?, pageToken? }), comment(resource, key, { body, mentions? }) and mentionable(resource, key, query) (a record’s comments, adding one, and the people it may mention), form(name), formChallenge(name) and submitForm(name, values, proof) (a public form), upload(resource, field, file, { onProgress?, signal? }) (a file for a file field; its value goes in the next write, and onProgress uses XMLHttpRequest, since fetch reports no upload progress), live({ onChanges, onResync, onRetry? }) (hears which records of the live resources change until the function it returns is called, connecting again by itself; every caller of one client shares one stream), channel(resource, key) (a record’s channel, with its presence and broadcasts, every channel of the client on one socket), bridges.open(name, target) (a TCP bridge’s socket, with when the server closes it).
With an absolute baseUrl, such as another app’s https://desk.example.com/api/v1, the url of each file in a record the client answers is absolute too, on that API’s origin, where the API answers a path on its own origin. routedClient(own, sourceOf) is one client over several APIs: each call about a resource goes to the client sourceOf(resource) gives, else to own, as the admin app does for remote resources, and sourceMeta(meta, source) keeps the part of another API’s /meta an app draws.
createStaticSession(token) is a session already signed in with a token you hold, such as one from protobase token, for stories and scripts: it never refreshes, so the token must outlive the run, and it cannot change the account. tokenExpiry(token) reads a JWT’s expiry, in milliseconds.
The admin app
Section titled “The admin app”<App baseUrl="/api/v1" /> renders the shell from /api/meta (beside the API, so createClient derives it from baseUrl) and routes /:page and /:page/:tab (composed pages and their tabs), /:resource (list) and /:resource/:key (record); it opens on the first entry of the sidebar the user sees, or, with none, the first page or resource. Its own pages sit under /-/, which no page or resource name takes: /-/account and its tabs (the user’s account page, from /meta’s account) and /-/sign-in-policy (admins: the policy, and the log of staff sign-ins). Before the shell, it signs in on its sign-in route, /-/sign-in, with the methods the server offers and asks for what the sign-in policy requires. Someone signed out goes there from any page, with that page in ?next=, and signing in comes back to it; each step (a forgotten password, an emailed code, making an account) adds ?step=, so the browser’s Back returns to the step before; ?staff-sign-in opens the staff sign-in page instead, and a staff session gets a banner below the top bar. createAuthSession from @protobase/client is that session (signIn, signInWithCode, signInWithPasskey, verifyTwoFactor, account, signInPolicy, staff). ui takes the project’s custom components and action handlers. The list state lives in the URL: ?list=, a named list, ?filter= (AIP-160), ?order_by=, ?display=, the display it shows, ?layout=panel, the filters in a panel beside the table on a desktop instead of a bar above it, ?map=52.37,4.89,12, where a map looks, ?calendar=month,2026-10-01, the month or week a calendar shows, ?timeline=quarter,2026-10-01, the week, month or quarter a timeline shows, and ?saved_search=, the saved search the list was opened from. Views come from tests/apps/*/config/*/ui.ts. The sidebar’s recent-record groups and the user menu are configured there too: see Sidebar, User menu and Bottom bar.
Global search
Section titled “Global search”The search box in the top bar looks in every resource the user can read that has search fields (.search(...) in its data config) and a view in the sidebar or the user menu. Its placeholder names them, such as “Search organizations, services and more”; an app with no page or resource has no box.
From two characters on, it asks each of those resources’ list API for search("<text>") (every word, even part of one, in one of the search fields; the end of a digitsEnd field) with the user’s token, five records each, so row filters and hidden fields apply exactly as on the lists and it never offers a record the user could not open. Before the records, under Go to, are the sidebar’s pages and lists whose names hold the text (“stock” finds Stock levels), and under Create a New … for each resource the user may create whose name holds it, with or without “new” before it (“order” or “new ord” finds New order), five of each. The records are grouped by resource, two lines each: a bold title, the view’s searchResult title fields joined by spaces (default: the record’s title), and a subtitle, the view’s searchResult subtitle (default: the first search field not in the title). When the text matched a search field that neither line shows, such as a phone number, that field is the subtitle instead.
Each result is a link: a click or Enter opens it and closes the list, Enter the first result when none is highlighted, and Cmd or Ctrl click, a middle click or the browser’s menu open it in a new tab. The text stays, so focusing the box again shows the same results without asking the server; only changed text searches again. While the box has text, a clear button replaces the ⌘K hint. ⌘K (Ctrl+K) focuses the box, or opens it on a phone; the arrow keys move through the results, and Escape clears the box, then leaves it. A resource whose search fails says so in its group.
Live stories
Section titled “Live stories”bun run db:up && bun run --cwd tests/apps/erp serve, then bun run storybook. Storybook proxies /api to PROTOBASE_API (default http://localhost:8787); pick another API in the toolbar. Without a server the stories say so. bun run screenshots:live writes screenshots/live/.