Contracts: how PocketOne fits together
PocketOne is PocketBase plus extensions. What keeps those extensions from turning into a pile of plugins that know too much about each other is how they meet: through contracts.
The idea
A contract is a promise with a name and a version. restore/v1 promises one thing: put this app's data back as it
was at a moment. It says what you can ask and what you get back. It says nothing about how.
An extension that keeps the promise provides the contract. Everything else talks to the contract, never to the
extension behind it: the dashboard, the pocketone command, an AI agent over MCP, your pb_hooks, and other
extensions.
That's the whole rule: every API an extension offers is a contract. Extensions have no private routes and never import each other.
An example: restore/v1
Every PocketOne app can restore its data to a moment. Who does the work depends on the app:
| Provider | How close it gets |
|---|---|
| PITR | Any second in the last three days, from continuous history. |
| Backups, the default | The latest backup made at or before the moment. It steps aside when PITR is on. |
| A multisite host | It could restore an instance from the host's own disk snapshots. |
Asking looks the same whoever answers:
pocketone remote restore to --at -2h # the command line
curl -X POST https://app.example.com/api/_c/restore/v1/restore \
-H "Authorization: $TOKEN" -d '{"at": "2026-11-10T15:00:00Z"}' # HTTP
An agent asked to "restore my app to yesterday at 3pm" calls the same operation as an MCP tool. Settings → Backups shows the contract's own "Restore to a moment" screen. The answer always says which point the data came from: exactly 3pm with PITR, or the 2:00 backup without it.
If something better than PITR comes along tomorrow, it provides restore/v1, and nothing that restores apps has to
change.
Why it matters
- Swap anything. Any extension that provides a contract can stand in for another. One line in
pocketone.yamlchooses when several could. - Build on anything. Extensions depend on contracts, not on each other: Deploy requires
remote/v1, not "the Remotes extension". Replace Remotes and Deploy keeps working. - One surface, promised. If a client can call it, it's in a contract: named, versioned, documented and checked.
Every extension route lives under
/api/_c/<contract id>/; only paths a standard fixes stay at the root (/.well-known/*,/mcp). - Written once, reachable everywhere. A contract's interface is the source for everything around it. Each
operation is at once an HTTP endpoint, a
pocketone remotecommand, an MCP tool, a hook in Go and inpb_hooks, and a typed client call. Every one of those paths passes the same checks: superusers only unless the operation is public, the token's scopes, and the action hooks. - Nothing hidden. Each app prints who provides what when it starts;
pocketone remote whoamilists the contracts an app offers; the catalogue lists every contract with the extensions that provide it, require it and work with it.
What one interface gives you
Write the interface, run go generate, and a contract like restore/v1 gets all of this:
| Surface | restore/v1 |
|---|---|
| HTTP API | GET /api/_c/restore/v1, POST /api/_c/restore/v1/restore |
| Command line | pocketone remote restore points, pocketone remote restore to --at -2h |
| MCP tools | restore_points, restore_restore_to |
| Hooks | restorev1.OnRestoreTo(app, ...) in Go, onRestoreRestoreTo(...) in pb_hooks |
| Client | restorev1.NewClient(url, token, nil).RestoreTo(...) |
| Dashboard | "Restore to a moment" on Settings → Backups, shown for any provider |
Who provides what
When an app starts, PocketOne settles every contract and says what it decided:
standard: restore/v1 ← pitr (default backups stepped aside)
standard: mail.fallback/v1 ← mailtrap
standard: deploy/v1 ← deploy (default)
-
Defaults. A standard extension often provides a contract as the default: it steps aside as soon as anything else provides it.
-
Choices. When two extensions provide a contract that takes one, the app won't start until
pocketone.yamlpicks one:providers: restore/v1: pitr -
Chains. Some contracts take several providers in order. Mail with SMTP off goes through
mail.fallback/v1's chain: the dev inbox in dev mode, then a host's relay. -
Your own JS. An app's
pb_hookscan provide contracts too, inonContracts((e) => e.provide(...)). -
The host. On a multisite host, some contracts are answered by the host for its instances. An instance running a stock PocketBase image in Docker has no PocketOne extensions inside it, but the host still answers
remote/v1for it, sopocketone remote logsworks there too. The host's own parts are contracts as well: what runs instances (runtime/v1, Pocker or Docker), what admits requests (gate/v1), its TLS (tls/v1).
Versions
A contract's id carries its major version only: restore/v1. Within v1 the promise doesn't change. Changing it
means a restore/v2 beside v1, so whatever relies on v1 keeps working. A new optional ability is usually a new,
small contract rather than a change to an old one.
Where contracts live, and who owns them
Every contract, from the standard set or the community, lives in one place: ext/contracts/<id path>/vN/
(mail.fallback/v1 is ext/contracts/mail/fallback/v1/). Extensions live in ext/<name>/. Keeping contracts
together means one namespace, so two authors can't publish different rehash/v1s, and it means one place to look
for what you can build on.
Each contract has a README like an extension's, with its owners and a one-line promise at the top. Its list of the extensions that provide it, require it and work with it is generated from the code, so it's never out of date.
Whoever first creates a contract owns it. An extension author who needs a contract that doesn't exist yet writes it
first, and then owns both the contract and the extension that provides it. Changes to a contract are reviewed
carefully, because every provider and every caller relies on the promise. Name a contract for what it does
(restore/v1), not for the extension that happens to provide it first.
Words
| Word | Meaning |
|---|---|
| Contract | A named, versioned promise: a Go interface plus the API, commands, tools and hooks generated from it. |
| Provide | An extension keeps the promise for an app. |
| Require | An extension can't work without the contract; without a provider it's turned off, and the startup lines say why. |
| Works with | An extension uses the contract when something provides it. |
| Default | A provider that steps aside when any other extension provides the contract. |
| Host-provided | A multisite host answers the contract for its instances. |
Next
- Contracts: what each one promises, and who provides, requires and works with it.
- Writing an extension: declare, provide and use contracts in your extension.
- Add a contract: the folder, the README and the generated code.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.