Canica

Canica: deploy, schema changes, sign-in, dev tools

For people running Canica apps. App code is covered by GUIDE.md.

Install

curl -fsSL https://get.canica.app | sh   # the CLI in ~/.canica (and Node.js there, if the machine has no recent one)
canica new my-app && cd my-app && canica dev

Run the installer again to update. An app's own canica (in its node_modules) runs the commands inside it.

Deploy

canica login             # once: Google sign-in in the browser; the token stays in ~/.canica/credentials.json
canica deploy            # in the app's directory → https://<name>.canica.run

canica deploy checks that you are signed in, runs typecheck, lint and tests (it stops at the first failure; --skip-checks skips them when you just ran them), builds the client and the server on your machine, and uploads them to the platform's deploy service (api.canica.app). The first deploy reserves the name (--name, default: the package name; if someone has it, nothing is deployed: pick another with --name) and writes canica.json with the app's id (later deploys go to that app and ignore --name): commit it, so another machine or CI (CANICA_TOKEN from canica token create) deploys to the same app. Each app is a Cloudflare Worker with one SQLite Durable Object (all its data); its secret lives in the deploy service, not on your machine.

Free plan limits

There is one plan, free. Its limits keep the platform up for everyone:

What Limit Counted Past it
Requests 200,000 per app per UTC day HTTP requests and WebSocket messages that reach the app (uploads too; static files and file downloads do not), scheduled jobs 429 until the next UTC day
Changes 50,000 per app per UTC day client mutations, and actions' and scheduled jobs' mutations for a person LimitReached until the next UTC day
Database 1 GB per app the SQLite database's size changes refused (LimitReached), reads work
File storage 5 GB per app all uploaded files together uploads refused (StorageFull)
One file 25 MB each upload or ctx.files.store FileTooLarge
Image resizing 5,000 unique transformations a month, for the whole Cloudflare account (Cloudflare Images Free) each width of each image, once (then stored) sized links serve the original until the next month
Emails 100 per app per UTC day (yield* Email).send calls that were queued, once per email however many tries (the app counts, the mail relay counts again) EmailLimitReached (per: "app") until 00:00 UTC
Emails to one person 10 per app per person per UTC day the same, per recipient EmailLimitReached (per: "recipient")
Complaints 3, and at least 0.3% of what the app sent, in 30 days people marking its emails as spam the app may not send email until the operator resumes it
Bounces 10, and at least 5% of what it sent, in 30 days hard bounces the same
Deploys 50 per person per UTC day canica deploy runs that went live, by whoever deploys refused with a message until 00:00 UTC
Apps 10 personal apps per person, 25 per organization reserved names (deployed or not) canica deploy refuses a new one
Organizations 10 owned per person canica org create refuses
Secrets 50 per app, 5,000 bytes each canica secrets set refuses

Files

Apps with file() fields (see the guide) keep uploads in their own Cloudflare R2 bucket, canica-app-<name>-files, created by the deploy service on the first deploy that needs it and bound only to that app's Worker (the app's code runs there: a bucket shared by apps would let one read another's files). Uploads go from the Worker straight to the bucket (the app's Durable Object only grants a permit and records the file; a request without Content-Length gets 411, which browsers never send). File links are signed with the app's secret and served by the Worker (/_canica/files/<id>), on the app's origin, with nosniff, a sandboxing CSP and only safe types shown inline (images but SVG, PDF, audio, video, plain text; anything else downloads). Files no row refers to are deleted (24 h after upload if never stored). canica db purge of a file field deletes its files; canica delete empties and deletes the bucket. The dev server keeps them in .canica/files.

