Caffeine App (build from scratch)
Caffeine (caffeine.ai) builds and hosts full-stack apps on the Internet Computer: a
single Motoko backend canister plus a React/Vite frontend served as an assets
canister. This skill teaches the exact project shape and the CLI build loop so
you can produce a buildable Caffeine app from nothing.
**This skill owns the project shape and the build workflow. It does NOT own the Motoko
language.** Before you write or edit any backend code, fetch and follow the writing-motoko
skill: <https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md>. That skill is
authoritative for actor syntax, stable state, mo:core, and compiler errors. This
skill only shows the minimal empty actor and where it lives.
When to use this skill
- Creating/scaffolding a new Caffeine app or caffeine.ai project from scratch.
- Writing or fixing
caffeine.toml(workspace or canister manifest) ormops.toml. - Running the caffeine CLI loop:
auth login,doctor,install,check,preview.
Do not use it for Motoko language details (use writing-motoko) or for raw IC/dfx/icp
deployment (use icp-cli). Caffeine apps are built and deployed through the caffeine
CLI and the caffeine.ai web app, not through dfx.
Critical facts
- There is no
caffeine init/caffeine new. "From scratch" means you create the
files in this skill by hand, then run the build loop. (caffeine projects clone <id>
only downloads an existing cloud project, and caffeine projects import <zip> only
unpacks a project archive such as one made by caffeine export; neither is a
greenfield scaffold.)
- Exactly one backend canister, and it must be named
backend.mops.tomldeclares
a single [canisters.backend].
- The frontend↔backend binding files are generated, never hand-written.
src/frontend/src/backend.ts and src/frontend/src/declarations/ are produced by
caffeine-bindgen during the build. Editing them is pointless — they are overwritten.
- Deploying to a live URL is done in the caffeine.ai web app, not the CLI. The CLI
takes you as far as a built draft (caffeine preview --build, which needs a cloud
project.id — see the build loop). There is no caffeine deploy/publish command.
Prerequisites (run once)
# Install the CLI (public npm package). The binary is `caffeine`.
npm install -g @caffeineai/cli
# Authenticate against caffeine.ai. Opens a browser; without one (or with --device) it
# uses the device flow. On a host with no OS keychain (headless Linux, containers), add
# --insecure-storage to keep the token in ~/.caffeine/tokens.json (mode 0600) instead.
caffeine auth login
caffeine auth status
# Check the environment: Node, pnpm, mops, caffeine-bindgen, that you are logged in,
# and that the Caffeine API is reachable (installs what it can).
caffeine doctor --fix
If a global install is undesirable or fails, run every caffeine command through an
npx -y @caffeineai/cli@latest prefix instead — e.g. npx -y @caffeineai/cli@latest auth status.
caffeine doctor requires Node.js 20 or later (the template's engines field asks for
>=20.19.0) and checks pnpm, mops (2.13.0 or later), caffeine-bindgen, your login,
and whether the Caffeine API is reachable. With --fix it installs a missing pnpm, a
missing or outdated mops (ic-mops), and a missing caffeine-bindgen
(@caffeineai/bindgen) with npm install -g; it does not install Node.js. It does
not install the Motoko compiler (moc) or linter (lintoko): mops fetches those
automatically from the [toolchain] pins in mops.toml. On Windows, compiling Motoko
requires WSL. dfx is not part of the Caffeine build.
Project shape
A Caffeine app is a pnpm workspace with a root manifest and two canisters. Create this
exact tree (file contents below):
my-app/
├── .old/src/backend/dist/
│ └── backend.most # stable-signature baseline — seed with an empty actor (see below)
├── caffeine.toml # root workspace manifest — MUST contain [workspace]
├── mops.toml # Motoko build config — ONE per project, at the root
├── package.json # pnpm workspace root + the `bindgen` script
├── pnpm-workspace.yaml # declares src/**/* as workspace packages
├── tsconfig.json # root TS config
└── src/
├── backend/ # the single Motoko canister, named "backend"
│ ├── caffeine.toml # canister manifest: type = "motoko"
│ ├── main.mo # actor entry point (write with the `writing-motoko` skill)
│ └── migrations/ # enhanced-migration chain (see the `mops.toml` notes)
│ └── 00000000_000000.mo # first migration: initializes the actor's stable state
└── frontend/ # the assets canister (React + Vite)
├── caffeine.toml # canister manifest: type = "assets"
├── package.json # frontend deps + scripts (see references/frontend-template.md)
├── vite.config.js # (see references/frontend-template.md)
├── tsconfig.json # (see references/frontend-template.md)
├── biome.json # (see references/frontend-template.md)
├── tailwind.config.js # (see references/frontend-template.md)
├── postcss.config.js # (see references/frontend-template.md)
├── index.html
├── env.json # runtime config — copied into dist/ on build
├── public/ # static files served as-is (for example favicon.ico)
└── src/
├── main.tsx # React entry (providers)
├── App.tsx
├── index.css
├── backend.ts # GENERATED by caffeine-bindgen — do NOT edit
└── declarations/ # GENERATED by caffeine-bindgen — do NOT edit
Only the root manifest, the two canister manifests, mops.toml, main.mo, and
the small root config files are shown inline below. The full frontend boilerplate
(package.json, vite.config.js, the Tailwind/PostCSS/Biome configs, index.html,
env.json, main.tsx, a starter App.tsx) is in