Build with an AI coding tool
An AI coding tool can build a phibac app for you if it knows the rules. This page gives you two prompts to paste into the tool (for example Claude, in the desktop app or in a terminal), explains what the tool does and what it asks you to do, and how to check what it builds.
These prompts have not yet been tested with any AI tool. Treat what the tool writes as a first draft and check it as described in Check the AI's work.
Choose a prompt
Both prompts tell the AI the same rules: first check that the CLI (the command-line tool) and the SDK (the JavaScript library your page uses) are installed in the project and install them from npm if they are not, run every CLI command as npx phibac … and run every command itself, describe the data in pb.config.ts, call connect() only from a click, try everything on a local server first, keep developer keys out of the chat, and stop and ask you when the docs and the server disagree. Where llms-full.txt says something else, such as building straight on this server, the prompt wins. Both end with the line What I want to build:. Paste the prompt, then write what you want on that line, for example "a notes app where I can pin notes".
- The short prompt suits a tool that can read web pages. It tells the tool to read llms-full.txt, the full reference written for AI tools, before it writes any code. Give a tool that file only through one of the two prompts: on its own, the file builds straight on this server; the prompts tell the tool to try everything on a local server first.
- The full prompt suits a tool that cannot read web pages, or when you want the rules in the conversation from the start. It holds a complete
pb.config.ts, the SDK calls most apps use, what queries cannot do, the most common errors and what never to do.
Press Copy above a prompt to copy it. You can also select the text and copy it, or give a tool the plain-text address: /docs/prompts/short.txt and /docs/prompts/full.txt.
The short prompt
You are helping me build a web app on phibac, the backend at https://phibac.com. Each user has one private database there, and the apps that user approves share it. I write only the front end.
Before you write any code, read https://phibac.com/llms-full.txt and follow it, except where this prompt says otherwise: this prompt wins. Never invent SDK methods, CLI commands or options, and never hard-code limits.
First make sure the SDK and the CLI are installed in this project; if they are not, install them with `npm install @phibac/sdk` and `npm install --save-dev phibac`. Write every CLI command as `npx phibac …`.
Create the app with `npx phibac init`, describe every collection in `pb.config.ts`, publish it with `npx phibac deploy`, then write the types with `npx phibac generate`.
Give every collection and field a description, and mark every field you filter or sort on `indexed`.
Call `connect()` and `requestAccess()` only from a click handler, before any `await`: the browser blocks their popups anywhere else.
Run every command yourself. Ask me only to do things in the browser, and tell me in plain words what to do and why.
Build and test against the local server first: start `npx phibac dev` yourself in the background, in the project folder, before any other CLI command, and leave it there: it keeps running. Run every `npx phibac` command from that same folder. The local server came with the CLI; if it says there is no server for this computer or that the server package is not installed, stop and ask me.
On the local server the CLI needs no token: it reads the server's own key from `./.pb/developer-token` by itself, so never open, print or copy that file.
When the app is ready to try, tell me the address to open, and that on the local server any email address works for signing up and no email is sent.
Going live is a later step: ask me before you start it. There the CLI needs a developer token from the server it talks to, in `PB_TOKEN`, which I create on that server's `/account/developer` page; if it is missing, stop and ask me.
Never ask me to paste the token into this chat, never print it, and never write it into a file.
If the docs and what the server answers disagree, stop and ask me.
What I want to build:
The full prompt
You are helping me build a web app on phibac, the backend at https://phibac.com. Each user has one private database there, and the apps that user approves share it. I write only the front end: static files that read and write the user's data through the SDK, `@phibac/sdk`. Users sign in with a passkey or a password in a popup on the server's own page; there is no server code, no SQL and no sign-in code for you to write, and the app never sees the password. Follow every rule below. If the docs and what the server answers disagree, stop and ask me.
SETUP
- First make sure the SDK and the CLI are installed in this project; if they are not, install them with `npm install @phibac/sdk` and `npm install --save-dev phibac`. Write every CLI command as `npx phibac …`.
- Run every command yourself. Ask me only to do things in the browser, and tell me in plain words what to do and why.
- Build and test against the local server first: start `npx phibac dev` yourself in the background, in the project folder, before any other CLI command, and leave it there: it runs the server at http://localhost:8787 (the SDK's and the CLI's default) and keeps running. Run every `npx phibac` command from that same folder. The local server came with the CLI; if it says there is no server for this computer or that the server package is not installed, stop and ask me.
- On the local server the CLI needs no token: it reads the server's own key from `./.pb/developer-token` by itself, so never open, print or copy that file.
- `npx phibac init --name "<app name>" --origin <the page's origin>` creates the app and writes `pb.config.ts`. Then `npx phibac deploy` publishes the collections, and `npx phibac generate` writes `src/pb-types.ts`. When the app is ready to try, tell me the address to open, and that on the local server any email address works for signing up and no email is sent.
- Going live is a later step with its own account, token and app ID on https://phibac.com (the CLI reaches it with `PB_BASE_URL=https://phibac.com`, the app with that `baseUrl`): ask me before you start it. There the CLI needs a developer token from the server it talks to (a token works only on the server that made it), in `PB_TOKEN`, which I create on that server's `/account/developer` page; if it is missing, stop and ask me.
CONFIG FILE `pb.config.ts` (a complete example; keep the app ID that `npx phibac init` wrote)
```ts
import { defineApp, collection, string, boolean, datetime } from "phibac";
export default defineApp({
app: "app_...",
collections: {
"com.example.notes.note": collection({
version: 1,
description: "A note written by the user",
fields: {
text: string({ description: "Note text", maxLength: 20000, required: true }),
pinned: boolean({ description: "Whether the note is pinned", indexed: true }),
remindAt: datetime({ description: "When to remind the user of the note", indexed: true }),
},
}),
},
});
```
SCHEMA RULES
- Every collection and every field needs a `description`: users read them on consent pages.
- Collection names are a domain I control written backwards, with at least three lower-case parts (`com.example.notes.note`); `core.` and `sandbox.` are reserved. Field names use letters, digits and `_`; `createdAt` and `updatedAt` already exist.
- Field helpers: `string`, `number`, `integer`, `boolean`, `datetime`, `enumOf([...], {...})`, `json`, `fileRef`, `recordRef`. Write every `datetime` value with `new Date().toISOString()`.
- Mark every field you filter or sort on `indexed: true`; a `json` field cannot be indexed.
- Make additive changes only, such as a new optional field. Other changes are breaking, such as removing, renaming or retyping a field, making a field required or optional, adding a required field, or tightening a `maxLength`, `min`, `max` or `enumOf` list: each needs a new major version (`version` raised by one).
- Data only this app needs can go in a `sandbox.<name>` collection, which needs no schema.
SDK (call `connect()` and `requestAccess()` only from a click handler, before any `await`: the browser blocks their popups anywhere else)
```ts
import { connect, PbError, type PbRecord } from "@phibac/sdk";
// In the app, import both from the generated file: import { SCHEMA_MAJORS, type ComExampleNotesNoteV1 as Note } from "./pb-types";
const SCHEMA_MAJORS = { "com.example.notes.note": 1 } as const;
interface Note { text: string; pinned?: boolean; remindAt?: string }
const BASE_URL = "http://localhost:8787"; // the local server (npx phibac dev); this prompt came from "https://phibac.com"
const list = document.querySelector<HTMLUListElement>("#notes")!;
const show = (records: PbRecord<Note>[]) =>
list.replaceChildren(...records.map((r) => Object.assign(document.createElement("li"), { textContent: r.data.text })));
document.querySelector("#sign-in")!.addEventListener("click", async () => {
try {
const backend = await connect({ app: "app_...", baseUrl: BASE_URL, schemaMajors: SCHEMA_MAJORS });
backend.onConflict(({ error }) => console.error(error.code, error.message));
const notes = backend.collection<Note>("com.example.notes.note");
notes.where("pinned", "==", true).orderBy("createdAt", "desc").subscribe(show);
await notes.create({ text: "Buy milk", remindAt: new Date().toISOString() });
} catch (e) {
if (e instanceof PbError) console.error(e.code, e.message);
}
});
```
- A collection has `create(data)`, `update(rkey, patch)`, `delete(rkey)`, `get(rkey)` and `list()`. Writes return at once as `pending` and become `synced`; the server's refusals arrive later through `backend.onConflict()`.
- Queries: `where(field, op, value)` with `==`, `!=`, `<`, `<=`, `>`, `>=` or `in`, then `orderBy(field, "asc" | "desc")`, `limit(n)`, and `get()` or `subscribe(fn)`. Without `limit(n)` a query returns at most 500 records.
- Files: `backend.files.upload(file, { collection })` returns a file ID for a `fileRef` field; `backend.files.url(id)` gives a short-lived address: reuse an address while it is valid, ask for a new one when it has expired, and never store one in a record.
- Before `backend.signOut()`, check `backend.status().pending`: sign-out deletes changes not yet sent.
- Show data with `textContent`, never `innerHTML`.
- Another app's collection is read-only: open it with `backend.collection(name, { versions: [1] })` (the major versions your code understands), then call `requestAccess()` on that handle from a click; until the user agrees, reads fail with `consent_required`.
QUERY LIMITS (and what to do instead)
- Filters combine with AND only: use `in` for one field with several values, or run one query per condition and merge by `rkey`.
- Queries sort by one sort field only (a second `orderBy` replaces the first): sort again in your code.
- There is no text search: for "starts with", store a lower-case copy in an indexed field and query a range; otherwise filter in your code.
- There are no counts or totals: read the records with a `limit(n)` larger than the collection can get, and compute in your code.
- No joins: linked records are not fetched. Take the rkey from the end of a `recordRef` value and call `get(rkey)`.
COMMON ERRORS
- `popup_blocked`: `connect()` or `requestAccess()` did not run straight from a click. Call it first in the click handler.
- `invalid_request` saying a field "cannot be used to filter or order": mark it `indexed: true`, then `npx phibac deploy` and `npx phibac generate`.
- `not_found` saying the collection "has no published schema": run `npx phibac deploy` before writing to it.
- `npx phibac deploy` shows a collection as `breaking` (the server's code is `schema_incompatible`) and publishes nothing: make the change additive, or raise that collection's `version`.
- `consent_required`: call `requestAccess()` on the collection handle from a click, then query again.
NEVER
- Never write, change or delete records in a collection another app owns.
- Never ask me to paste the token into this chat, never print it, and never write it into a file or into code.
- Never invent SDK methods, CLI commands or options, and never hard-code limits: handle the error the server returns.
For anything this prompt does not cover, read https://phibac.com/llms-full.txt; where it differs from this prompt, this prompt wins.
What I want to build:
The packages the AI installs
The prompts tell the AI to make sure the SDK and the CLI are installed in your project and, if they are not, to install them from the npm registry with the same commands as step 1 of Build your first app:
npm install @phibac/sdk
npm install --save-dev phibac
You can also run these two commands in the project yourself before you start the tool. The AI then runs every CLI command as npx phibac …, which runs the CLI installed in the project.
No token while you build on your computer
You do not set up anything for the AI while it builds on your computer. It starts the local server with npx phibac dev in the background, and the local server makes its own developer key in ./.pb/developer-token, which the CLI uses by itself. The prompts tell the AI never to open, print or copy that file. npx phibac dev also adds a .pb/ line to .gitignore, so the key and your test data stay out of Git.
The AI asks you only to do things in the browser. When the app is ready, it tells you which address to open. To sign up there, type any email address and press Send me a link: the local server sends no email, so it goes straight to Confirm and continue, and then you choose a passkey or a password. If a page asks for a code from an email, the local server shows that email on the same page. Develop on your own machine explains the local server.
Give the AI a token when you go live
Putting the app on the internet is a separate step, and the AI asks you before it starts it. There the CLI needs a developer token: a secret key, starting with pbd_, that lets it create your apps and publish their schemas. A token works only on the server that made it, so it must come from the server the app goes live on (https://phibac.com/account/developer on this server). Put your app on the internet shows how to create it.
Give the token to the tool through the environment, never through the chat:
-
Open the terminal you will start the AI tool from, or the terminal the tool runs its commands in.
-
Set the token there, pasting your token in place of
pbd_...:export PB_TOKEN=pbd_... -
Start the AI tool from that terminal. The commands it runs, such as
npx phibac deploy, readPB_TOKENfrom there.
Never paste the token into the chat, and do not let the tool write it into a file in your project. Both prompts tell the AI never to ask you to paste the token into the chat, never to print it and never to write it into a file, and to stop and ask you when PB_TOKEN is missing. If the token ends up somewhere it should not, press Revoke next to it in the developer section of your account page (https://phibac.com/account/developer on this server) and create a new one.
What the AI can and cannot do with your token
With a developer key, the CLI and the agent tools (if you connect them) can create apps, change the origins an app runs from (its web addresses), preview and publish schemas, generate types and read these docs. They never read or change any user's data, and they cannot delete an app or a published collection: no developer route or agent tool touches user data. User data is reached only by your app, running in a user's browser after that user signs in and agrees.
The prompts need only the CLI. If your AI tool can use agent tools, Developer API and agent tools lists them and explains how to connect the tool to this server.
What to expect
- The AI first checks that the CLI and the SDK are installed, and installs them from npm if they are not.
- It creates the app with
npx phibac init, writespb.config.ts, publishes it withnpx phibac deploy, runsnpx phibac generateand then writes your page. - It runs every command itself, starting with the local server:
npx phibac devkeeps running, so the AI starts it in the background. The server comes with the CLI; if it says there is no server for your computer, or that the server package is not installed, the AI stops and asks you. - It needs no token on the local server, and asks you only to do things in the browser, such as signing up and pressing Sign in on your app.
- It asks you before it starts putting the app on the internet.
Check the AI's work
- Read what
npx phibac deployprints. It previews every collection before it publishes and publishes nothing if a change is breaking. Check that each collection and field has a description a user would understand, and that every field your app filters or sorts on isindexed. - Let TypeScript check the code. With the types from
npx phibac generate, your editor or the TypeScript compiler flags a wrong field or value before you run anything. - Try the app against the local server. With the local server the AI started still running, open the page, press Sign in, save some records, then reload the page and check that they are still there. Sign-in needs your passkey or your password, so do this step yourself.
- Look for the usual mistakes. Common mistakes lists them. In particular:
connect()andrequestAccess()are called straight from a click; data is shown withtextContent, neverinnerHTML; the code never writes to another app's collection; and nopbd_token appears anywhere in the project outside the./.pbfolder. - Look up any error code in Errors and how to fix them.
Next step
Build your first app does the same steps by hand, with an explanation of each one.