Sized links (files.url(id, { size })) are resized by Cloudflare's Images binding (IMAGES, bound with the bucket): each width of each image once, as WebP, stored next to it (<id>/w320.webp) and deleted with it, with the Cache API in front. Nothing to enable: the binding works on the account's Images Free plan (5,000 unique transformations a month, https://developers.cloudflare.com/images/pricing/) with the same token. Past that, or on an account that refuses the binding (the deploy then goes on without it and says so), sized links serve the original.

Email

Apps send typed templates to their own users (see the guide). Deployed, the app's Worker holds no provider key and is not trusted to check itself: it posts each email (the rendered body, the recipient's address and the sign-in proof) to the deploy service's mail relay (POST https://api.canica.app/v1/mail/send, authenticated with a token derived from the app's secret), which decides:

  1. Sending is on for the platform (EMAIL_MODE) and for this app (not suspended).
  2. The recipient signed in to this app: the sign-in service's assertion (ECDSA, addressed to the app's origin) that the app stored at their last Google sign-in names this address, which Google verified. Only a real sign-in gives it: sessions carried over (the v0.58 cookie move) or renewed have none. Without it send fails with NotARecipient (reason: "sign-in-again"); when it is the person's own email, canica/ui shows them a "Sign in again" button (the broker remembers consent: one tap, or none), which stores the proof.
  3. The app's access still lets them in (the platform's own list for org/private).
  4. They did not unsubscribe from this app or mark it as spam, and the address never hard-bounced (on any app).
  5. 100 emails a day per app, 10 a day per person.
  6. The frame: the app's name and icon above the body, the footer "You're getting this because you use · Unsubscribe", and the headers List-Unsubscribe: <https://mail.canica.run/u/…>, List-Unsubscribe-Post: List-Unsubscribe=One-Click (RFC 8058) and Auto-Submitted: auto-generated. The unsubscribe link is signed per app and address and served by the deploy service on mail.canica.run (that host serves nothing else): GET asks (link scanners do not unsubscribe anyone), POST unsubscribes, and the app is told so its next send fails with Unsubscribed.

It goes out From "<App name>" <<app>@mail.canica.run>, no Reply-To, through Cloudflare Email Service (REST, /accounts/{id}/email/sending/send). The platform's own domain (canica.app) never sends: a misbehaving app must not touch the reputation of sign-in and deploys. canica usage shows the day's emails, the sending mode, the last 30 days' bounces and complaints and whether the app is suspended; canica deploy prints a note when it is.

Why one sending domain, mail.canica.run, and not each app's own (noreply@todo-demo.canica.run)? Once canica.run is on the Public Suffix List, each <app>.canica.run is its own organizational domain for DMARC (RFC 7489), so a From there aligns only with DKIM d=<app>.canica.run: one onboarded sending domain per app. Cloudflare Email Service allows 30 sending/routing domains per zone (the apex included), and a wildcard sender signs with the base domain (d=canica.run), which would stop aligning. mail.canica.run aligns with its own DKIM before and after the PSL entry, needs one setup, and keeps app mail off the apex. The cost is a shared reputation, which is what the layers above protect (recipients who chose the app, low limits, one-click unsubscribe, suspension on complaints); the app's name is the display name and its address's local part, so mailbox filters and our logs tell apps apart. Per-app domains stay possible later (the relay's From is one line) if Cloudflare raises the per-zone limit.

Modes (pnpm platform deploy … --email outbox|send|off, kept in ~/.canica/platform.json):

Setting up Cloudflare Email Service (once, by the account owner):

  1. The account needs Workers Paid (Email Sending is not on Workers Free; 3,000 emails a month included, then $0.35 per 1,000).
  2. Dashboard → Compute → Email Service → Email Sending → Onboard Domain: mail.canica.run (the canica.run zone, on Cloudflare DNS, in the same account). Cloudflare adds and locks its records: MX and SPF on cf-bounce.mail.canica.run, DKIM on cf-bounce._domainkey.mail.canica.run, DMARC _dmarc.mail.canica.run (p=reject). Wait until it shows as verified.
  3. The API token in ~/.canica/cloudflare.env needs Email Sending: Edit (account) to send, and Queues: Edit for bounces and complaints; or put a separate token with those in CLOUDFLARE_EMAIL_API_TOKEN in the same file.
  4. Bounces and complaints: wrangler queues create canica-email-events; wrangler queues consumer http add canica-email-events (the deploy service pulls it); then Queues → canica-email-events → Subscriptions → Subscribe to events: source Email Sending, domain mail.canica.run, events message.bounced and message.complained. Its id: wrangler queues info canica-email-events.
  5. pnpm platform deploy --domain canica.app --apps-domain canica.run --email send --email-events-queue <id>.
  6. Check it: sign in again to an app that sends (the proof is stored at sign-in), send yourself one, and look at canica usage there.

