# One app. Two modes.

You don’t build a bookmarklet app and an OS app. You build one bundle. The shell decides which mode it runs in — card mode or app mode.

- **A card on someone’s site** (card mode) — Etsy, eBay, articles — opened from the bookmarklet, a Fave1 Button or Try it. `ctx.page` is that live document. Break the Site lives here.
- **`<id>.fave1.app`** (app mode) — Opened from My Fave1. Same install, same session. `ctx.page` is your own page — never fave1.com.

## The panel and the page

- **The panel — blocks or your own DOM** (ctx.ui) — Blocks for lists and forms; `host()` for an editor, a gallery, a board. The header is always Fave1’s — no app can fake it.
- **The host page — full DOM** (ctx.page) — The real `document`. Query, mutate, animate. That’s the product.

## Which mode am I in?

`src/index.ts`

```ts
if (ctx.surface === 'card') {
  // Card mode — a card on someone's site. Play with the page.
} else {
  // 'app' — app mode, your own screen at <id>.fave1.app. Boards, lists, settings.
}
```

`ctx.surface` is how one bundle draws two screens — the game in card mode, the board in app mode. It never changes mid-run: opening the other mode is a fresh launch.

## One wall

Reshape the host page all you like. You can’t touch the session, another app’s data, or the shell. Everything outside the page goes through `ctx`, and `ctx` only has what your manifest declared. The browser itself is yours too, with a few rules — [Beyond ctx](https://developers.fave1.com/docs/web-apis.md).

## Everything on ctx

| Member | What it is | Needs |
| --- | --- | --- |
| `ctx.ui` | The panel — blocks, your own DOM, moving it out of the way. [ctx.ui](https://developers.fave1.com/docs/ctx-ui.md) | — |
| `ctx.page` | The page you opened on — its address and title always, its text or whole DOM if declared. [ctx.page](https://developers.fave1.com/docs/ctx-page.md) | `page.*` |
| `ctx.storage` | Private JSON on the person’s account. [ctx.storage](https://developers.fave1.com/docs/ctx-storage.md) | `storage` |
| `ctx.files` | Their files on the account. [ctx.files](https://developers.fave1.com/docs/ctx-files.md) | `storage` |
| `ctx.shared` | A value shared by one link — anyone with it reads, and edits if the owner lets them. [ctx.shared](https://developers.fave1.com/docs/ctx-shared.md) | `storage` |
| `ctx.stickers` | Give them a sticker for their My Fave1 home — a reward they choose where to put. [ctx.stickers](https://developers.fave1.com/docs/ctx-stickers.md) | `storage` |
| `ctx.purchases` | Sell things inside your app for Fave1 credits — Fave1 holds the price and the Buy button. Not open to your app yet. [ctx.purchases](https://developers.fave1.com/docs/ctx-purchases.md) | `storage` |
| `ctx.pub` | One public value per person, readable by everyone using your app. [ctx.pub](https://developers.fave1.com/docs/ctx-pub.md) | `pub` |
| `ctx.live` | Rooms — several people edit the same table at once, pushed live — and direct lines between two of them. [ctx.live](https://developers.fave1.com/docs/ctx-live.md) | `pub` |
| `ctx.user` | Signed in or not, an id that’s yours alone, whether the account opens without asking, and their plan (`plus` · `tier`). [ctx.user](https://developers.fave1.com/docs/ctx-user.md) | — |
| `ctx.config` | A JSON you edit in the console. [ctx.config](https://developers.fave1.com/docs/ctx-config.md) | — |
| `ctx.locale · ctx.t(key)` | The language this person uses, and your words in it from `locales/*.json` — English underneath. [ctx.locale · ctx.t](https://developers.fave1.com/docs/ctx-locale.md) | — |
| `ctx.notify.send() · cancel() · status() · on() · opened` | A notification to this person, from your app — a reminder they set — or to someone else for what was done for them. A number on your icon and a row in their Fave1 notifications; `on()` fires while your app is open. [ctx.notify](https://developers.fave1.com/docs/ctx-notify.md) | — |
| `ctx.surface` | `'card'` in card mode, `'app'` in app mode — above | — |
| `ctx.can(p)` | Is this permission live right now — declared, switched on, and for `storage` · `pub` (so also `ctx.files` · `ctx.shared` · `ctx.live`), someone signed in. [When one is off](https://developers.fave1.com/docs/permissions.md#off) | — |
| `ctx.perms.open()` | Opens your app’s permission screen in their Fave1 settings, in a new tab | — |
| `ctx.clipboard.read() · write(t)` | Copy and paste — pasting asks every time. See [ctx.clipboard](https://developers.fave1.com/docs/ctx-clipboard.md) | `clipboard` |
| `ctx.ai.chat() · stream() · run() · speak() · status() · choices() · setup()` | Ask an AI model on Fave1 AI — Claude, ChatGPT, Gemini or Grok, paid from the person’s Fave1 credits — text, pictures, answers in a shape, tools, a voice that reads it out (`voices()`), and what’s left this month (`usage()`). No keys anywhere. See [ctx.ai](https://developers.fave1.com/docs/ctx-ai.md) | `ai` |
| `ctx.camera.open() · close()` | Their camera, live, while your app is open — Fave1 asks first and shows a red dot. See [ctx.camera](https://developers.fave1.com/docs/ctx-camera.md) | `camera` |
| `ctx.mic.open() · close()` | Their microphone, live, while your app is open — Fave1 asks first and shows a red dot. See [ctx.mic](https://developers.fave1.com/docs/ctx-mic.md) | `mic` |

Every call that can fail rejects with an `Error` carrying a `code` — `denied`, `signed-out`, `quota` and so on, typed as `Fave1Error` in `types/fave1.d.ts`. Each page lists the codes it can give.

## Lifecycle

`src/index.ts`

```ts
Fave1.defineApp({
  onLaunch(ctx) {
    // The panel opened. Draw it, read the page, change the page.
  },
  onDestroy() {
    // The panel closed. Put the page back, stop your timers.
  },
});
```

Two hooks, that’s all. `onLaunch` runs each time someone opens your app; `onDestroy` runs when they close it or open another one, and gets the same `ctx`. Your bundle itself runs once per page: close the app and open it again on the same page, and module variables still hold what they held. So set up your state in `onLaunch` and clear it in `onDestroy`. DEV builds load fresh on every open, so you won’t see leftovers while you build — people will. What should outlast the page goes in [ctx.storage](https://developers.fave1.com/docs/ctx-storage.md).
