# BackendShare

> Zero-signup app hosting for AI agents. One CLI command, one MCP tool call, or one REST request turns files into a live HTTPS URL with a SQL database, file storage, message queues, a cache, end-user login and AI. Humans take ownership of (claim) the app later.

## Quick start (zero signup)
<a id="quick-start"></a>

CLI, in any project directory, no account needed:
  npx -y https://api.backendshare.com/cli.tgz deploy
It runs a short anti-spam check (a proof of work, ~5 s of computation; this replaces signing up), creates a temporary account and app kept for 72 hours, publishes it, and prints the URL, an access key (token, saved to ~/.config/backendshare/credentials.json) and a claim link: the human owner opens it to take ownership of the app. Run it again to redeploy.

MCP (Streamable HTTP): add the server URL https://api.backendshare.com/mcp and call the `deploy` tool with your files. No access key (token) is needed for the first call; keep the returned token for later calls.

REST, one request: POST https://api.backendshare.com/v1/deploy {"name":"demo","files":[{"path":"index.html","content":"<h1>hi</h1>"}],"tos_accepted":true,"pow":{...}}. Without a token the first response is 422 E_POW_INVALID containing an anti-spam challenge; solve it (see "Anti-spam check") and resend.

## What gets deployed
<a id="what-gets-deployed"></a>

Static files (index.html, CSS, browser JS, images) are served from a global network close to visitors.
Backend code (a serverless function) becomes your API: an ES module exporting `export default { async fetch(request, env, ctx) { ... } }`. Entry: build.entry in backendshare.json (appshare.json is still read), else worker/index.ts|js, src/index.ts|js, worker.ts|js, _worker.js, or a root index.js that has `export default`. The CLI bundles TypeScript and npm dependencies with esbuild; TypeScript sources and config files are never published.
GET/HEAD requests that match a static file are served first; everything else goes to fetch().
Your URL: https://<app_key>.backendshare.com (see "App address").

## What your code can use (env)
<a id="bindings"></a>

env.DB      – SQL database (SQLite), one per app. env.DB.prepare("select 1").all()
env.FILES   – file/object storage (S3-compatible API), one per app. await env.FILES.put("a.txt", "hi")
env.<QUEUE> – message queue for each queues[] entry: send jobs now, process them in the background by exporting `queue(batch, env)`.
env.<DO>    – real-time state objects (one strongly consistent instance per id, e.g. a chat room or counter) for each durableObjects[] entry; export the class from your module.
env.AS.cache.get/put/delete(key, value, {ttl}) – key-value cache (changes can take up to a minute to appear everywhere).
env.AS.ai.chat({model, messages, max_tokens}) – AI chat completion in OpenAI format (apps that have been claimed only).
env.AS.auth.getUser(request) – signed-in end user {id, email} or null (see Sharing).
env.BACKENDSHARE_URL (public app URL), env.BACKENDSHARE_PROJECT, env.BACKENDSHARE_ENV (the older APPSHARE_* names hold the same values), plus your vars and secrets.

## backendshare.json
<a id="manifest"></a>

{
  "name": "my-app",
  "build": { "command": "npm run build", "output": "dist", "entry": "src/index.ts" },
  "database": { "migrations": "./backendshare/migrations" },
  "queues": [{ "name": "jobs", "binding": "JOBS", "maxRetries": 3, "deadLetter": true }],
  "durableObjects": [{ "binding": "ROOM", "className": "Room" }],
  "access": { "mode": "private", "emails": ["me@example.com"] },
  "secrets": ["STRIPE_KEY"],
  "vars": { "MODE": "prod" }
}
Every field except name is optional. "queues" are message queues, "durableObjects" are real-time state objects (see above). appshare.json and ./appshare/migrations from older projects are still picked up. Database migrations are NNNN_name.sql files applied once, in order; editing one that already ran fails with E_MIGRATION_DRIFT.

## App address
<a id="app-address"></a>

Every app gets its own subdomain: https://<app_key>.backendshare.com. The app_key is unique per app and unguessable (a readable prefix plus 10 random characters, e.g. https://my-notes-k3x9p2m7qa.backendshare.com) and is always a valid DNS label; platform names (www, api, admin, app, mail, docs, status, cdn, static, mcp, send, …) are never used. Each app is its own browser origin, so localStorage, cookies and service workers are isolated from other apps, and root paths ("/", "/api") work as written: no base path configuration is needed.
Your backend code sees the public URL in request.url; env.BACKENDSHARE_URL holds it too. Cookies your app sets are host-only (any Domain attribute is removed), so they never reach other apps or the platform hosts. Apps on backendshare.com are same-site with each other, so SameSite cookies do not stop requests from another app; check the Origin header for state-changing requests. Old https://<slug>.workers.dev addresses redirect (308) to the new one.

## Sharing and end-user login
<a id="sharing"></a>

Apps are public by default. Make one private with `backendshare share a@x.com,b@y.com` (or --domains corp.com), PUT /v1/projects/{id}/access, or the MCP `share` tool. Visitors sign in with an email code at <app URL>/_as/auth/login and the platform enforces the list; your code needs no auth logic. Inside fetch(), read the user with env.AS.auth.getUser(request).

## Claiming: handing the app to its owner
<a id="claiming"></a>

Apps published without an account are temporary and live 72 hours. To keep one, a human takes ownership ("claims" it): give them the claim URL, or the code (valid 15 minutes) to enter at https://api.backendshare.com/claim. After they sign in with an email code and claim: the temporary access key stops working, the app's internal credentials are replaced, the app keeps its URL, and the agent collects a permanent access key (project token) with `backendshare claim` (polls POST /v1/claims/poll) or the MCP `claim` tool.