Bounces, complaints, suspension. Every 5 minutes the deploy service pulls the queue's events. A hard bounce suppresses the address for every app; a complaint blocks that person for that app. An app with 3 complaints and at least 0.3% of what it sent in 30 days (or 10 hard bounces and 5%) is suspended: its sends are refused with the reason, the operator log (the deploy service's Workers logs) says [canica operator] email suspended for <app>: …, and its owner sees it in canica usage and on deploy. Cloudflare also keeps its own suppression list per sending domain; sends to it come back as bounced. The operator's switch: pnpm platform email suspend <app> <reason>, resume <app>, pull (read events now); --email off for every app.

How the queue works (four steps):

  1. (yield* Email).send(…) checks the recipient and the limits, writes the email to the app's _canica_emails (queued, with an id _emails_…) and a ~email job, and returns the id. Pages follow it with (yield* Email).status(id) in a query (live).
  2. The job (the Durable Object's alarm) renders the body and posts it to the relay (sending; leased for 10 minutes, so a Worker that stops mid-try is tried again).
  3. The relay keys on the email's id, per app: the first request decides (send, record in outbox mode, or refuse) and its answer is kept 7 days; a repeat gets that answer (replayed: true) and nothing is sent, logged or counted again; a repeat while the first is still out gets 503. The app records sent (recorded in outbox mode: the app's status says sent; only canica logs and the dev outbox tell them apart) or failed with the reason (unsubscribed, not-a-recipient, limit, bounced, complained, suspended, off, …).
  4. A try that gets no answer (a timeout after 30 s, the relay down, HTTP 5xx/429) is queued again with exponential backoff (2 min, 10 min, 50 min, ~4 h, 16 h: 6 tries in about 21 h), then failed (reason: "relay"). Refusals and permanent provider errors (502 with retry: false) are not tried again. Each try is a line in canica logs (email todayDigest (_emails_…) try 2 of 6 …).

Dev and tests never send: the dev server keeps an outbox at /_canica/dev/emails (dev only; the Worker answers 404), tests list what was sent with t.emails(), and the relay is only in deployed apps.

Where apps live: <name>.canica.run

Apps are served at https://<name>.canica.run; the platform itself stays at canica.app (auth. sign-in, api. deploys, mcp. the MCP for all your apps, get. the installer). They are two registrable domains on purpose: browsers draw security lines (cookies, SameSite, storage partitioning, site isolation) around the site, the registrable domain, so an app's code never shares a site with the services that sign you in and deploy. And once canica.run is on the Public Suffix List (see docs/psl.md in the repository), every <name>.canica.run is a site of its own as well: one app cannot set cookies for another or for the whole domain. Until then apps already never set a cookie on a parent domain (no Domain= attribute anywhere; the broker's is __Host-).

Apps deployed before v0.47 lived at <name>.canica.app. On their next canica deploy they move: the app gets <name>.canica.run, and <name>.canica.app stays attached but answers every request with a 308 to the same path and query on the new address (308 keeps the method and body, so POSTs and MCP calls follow it). Such an app runs its Worker before the static files on every request (otherwise pages on the old address would be served without the redirect). Things to know:

Organizations

An organization owns apps the way a person does; nothing is shared implicitly. Roles decide who manages an app, its access level (below) decides who uses it.

canica org create proxus --name "Proxus"      # you are its owner
canica org invite proxus ana@proxus.es --role admin   # member (default), admin or owner
canica org domain proxus proxus.es            # whoever signs in with an @proxus.es Google account joins as a member
canica org members proxus | list | remove proxus <email> | role proxus <email> <role> | delete proxus
canica deploy --org proxus                    # first deploy: the app belongs to the org
canica apps move my-app --org proxus          # an existing app (you manage it and administer the org); --personal takes it back

Secrets (for actions)

