Canica

Canica

Canica is a framework and a place to run what you build with it: a TypeScript app with a live database, Google sign-in, files, email and HTTP endpoints, deployed with one command to https://<name>.canica.run. It is strict on purpose: one way to do each thing, checked by types, lint and tests, so a coding agent (or you) writes apps that work the first time.

Install

curl -fsSL https://get.canica.app | sh

A first app

canica new my-app      # a small guestbook to start from, with AGENTS.md for your agent
cd my-app
npm run dev            # http://localhost:5173: the app and its backend, one port
canica login           # once, with Google
canica deploy          # typecheck, lint, tests, build, migrate, deploy → https://my-app.canica.run

What an app is

my-app/
  server/index.ts      tables, queries, mutations, actions, endpoints, crons: the whole backend
  shared/fields.ts     fields both sides validate with (a title's length, an email)
  src/routes/          one file per page: index.tsx is /, rooms/$room.tsx is /rooms/:room
  src/components/      modals and pieces of pages
  src/app.test.tsx     tests: the server's handlers and scenes that click through pages
// server/index.ts
import { mutation, query, schema, string, table, userId, Viewer, desc, eq } from "canica/server"

export const { app, Db, tables } = schema({
  notes: table({ owner: userId(), text: string().trim().min(1) }).index("by_owner", ["owner"]),
})
const { notes } = tables

export default app({
  name: "Notes",
  queries: {
    // Live: every page showing it updates when a note is added, anywhere.
    mine: query(function* () {
      const viewer = yield* Viewer
      return yield* (yield* Db).select().from(notes).where(eq(notes.owner, viewer.userId)).orderBy(desc(notes.createdAt)).limit(50)
    }),
  },
  mutations: {
    add: mutation({ text: string().trim().min(1) }, function* ({ text }) {
      const viewer = yield* Viewer
      yield* (yield* Db).insert(notes).values({ owner: viewer.userId, text })
    }),
  },
})
// src/routes/index.tsx
import { page, useQuery } from "canica/client"
import { ErrorState, Item, ItemContent, ItemGroup, ItemTitle, Loading, PageHeader } from "canica/ui"

export default page({
  title: "Notes",
  view: () => {
    const notes = useQuery("mine")
    return (
      <section className="flex flex-col gap-6">
        <PageHeader title="Notes" />
        {notes.match({
          loading: () => <Loading shape="list" />,
          failure: (error) => <ErrorState error={error} />,
          success: (list) => (
            <ItemGroup>
              {list.map((note) => (
                <Item key={note.id} variant="outline">
                  <ItemContent><ItemTitle>{note.text}</ItemTitle></ItemContent>
                </Item>
              ))}
            </ItemGroup>
          ),
        })}
      </section>
    )
  },
})

The names are typed end to end: useQuery("mine") knows what mine returns, useMutation("add") what it takes and which errors it can fail with.

The pieces

What it is for Where
Queries Reading. Live: pages re-render when what they read changes. Server
Mutations Writing, in a transaction. No network, no clock of their own: deterministic. Server
Actions The outside world: fetch, typed OpenAPI clients, secrets; then a mutation saves the result. Server
Endpoints HTTP from other servers at /api/…: webhooks, scripts, other apps. Server
Crons and the scheduler Work every 15 minutes, or in an hour. Server
Pages File-based routes, live queries, forms in modals, canica/ui components. Client
Access Who may use the app: anyone signed in, your organization, people you add, or everyone (guests too). Access
Files Uploads, image sizes, signed links. Files
Email Templates in React, sent from mutations and actions. Email
Tests testApp for handlers, scenes for pages, all in-memory. Tests
Storyboard Every page, modal and state as one canvas of screenshots. Storyboard
MCP Every deployed app is a tool your agent can use, with your permission. Deploy

Where to go next