## CLI
<a id="cli"></a>

npx -y https://api.backendshare.com/cli.tgz <command>
deploy [dir] [--name n] [--project p] [-m msg]   publish without signing up; reuses the saved access key
init [dir]                 starter: static page + backend code + SQL database migration
claim [--wait]             link/code for the human to take ownership; saves the new access key once claimed
whoami | projects | deployments | logs | usage | open
rollback [version]
secrets [set KEY VALUE | rm KEY]      (value may be piped on stdin)
share a@x.com,b@y.com [--domains corp.com] | share --public
db query "select …"
tokens [create --scopes deploy,project:read | revoke ID]
login [--wait] | logout | delete --yes | mcp | pow '<challenge json>'
Output is JSON when stdout is not a terminal (--json / --human to force). Exit codes: 0 ok, 2 invalid input, 3 auth, 4 scope/plan, 5 payment, 6 not found, 7 conflict, 8 rate limit / anti-spam check / daily quota, 9 prepublish check, 10 deploy failed.

## Anti-spam check (proof of work)
<a id="proof-of-work"></a>

Instead of a signup form, a deploy without an account must show it spent a few seconds of computation; the CLI, MCP server and website do this for you. Only REST clients implement it:
POST https://api.backendshare.com/v1/signup/challenge → {challenge_id, seed, k, g}. c0 = SHA256(base64url_decode(seed)); for i in 1..k: c_i = SHA256 applied g times to c_{i-1}. checkpoints = base64url(c0‖c1‖…‖ck) (32·(k+1) bytes). Submit {challenge_id, checkpoints} within 5 minutes (single use). About 3–5 s in Node; or run `npx -y https://api.backendshare.com/cli.tgz pow '<json>'`.

## REST API
<a id="rest"></a>

Base https://api.backendshare.com/v1, Authorization: Bearer <token> (an access key: as_anon_… temporary app, as_proj_… one app, as_acct_… whole account). Errors: {"error":{"code","message","fix_hint","next_command"}}.
POST /deploy (one-shot) · POST /signup/challenge · POST /signup {email} · POST /signup/verify
GET /me · GET/POST /projects · GET/DELETE /projects/{id}
POST /projects/{id}/deployments {manifest, files:[{path,sha256,size}]} → PUT /blobs/{sha256} for missing → POST /deployments/{id}/finalize
GET /deployments/{id} · POST /projects/{id}/envs/production/rollback · GET /projects/{id}/logs
PUT /projects/{id}/secrets/{NAME} {value} · PUT /projects/{id}/access · POST /projects/{id}/db/query {sql, params}
GET /usage · GET/PUT /projects/{id}/payg {enabled, daily_cap_usd} · GET/POST/DELETE /tokens · POST /claims/code · POST /claims/poll · POST /oauth/device · POST /oauth/token
GET /ai/models · POST /ai/v1/chat/completions (runtime credential) · POST /abuse/reports

## Limits
<a id="limits"></a>

Free plan (claimed account): up to 3 apps (each one backend service) per account; 5,000 dynamic requests per app per day and 10,000 per account per day (all apps combined); SQL database 100 MB, file storage 1 GB, AI trial $1/month.
Temporary (not yet claimed): 1 app, kept 72 hours, 1,000 dynamic requests/day, SQL database 50 MB, file storage 200 MB, no AI.
Only dynamic requests count: requests your backend code answers, and any non-GET request. Static files (HTML, JS, CSS, images), OPTIONS and HEAD requests, the platform's own notice pages and login redirects are not counted; static files only have an anti-abuse ceiling (50,000 per app per day on the free plan, 10,000 for temporary apps).
Usage within a plan's quotas is never billed. Daily counters reset at 00:00 UTC. At 80% of a quota the owner gets a usage alert. Pay as you go: while the account balance is above zero and the app has it on (default on, at most $5 per app per day), usage past a quota keeps working and is charged from the balance — dynamic requests $3 per million, storage per GB-month, AI past the monthly credit at cost × 1.3 (prices: https://backendshare.com/#pricing). Set it per app with GET/PUT /v1/projects/{id}/payg {enabled, daily_cap_usd}, the MCP tool payg or `backendshare payg`. Without a balance (or with pay as you go off, or the daily cap reached), the app keeps working for a further 20% grace after 100%; then dynamic requests answer 429 with error code E_QUOTA_EXCEEDED and a Retry-After header until the reset, while pages and static files keep loading. Browsers get a page that explains it, API clients get JSON with a fix_hint: claim the account (temporary apps), top up the balance, turn pay as you go on or raise its cap, or upgrade to a higher plan (https://backendshare.com/#pricing). Creating an app beyond the app limit fails with E_PLAN_LIMIT; when the platform has no database capacity left for a new app, creation fails with E_PLATFORM_CAPACITY (503) before anything is created. Containers and custom domains are not available yet.

## Under the hood
<a id="under-the-hood"></a>

BackendShare runs on Cloudflare. If you know those products: backend code = Workers, SQL database = D1, file/object storage = R2, message queues = Queues, real-time state objects = Durable Objects, key-value cache = Workers KV, AI = Workers AI. You never need a Cloudflare account; every resource is created and isolated per app by the platform.

## Runnable examples

- [Deploy a feedback board with a persistent SQL database](https://backendshare.com/examples/feedback-board)
- [Add safe file collection to an agent-built app](https://backendshare.com/examples/file-drop)
- [Deploy a webhook inbox for synthetic JSON events](https://backendshare.com/examples/webhook-inbox)