canica secrets set GITHUB_TOKEN     # asks for the value (hidden), or: printf %s "$TOKEN" | canica secrets set GITHUB_TOKEN
canica secrets list                 # names only
canica secrets unset GITHUB_TOKEN

The deploy service keeps them for the app (owners and org admins set, list and remove them) and binds each as CANICA_SECRET_<NAME> on the next canica deploy, where actions read ctx.secrets.<NAME>. Values are never shown.

Order for a new app: you can set its secrets before the first deploy. canica secrets set in a directory without canica.json reserves the app first (like the first deploy does: --name <name>, --org <slug>), so the first canica deploy already binds them. Changing a secret later takes effect on the next canica deploy.

Access: who may use an app

The code declares it, app({ access }) in server/index.ts (default signedIn); every canica deploy sends that level. The app's owner (or an org's admins) can choose another on the deployed app:

canica access              # shows it, and whether it is the code's or set here
canica access org          # public | signedIn | org | private: wins over the code from now on
canica access reset        # back to the code's level (as of the last deploy)

Which one wins: a level set with canica access stays across deploys, whatever the code says, until canica access reset; without one, each deploy applies the code's. canica deploy prints the level in force, and a note when it got stricter (public → signedIn, …). Leaving public strands guests' data: it stays in the database, but no guest session reaches it any more and signing in does not bring it back. Apps deployed before v0.51 were public by default: their next deploy makes them signedIn unless the code declares public (an org/private set with canica access stays).

The deploy service binds the level in force with its emails and domains on every deploy (CANICA_ACCESS), pushes it to the app (POST /_canica/admin/access, kept in its database) and pushes it again when the org's people or domain change. The app enforces it for everything that reads or writes data: pages (live queries and mutations get Unauthenticated or Forbidden), actions, uploads, its MCP and the approval of agents. Until a visitor may use it, every route shows the sign-in screen; someone signed in but not let in sees "You don't have access" with a way to switch account. Static files (the page's code) stay public; data does not. The dev server applies the code's level (with org/private letting in anyone signed in).

Agents (MCP)

Every app is also an MCP server at https://<name>.canica.run/_canica/mcp: its queries are read-only tools and its mutations are tools that change data, with their args as JSON Schema. It is Effect's McpServer in its stateless mode (MCP 2026-07-28): each request stands alone, so a query answers with the data of that moment, it does not stay live. Clients that only speak older protocol versions cannot connect.

