The app platform's design
Leafen's code cites the app platform's design by section — for example "docs/app-platform.md 16" or "T5". This page keeps those numbers: each section says in a few lines what that part of the design settles and links to where Building Leafen apps describes it for an app's author. The guide is the full description; where the two seem to differ, the guide is right.
1. What it builds on
Apps reuse what Leafen already has rather than a second system: accounts without a person for an app's account, the native API's key scopes and route table for what an app may reach, the outbound address checks for its relay, durable jobs and schedules for its workers, realtime rooms, history and undo, the administrator settings' encryption for its secrets, and backup and restore. Architecture describes the server they belong to.
2. The package and its manifest
An app is a .leafenapp zip — a manifest, a screen, workers, data setup and an
optional Ed25519 signature — fixed at install by a fingerprint over its files.
See What an app is and The manifest.
3. Installs, organizations and permissions
An app is installed once per server. Each organization that uses it gets its own app workspace and data, and the administrator chooses who there may use it and approves exactly what it may reach. See What an app is and The manifest.
4. The screen: a sealed frame and its channel
The screen runs in a frame with no origin and talks to Leafen only through one channel; Leafen draws the app's header, its confirm windows and its full window outside the frame. See The screen.
5. Three ways an app acts, and approvals
An app acts as the person (a short-lived token narrowed to what was approved), as the app (an action run by a worker as the app's account) or on its own (schedules, webhooks, data changes, room messages). See What an app is and Actions and approvals.
6. The app workspace and its data
The app's account owns a workspace per organization, holding the databases, pages and views the manifest declares, kept by stable keys across versions. See Data.
7. Reaching outside
The screen reaches only the addresses the manifest names; requests that need a secret, and private addresses an administrator allows, go through Leafen's relay. See Reaching outside.
8. Outside sign-in and secrets
Outside accounts connect through Leafen, which keeps their tokens and the app's secrets on the server and fills them into relayed requests; the app never sees them. See Reaching outside and Security notes.
9. Rooms, the temporary store and public guests
Realtime rooms, a temporary key-value store, and guests who join through a link with no Leafen account and no access to Leafen's data. See Rooms, the temporary store and guests.
10. An action is defined once
One action in the manifest is a button on the screen, an agent's tool and an automation's step, run by the same worker function under the same rules. See Actions and approvals.
10-1. Where an app adds to Leafen
Besides its own screen: blocks and side panels, lines in the "/" menu and in a row's or a page's "…" menu, and property editors — each declared, approved at install, and gone when the app stops. See Blocks and panels, Menu lines and Property editors.
11. Server workers
Workers are WebAssembly modules (the Extism calling convention) run in a separate process with no files, network or environment of their own; they reach Leafen and the outside only through host functions. See Workers.
12. Room and connection workers
Longer-running workers for a room's rules or a connection with no webhook, within limits, reaching outside only through the sockets the manifest lists. See Workers and Reaching outside.
13. Agents
An app's actions marked as tools, and its instructions, reach the agents connected to Leafen. See Agents.
14. HTML in a page
An uploaded HTML file shows in a page in the same sealed frame, with no channel and no access to Leafen, under a "User HTML" mark that an organization can turn off. See Embed.
15. Budgets and running apps
Leafen's own work comes first: apps run within budgets for the whole server, for each app and for each person using it, an app refused too often is stopped, and administrators see each app's use. A person sees what an app read with their access. See Budgets and What people see.
16. Distribution, the catalog and revocation
Built-in apps, the official catalog and packages installed from a file; signed lists, and a revoked version stops. See Distribution.
17. Addresses, links and home-screen apps
An app's screens have addresses of their own under /apps/, open from links
and from a home-screen icon. See The manifest (pwa)
and Architecture.
18. The SDK, the CLI and the documents
The SDK in sdk/app, the leafen app commands and this guide. See
Quick start and
Versions and compatibility.
19. Milestones
Not kept here: each release's notes say what it adds.
20. Threat model
Who the design guards against: an app's author who means harm or was broken into, a person using an app to go past their rights, public guests and the open web, instructions hidden in what an app reads, and whoever tampers with how packages are delivered. What it keeps: the bounds of what each person may reach in Leafen, sessions, tokens and secrets, private networks, Leafen's own availability, history and undo that tell the truth, and a screen that doesn't deceive. The code names each threat by its number.
| # | Threat | Where its guard is described |
|---|---|---|
| T1 | The frame escapes its seal: reads Leafen's storage, moves the top window, opens an unsealed pop-up | The screen |
| T2 | Another frame or document sends commands to the screen's channel | The screen |
| T3 | Relayed requests into a private network, by name, by redirect or by a name that changes where it points | Reaching outside |
| T4 | A worker gets out of WebAssembly or its process, or reaches the server's files and resources | Workers |
| T5 | A changed, unknown or revoked package, or code loaded from elsewhere | What an app is, Distribution |
| T6 | A secret leaks through the screen, a worker, a log or a backup | Reaching outside, Security notes |
| T7 | Data leaves through an address or a connection the manifest doesn't name | Reaching outside |
| T8 | Instructions or tools that steer an agent wrong | Agents |
| T9 | Public guests who flood a room, send spam or reach for Leafen's data | Rooms, the temporary store and guests |
| T10 | An app that uses up the server and stalls Leafen | Budgets |
| T11 | An app that imitates Leafen's sign-in or confirm windows | The screen, Actions and approvals |
| T12 | Rights wider than the person's, a write to a locked database, the app account's rights borrowed by a person | What an app is, Data |
| T13 | An approval used twice, or for another input or action | Actions and approvals |
| T14 | One organization's app data reaching another | What an app is, Data |
| T15 | A forged or replayed incoming webhook | Reaching outside, Workers |
| T16 | An outside sign-in's token taken, or its sign-in forged | Reaching outside |
| T17 | Script through an app's text in Leafen's screens (names, descriptions, notices) | Security notes |
| T18 | Script through a file an app uploaded | Embed |
| T19 | An update that widens what an app may reach without asking | Distribution |
| T20 | Changes that slip past history and undo | What an app is, Actions and approvals |