# service-compris > A Firebase backend you **install libraries onto** rather than deploy features into. > A JSON manifest becomes collections, schemas and access rules on a running host — > no function deployment, no code review, no redeploy. Agents authenticate with > scoped tokens that attenuate their human's authority and die when it does. Status: **0.4.0** (0.2.0 was the first stable release). Two production hosts run it: tosijs-virta's (the first consumer, which broke the betas and got every break fixed) and loewald.com. Verified against a real deployed host by seven acceptance scripts (`scripts/verify-*.js`). The same endpoints also run in one Bun process on SQLite (`bun run serve:local`), with no Firebase. ## Start here - [BETA.md](BETA.md): the walkthrough — stand up a host, claim it, write a manifest, install it, give an agent an identity. Also lists what is deliberately not ready. - [CHANGELOG.md](CHANGELOG.md): what changed and, for each fix, what the bug actually was. - [DECISIONS.md](DECISIONS.md): dated, append-only architectural decisions. Read before proposing changes to RBAC, the access model, or the endpoint surface — several of those questions are settled and the reasoning matters more than the conclusion. ## The seven things that will save you the most time 1. **A `404` usually means "not allowed", not "not there".** Denials are opaque to non-privileged callers on purpose — a protected document and a missing one must be indistinguishable, or the status code enumerates what exists. Only `admin`/`developer`/`owner` see the real `403`. 2. **Collections must be namespaced**: `yourlib:thing`. A bare name is the platform's, always. The separator is `:` — `/` already separates sub-collections. 3. **Mutating requests put the path in the BODY.** `GET`/`DELETE` use `?p=`; `POST`/`PUT`/`PATCH` send `{"p": "...", "data": {...}}`. `POST /docs {writes:[…]}` commits several documents atomically. 4. **In a manifest, `access` is an array, not a role-keyed object.** (The kernel's compiled `CollectionConfig` keys it by role.) Grants join as a lattice, so order is meaningless and holding more roles never grants less. 5. **A fresh function may answer `401` with HTML from *Google*, not from us.** It is not publicly invocable. Every endpoint declares `invoker: 'public'` in code (`functions/src/endpoint-options.ts`), so redeploying fixes it. Ours carry CORS and rate-limit headers; that is the tell. 6. **Errors are `{error: "", message, details?}`.** Switch on the code; the prose is free to change. Opaque `404`s carry no detail, by design. The codes, with statuses and when each fires, are the table under "Errors" in BETA.md. 7. **Endpoint-managed fields are hidden from your schema** — `_created`, `_modified`, `_seq`, `_by` — so `additionalProperties: false` works. ## Endpoints - `/doc` — single document CRUD. `GET`/`DELETE` take `?p=collection/id`; `POST`/`PUT`/`PATCH` take `{p, data}` in the body. `?p=coll/field=value` resolves by a field in `unique` or `tagFields`. - `/docs` — collection queries (`?p=`, `c=` limit, `f=` fields, `o=` order), the delta cursor (`since=` → `{rows, cursor, more}`), `modifiedAfter=` (documents edited since, newest first), and `POST {writes:[…]}` for an atomic multi-document commit. - `/install` — `POST {manifest, approving?}` installs or upgrades; `GET` lists; `DELETE ?name=` revokes. Requires `configurator`, and specifically **not** `owner`. `GET ?name=` answers `{name, version, status}` to any authenticated principal, tokens included. Or approve in a browser: `POST ?action=propose` needs no credentials and returns a link (`GET ?request=`, a dry run and an Approve button for a configurator); `?action=preview|approve|status`. `scripts/install-manifest.js` does this. - `/claim` — `GET` publishes a nonce; write it into the datastore to prove ownership, then `POST` (authenticated) to mint the first `configurator`. `bun scripts/claim.js --alias [--for ]` does both and opens `/claim?page`, where that person signs in and clicks Claim. - `/token` — `POST` mints a scoped token, `GET` lists your own, `DELETE ?id=` revokes. - `/blob` — files in a **storage area** (a manifest collection with `blob: {maxBytes, contentTypes?}`). `PUT/GET/DELETE /blob//`; `POST {op:"move", from, to}`. The area's access rules govern its files; its metadata lists through `/docs`, and is written only through `/blob`. 25 MB ceiling. See BETA.md "Store files". - `/authorize` — the browser loop that gives a CLI its first token. `?action=start|approve|exchange|config`; `GET ?request=` is the consent page. - `/room` and the `/rooms` WebSocket — game rooms (D26, D27), on Bun hosts only (Cloud Functions cannot hold a socket). The rooms host serves them alone, with guest tokens; the client is `tosijs-rooms`. - `/esm`, `/stored`, `/gen`, `/prefetch`, `/cachedQuery` (for a caller with a role; fetches public addresses only), `/user`, `/sitemap` — the older surface. See `reference/`, but trust the code over the file paths in it: they predate the `collections/` reorganisation. ## Rules a manifest lives by - **`unique: ["a", "b"]` makes each field unique on its own.** There is no composite (tuple) uniqueness. A missing or non-scalar value in a unique field is refused (`400 unique`). - **Upgrades are additive-only.** Removing a collection or field, newly *requiring* a field, or changing a unique constraint are refused as migrations rather than guessed at. A newly-required field would invalidate every stored document. - **A published version's content is immutable.** Re-POSTing the same version is normal; re-POSTing different content under the same version is a `409`. - **Revoking never drops rows.** Collections become unreachable; documents stay. - **v1 is declarative only.** A `functions` key is a hard failure, not an ignored field. Stored ajs is install v2. - **`envelope: { seq: true }`** assigns a monotonic `_seq` so a replica can resume. Opt-in: a total order serialises writes to that collection at roughly one per second, through one counter document. **`requireAttribution: true`** refuses a write the endpoint cannot attribute. **Declare `seq` before the first write:** an upgrade that turns it on or off for an existing collection is refused, because earlier (or later) documents would carry no `_seq` and be invisible to `since=`. - **`immutable: true`** (top level of a collection, beside `schema`) makes a stored document unchangeable: an identical re-write is a no-op, a different one is refused with `409 {error: "immutable"}` — in a batch, the whole commit is. Deletes are refused too, and an upgrade may add it but never drop it. Without it an upsert over an existing id REPLACES it and assigns a new `_seq`. Declare it on any log you replicate. - **Row visibility is a closed vocabulary**, not an expression language: `{field, op, value}` with `includes`, `eq`, `neq`, `nonEmpty`, `absent`, `lte`, `gte`, nested under `all`/`any`. To compare a row to the CALLER, put `principal: "uid"` in place of `value` (`eq` or `includes` only): `{"field": "owner", "op": "eq", "principal": "uid"}` is "your own rows". A signed-in caller with no role document has a uid and no roles, so a `public` rule like that one is all an app with per-account data needs. Anonymous matches no principal rule. Writes take the same rule: `write: {"visible": , "accept": }` admits a write when the rule holds on the stored row (if any) and on the new row, and the schema takes the content; someone else's row is a 404. Not `public` `write: "ALL"` plus `derive: principal`: the derive fills only a missing field, so anyone could name another owner. Ids are first come, first served: use fresh unguessable ids, not the uid. - **A role pre-assigned by contact email resolves only for a VERIFIED email.** Password sign-up is enabled on provisioned hosts, so an unverified address is a claim anyone can make. - **The `system` namespace is the platform's.** A manifest named `system`, or declaring `system:*`, is refused. - **Capabilities are shape-only so far.** The format is settled and validated, but nothing consults `grant.capabilities` yet. The install response reports `unenforced: [...]` so you are never told you hold a power you do not. ## What a token is `(principal, caveats)`. Effective authority is recomputed **on every request** as `rolesOf(principal) ∩ caveats.roles`. So a token never holds what its principal does not hold right now, and revoking a human revokes every agent they authorised — instantly, with no revocation list. `owner`, `configurator` and `developer` can never be carried by one. A token cannot mint another. `DELETE` is not a default method. The secret is shown once and never stored, only hashed. ## Repository shape - `functions/src/collections/` — the portable decision kernel. The `service-compris` npm package publishes part of it: `write-pipeline`, `access` and `roles` (plus `auth/caveats`), through `lib/index.ts`. No kernel file names a vendor: the datastore, files, identity, logger and HTTP are ports, with adapters in `functions/src/adapters/` (Firebase; SQLite and Bun for `serve:local`). - Blog posts and pages are NOT platform collections. They are `blog:post` and `blog:page`, from the blog manifest (`manifests/blog.json`, D28); a host has them once it is installed. The asset manager is `service-compris/assets`, with its own manifest. - The platform's OWN collections (`role`, `config`, `module`, …) can be served from stored configs in `system:registry` (`PLATFORM_CONFIGS_FROM_REGISTRY=true`, off by default; on in production). Seed them with `scripts/seed-registry.js` and `--check` BEFORE turning it on; with the switch on and nothing seeded, those collections are inaccessible. - `functions/src/install/`, `functions/src/auth/` — install and auth, each split into pure decisions plus a thin HTTP handler. If it is a judgement, it belongs in the pure half where it runs without a cloud. - `scripts/verify-*.js` — acceptance against a LIVE host, seven ceremonies: install, token, authorize, sequence, batch, provenance, blob. `--alias ` targets a project. Run these first on a new host; if they pass, anything you hit afterwards is your manifest or our design, not a broken deploy. - `src/` and `extensions/` — the blog and the asset manager, which stay here as installable extensions of the core (D28). Generic client pieces go upstream to tosijs-ui. ## Where to push hardest The manifest format. It was designed against three consumers and validated against one. If it cannot express something your design needs, **that is the bug** — say so rather than bending your design around it. A weakness found now is an issue comment; the same weakness after adoption is a migration. Issues: https://github.com/tonioloewald/tosijs-platform/issues