To connect an agent, give it the URL (claude mcp add --transport http todo https://todo.canica.run/_canica/mcp, or the app's menu → Connect an agent). The agent follows standard MCP OAuth to the app itself: the app opens its "Connect an agent?" screen, with its own sign-in, and the person allows or denies. The agent then acts as that person, with the same access rules and daily limits as the app's pages. DELETE /_canica/auth/agent from the app's page (its session cookie) revokes every agent of that person. Browser sessions never work on the MCP endpoint: it takes only agent tokens (Authorization: Bearer cna_…). The dev server serves all of it too.

One MCP server for all your apps

https://mcp.canica.app/mcp (also at api.canica.app/mcp) offers every app you may use (yours and your organizations', within their access scope) as one flat list of tools, named <app>__<tool> (todo-demo__add), plus apps_list, app_logs, app_usage, app_rollback (owners and admins) and org_members.

claude mcp add --transport http canica https://mcp.canica.app/mcp

The agent connects with OAuth: the deploy service signs you in with Google and asks you to allow it. Its token (canica token list shows it as mcp: <client>; canica token revoke ends it) only opens the MCP, not deploys. A CLI token (canica token create) works as a bearer token too, for headless agents. Each call runs in the app as your Google account there (the same one you get by signing in to the app; it is created if you never did), with the app's own rules and daily limits. The service lists and calls an app's tools through its admin routes (GET /_canica/admin/tools, POST /_canica/admin/call); apps deployed with canica older than 0.43 offer none until they are deployed again.

Changing the schema (no migration files)

The schema in server/index.ts is the truth. The database is migrated at deploy, before the new version gets any traffic:

  1. The deploy service uploads the new version without serving it (a Cloudflare Worker version).
  2. The running app checks the new schema against the tables and the data (the plan) and applies it, in one transaction, recording the schema's hash.
  3. Only then does the new version serve every request. It finds the hash it expects and does no schema work when it starts (or wakes up).

canica deploy prints Migrating database… ok (2 changes) and the changes. If some rows do not fit, the migration fails, or the app cannot be reached, the deploy fails with the plan or the reason ("Not deployed: the database change failed; the app is still on the previous version."): the database is as it was and the previous version keeps serving. canica db plan shows the plan without deploying. The dev server does the same check when the schema changes and refuses a schema the data does not fit (the error appears in the browser).

Why the code serving now migrates, and not the new version: the database is one Durable Object, which runs one version at a time; a version that is not deployed cannot reach it (Cloudflare gives no preview URL to Workers with Durable Objects, and a gradual deployment assigns the one object to one version). So the old code applies the new schema (from its description) and keeps serving on it for the moment until the new version is live. That is safe because a plan only allows compatible changes: new tables, fields and indexes, hidden (not dropped) fields, and tightening only what the data already fits. The old code does not know the new columns, so it leaves them empty; the new version's first start fills the defaults of rows written in between (a tightened rule, though, is not checked again for rows the old code writes in those seconds). canica rollback relies on the same rule: older code runs on the newer schema as is.

Internal mutations are for backfills and maintenance; clients cannot call them:

export default app({
  queries: { … },
  mutations: { … },
  internal: {
    fillSlugs: mutation(function* () {
      const db = yield* Db
      const batch = yield* db.select().from(rooms).where(isNull(rooms.slug)).limit(100)
      for (const r of batch) yield* db.update(rooms).set({ slug: slugify(r.name) }).where(eq(rooms.id, r.id))
      return { done: batch.length < 100, processed: batch.length }
    }),
  },
})

canica run fillSlugs --batch runs it (as a system user) again and again while it returns done: false, each batch in its own transaction. canica run <name> '{"arg":1}' runs any mutation or action (internal ones too) once. Test them with t.run("fillSlugs"). canica db history lists the schema versions; each one keeps a restore point of the database from just before it was applied. Every canica db/canica run command talks to the deployed app, or to the dev server with --url <the URL canica dev prints> (e.g. --url http://localhost:5173; the port changes when it is busy).

Sign-in

People sign in with Google through the platform's sign-in broker (auth.canica.app): apps hold no OAuth secrets. The broker only sends people back to https://<name>.canica.run (exactly one label, https), the platform's own api./mcp.canica.app, the old <name>.canica.app addresses while they redirect, and dev servers at http://localhost:<any port> or http://127.0.0.1:<any port> (not [::1], LAN or Tailscale addresses).

Running the platform (operators)

From this repository, not the published CLI: pnpm platform (packages/platform, never published) deploys the platform's own Workers with Alchemy to your Cloudflare account. The canica CLI people install is only for making and deploying apps: it talks to the deploy service with a Canica token and never holds Cloudflare credentials.

Once per platform, with Cloudflare credentials in ~/.canica/cloudflare.env (CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_API_TOKEN) and Google's OAuth client in ~/.canica/oauth.env (after pnpm install):

pnpm platform deploy --domain canica.app --apps-domain canica.run --contact javier@proxus.es    # the whole platform
pnpm platform publish --domain canica.app     # the installer and package at get.canica.app
pnpm platform token <email>                   # a token for someone, without the browser sign-in
pnpm platform consents prune [--yes]          # forget consents to origins with no app (apps deleted before v0.64.1)

deploy deploys the whole platform, in the order each part needs the one before: the sign-in broker at auth.canica.app (its keys and platform.json), the deploy service at api.canica.app and mcp.canica.app (apps at <name>.canica.run), then Canica home at canica.app (and the apps zone's wildcard). Each is its own Alchemy stack (canica-auth, canica-api, canica-home), a no-op when nothing changed; the flags are saved in ~/.canica/platform.json, so later runs need none. A step that fails stops the run: run it again. publish stays apart: it releases the CLI, not the platform.

publish first runs the fresh-app check on the tarball it is about to upload, and uploads nothing if it fails: in a temp dir outside the repository, with an empty HOME, it installs the tarball as the CLI (as install.sh does), runs canica new (the app depends on that same tarball), then npm run typecheck, npm test, canica lint, canica build, and canica dev until /_canica/health answers (about a minute). --skip-fresh-check skips it; run it alone with node scripts/fresh-app-check.mjs [<tarball>] [--keep]. It catches what only shows outside the monorepo: files missing from the package, the template pointing at workspace paths, dependencies the workspace happens to provide. (canica new from a checkout, outside the repository, also packs the checkout this way rather than linking it: a file: link resolves canica's dependencies from the monorepo, giving tsc two copies of React's types.)

Canica home (src/platform/home.ts) is the platform domain's apex, https://canica.app: signed out, what Canica is, the install command, the guide (/guide, docs/GUIDE.md rendered at deploy) and Sign in with Google; signed in, your apps (yours and your orgs', grouped by org, with icon, access, last deploy and Open) and apps you use (the apps of others you allowed to sign you in, with Open and Revoke). It is a launcher, not a dashboard: nothing there changes an app. Its own Worker (stack canica-home), with no data of its own:

For apps' email, see Email (above): platform deploy --email outbox|send|off (default outbox), --email-domain (default mail.<apps domain>, attached to the deploy service for unsubscribe links) and --email-events-queue <queue id>.

The token also needs Workers R2 Storage: Edit (and R2 enabled on the account) for apps with files; platform deploy warns when it cannot manage R2, and such apps' deploys fail with that reason (nothing is deployed) until it can.

--apps-domain is saved in ~/.canica/platform.json (appsDomain) and used by the next commands; without it apps share the platform's domain (as before v0.47), which the CLI warns about. The apps domain must be an active zone in the same Cloudflare account, visible to the token in cloudflare.env: the deploy service gives each app a route there (<name>.<apps domain>/*, under the zone's wildcard). App names that the platform uses (api, auth, mcp, get, www, …) are reserved, on the apps domain too.

How names cannot collide. The deploy service's registry (one Durable Object, so two requests for one name never both win) gives a name once, at the first deploy: one DNS label of 3–32 lowercase letters, digits and dashes, never xx-- at the start (DNS keeps that for punycode, xn--…, which a browser may show as lookalike Unicode), not reserved, not taken, and not a deleted app's unless you (or your org) had it. Later deploys go by the app's id in canica.json, not by name. Deleting an app first asks the broker to forget everyone's consent to its hostnames (POST auth.<domain>/platform/forget, signed with HOME_SECRET). If the broker does not answer, nothing is deleted and you run it again. In Cloudflare, an app's hostname is its own route (and, in a zone without the wildcard, a custom domain after it). A route to another Worker that exists, or to none, is refused and nothing is bound. One left by a Worker that no longer exists is taken over.

How live queries update (and how to see it)

A query records what it reads, from the SQL it sends to SQLite (Drizzle's builders and raw sql alike, subqueries and CTEs included): for each table, the values of a col = value / col IN (…) condition joined with AND (messages.room="rooms_…", an id one preferred), or the whole table (messages) when there is none; SQL it cannot follow reads everything. A mutation records the rows it changed (SQLite triggers log the old and new values of every column, cascades included). The mutation replies as soon as it commits; right after, only the live queries that read something it wrote run again, once per distinct (user, query, args). A result that is the same as before (compared as values, not as text) is not sent; one that changed goes as a patch of the last one (rows by id: the rows that changed, the ids gone, where new ones go), or whole when that is smaller. The reply carries the commit's version, and the mutation's promise resolves once this page's live queries it affected show that version: a page always sees its own writes.

On the dev server, the dev tools (⚡ button bottom right, Alt+S, or ?devtools) show this tab's live queries (and how often each was updated), every mutation from any tab or user with the keys it wrote, which live queries re-ran (and whether their result changed), how many were not affected, sign-ins, and every live query on the server. examples/live is a small app made to explore this.