# Cloudbed

An agent-native platform for building and deploying small full-stack TypeScript apps — **capsules** — in one command. Write a server contract and a Preact client, run `cloudbed deploy`, and get a live URL in seconds. Built to be driven by coding agents as much as by people: every CLI command speaks `--json`, and every deploy is inspectable.

## Quick start

```sh
npx cloudbed new my-app --template todo   # or --template guestbook
cd my-app
npx cloudbed dev                          # local runtime at http://localhost:3000
npx cloudbed deploy                       # live anonymous URL, no account needed
```

`cloudbed dev` runs the **same runtime code** that serves in production, under local `workerd` — so dev behaves like prod, and local state survives restarts (`--fresh` resets it).

## What a capsule is

```
server/index.ts        schema, queries, mutations, HTTP endpoints
client/index.tsx       the Preact UI (exports an App, renders into #app)
shared/                pure TypeScript shared by both sides
.env.cloudbed.server   optional server-only env (claimed deploys only)
```

The server is authoritative: queries decide what a client may read, mutations validate and re-check ownership before they write. The client subscribes to queries over a WebSocket and gets live updates pushed after every write.

```ts
// server/index.ts
import { capsule, mutation, query, string, table } from "cloudbed/server";

export default capsule({
  schema: { todos: table({ text: string(), ownerId: string() }) },
  queries: {
    todos: query((ctx) => ctx.db.todos.where("ownerId", ctx.auth.userId).all()),
  },
  mutations: {
    addTodo: mutation((ctx, text: string) =>
      ctx.db.todos.insert({ text, ownerId: ctx.auth.userId })),
  },
});
```

```tsx
// client/index.tsx
import { render } from "preact";
import { useMutation, useQuery } from "cloudbed/client";

function App() {
  const todos = useQuery("todos") ?? [];
  const addTodo = useMutation("addTodo");
  // render the list, call addTodo(text)
}
render(<App />, document.getElementById("app")!);
```

Every capsule gets:

- **A live database** — declare tables in the schema; rows carry server-managed `id`, `createdAt`, `updatedAt`. See the [server SDK](/server).
- **Live queries** — `useQuery` re-renders automatically after any mutation. See the [client SDK](/client).
- **Sign in with Google, zero registration** — the auth broker issues short-lived tokens scoped to your app's origin, with per-app pairwise user ids so apps can't correlate users.
- **HTTP endpoints** — for webhooks and non-browser clients.

## How deploys work

Your first `cloudbed deploy` needs no account and returns a URL on `*.cloudbed.app`. Anonymous deploys are sandboxed — no outbound `fetch`, no server env — and expire after 7 days. **Claiming** a deploy to your account lifts both and makes it permanent. See [Deploys & limits](/deploys).

## Where to go next

- [CLI reference](/cli) — every command and flag
- [Server SDK](/server) — schema, queries, mutations, endpoints
- [Client SDK](/client) — hooks, auth, routing
- [Deploys & limits](/deploys) — anonymous vs claimed, tokens, custom domains, quotas

For agents: every page here is also raw markdown (append `.md`), indexed at [/llms.txt](/llms.txt).
