The technical guide. For what a Code App is and how the system as a whole works, see How Dapp Builder Works.
A Code Dapp is an app whose entire UI comes from a synchronized index.html — with any HTML, CSS and JavaScript you like. The files live as a document inside Dapp Builder, sync automatically to every member's devices, and run there inside a secure sandbox. You need no build step, no repository and no server: write code in the built-in editor, save — and every device immediately runs the new version.
The complete contract for coding agents — constraints, manifest schema, runtime API, checklist and a minimal working example — is published as plain Markdown at /agent-instructions.md (also served as /llms.txt). Paste that URL or its contents into any chat LLM, Claude Code, Cursor or similar and ask it to build your app; the file is self-contained and needs nothing else from this site.
index.html and manifest.yaml.index.html. The APIs described below ($store, $router, …) are available before your scripts run.manifest.yaml. Saving is enough — changes sync live to all devices.Your code runs in an iframe with an opaque origin: it has no same-origin access to Dapp Builder or any other page. Native dialogs (alert(), confirm(), prompt()) work. The runtime content security policy blocks external scripts, network requests, nested frames, forms and objects. Relative and HTTP(S) links open your app at the top-level tab (only via real user activation); javascript: and data: targets are stripped.
Importantly: your code never gets direct access to the Yjs documents, members or credentials — only the role-checked façade described below. Writes require an owner or editor role; viewers read. Editing source code is owner-only.
Dapp.onReady()Dapp.onReady((context) => {
// context.meta — name, icon, color
// context.role — framework role ('owner' | 'editor' | 'viewer')
// context.identity — this device's identity
// context.roles / context.appRole — declared & assigned app roles
})
$data — simple JSON stateawait $data.set('count', 1)
const count = await $data.get('count')
const snapshot = await $data.snapshot()
const unsubscribe = await $data.subscribe((state) => { /* ... */ })
Keys up to 128 characters, values JSON-serializable up to 256 KB. Synced via the dapp document.
$store — record collectionsconst tasks = await $store.query('Tasks', { status: 'open' })
const task = await $store.create('Tasks', { title: 'Test' })
await $store.update('Tasks', task.id, { status: 'done' })
await $store.delete('Tasks', task.id)
const unsubscribe = await $store.subscribe('Tasks', { status: 'open' }, (records) => { /* ... */ })
Collection names are created lazily on first write; existing schema entities (name or UUID) stay compatible. Subscriptions filter by field values.
$router — navigation$router.current() // current route, e.g. '/tasks'
$router.search() // query string including '?'
$router.query('task') // single parameter or null
await $router.navigate('/tasks')
const unsub = $router.subscribe((path) => { /* toggle views */ })
$router.chrome() // 'standard' | 'fullscreen'
await $router.setChrome('fullscreen')
Only routes declared in the manifest are reachable (hidden ones included). Sidebar navigation, browser back/forward, shared links and in-app navigation all change the same route without restarting the app. Chrome switching preserves JavaScript state.
$events and $actions — app-to-app wiring// Sender (event id must be declared under manifest.bindings.events)
await $events.publish('game.move', { from: 'e2', to: 'e4' })
// Receiver (action id must be declared under manifest.bindings.actions)
const unregister = await $actions.handle('game.move.apply', async (payload, { deliveryId }) => {
/* ... */
})
Connections between two Code Dapps are approved per pair in Settings → Code App Bindings. Payloads are validated against the schemas declared in the manifests, and projected if the source declares one.
$roles — your own app rolesconst mine = $roles.current() // { id, label, extends } | null
const declared = $roles.list() // roles from the manifest
const assignments = await $roles.assignments() // owner/editor
await $roles.assign(publicKey, 'player') // owner only
$ui, $contacts, $share — requesting framework surfacesawait $ui.openCodeEditor({ file: 'index.html' }) // owner only
await $ui.openSettings({ section: 'sharing' })
const contacts = await $contacts.pick() // only user-picked contacts
await $share.open() // opens the framework's share surface
Each of these calls must be enabled under permissions.host in the manifest (see below), otherwise it fails. Calls resolve when the opened surface closes again; { opened: false } means politely declined (e.g. a dialog was already open).
# Comments are welcome — the manifest is YAML (JSON also parses).
name: Task Manager
routes:
- path: /
label: Overview
icon: home
- path: /tasks
label: Tasks
icon: list
- path: /internal # reachable by navigate(), hidden from the nav
label: Internal
icon: settings
hidden: true
roles:
- { id: player, label: Player, extends: editor }
- { id: spectator, label: Spectator, extends: viewer }
display:
chrome: standard
permissions:
host: { settings: true, contacts: true, sharing: true }
| Field | Meaning |
|---|---|
routes | 1–32 routes. Paths start with /, URL-safe, no query/hash/... Icons: home, list, dashboard, settings, code. "hidden": true only hides a route from the sidebar — it stays reachable by URL and $router.navigate() (presentation, never access control). |
roles | Up to 16 app roles. extends is required and is a ceiling: a role extending viewer cannot write — whatever your app logic does. Enforcement always uses the real framework role; app roles are labels for your own logic. |
display.chrome | "standard" (with sidebar) or "fullscreen". URLs always win: /dapp/:id/app/… shows chrome, /dapp/:id/full/… hides it. In fullscreen a framework-rendered return button appears that your app's DOM cannot remove. |
display.frameButton | false hides that fullscreen return button (default true). The /app URLs and $router.setChrome('standard') still work. |
permissions.host | Enables $ui.openSettings/$ui.openCodeEditor plus $contacts.pick() and $share.open(). Without the flag: failure (fail-closed). |
Role assignments are made by the owner via $roles.assign(); they are Ed25519-signed into the dapp document and verified on every device like member changes.
From the dapp settings you can export a signed .dapp file: metadata and source code - never records, members or credentials. Import on the home page verifies signature and fingerprint, shows a mandatory capability preview, and installs with fresh credentials and an empty data set. Once installed as an app, Dapp Builder also opens .dapp files directly from your file manager.
An owner can also create a reusable 24-hour source-share link from dapp settings. It transfers a signed definition through a temporary peer-to-peer room without adding the recipient to the original dapp. After reviewing the source and permissions, the recipient can install it as a new dapp or replace only the source and manifest of a dapp they already own; that dapp's data and members stay in place.
When sharing a dapp with a contact you can attach the package directly: it travels signed and encrypted inside the relationship control channel, stays inert in the recipient's inbox until they choose "Review attached app" and consciously install. Only then is the channel bound to the newly created local dapp.
The home page ships four complete, editable apps — the fastest way to working patterns for $store CRUD, routes, events, channels and image handling:
$store collections, CRUD with subscriptions, routes, a typed event.settle-up app role.All starters use minimum 44 px touch targets, single-column layouts below 560 px width and explicit type="button" handlers — good examples for your own apps, especially on phones.
index.html; routes toggle views within that one app. Additional files (custom .js/.css/assets) are prepared for (file map in the source document), but the editor currently offers index.html and manifest.yaml.