Docs / Decision records
ADR 0034: Proto Studio: a UI design and prototyping studio whose canvas is real HTML and CSS
- Status: Proposed
- Date: 2026-11-23
- Concept and build plan: docs/concepts/proto-studio.md
- Builds on: ADR 0006 (
.ofini), ADR 0011 (live editing), ADR 0016 (doc.officekinds), ADR 0029 (a studio on the generic project container), ADR 0032 (CLI reuses pure modules), ADR 0033 (docking)
Context#
OpenFini can draw (Vector), lay out pages (Layout), build websites by hand (Code, with a visual HTML designer) and edit video (Scene). It cannot design application UI the way people do it today in Figma, Penpot, Paper or Sketch: frames with auto layout, components with variants and properties, variables with modes, clickable prototypes, and a handoff to code. In 2025 and 2026 these products all added a way for AI agents to work on the document: Figma's MCP server (read, and since 2026 write to the canvas), Penpot's official MCP server, Sketch's local MCP server, and Paper, whose canvas is HTML and CSS and which ships an MCP server in its desktop app.
The owner wants a studio of that class that is native to OpenFini: the Vibe assistant creates and edits frames and
components from prompts and screenshots, an MCP server exposes the document to external agents (Claude Code, Cursor),
the ofini CLI exports code, tokens and assets and lints, the Code studio shares tokens and components with it, it is
live-collaborative from the first release, its panels dock, and it imports SVG, Sketch and Penpot files.
Constraints that shape the decision:
- No framework, no build step in development, lazy loading, a start-up budget with almost no headroom
(
scripts/size-budget.json). - Clean-room policy (clean-room.md): no proprietary formats without a public specification.
- Engines must stay pure so that the CLI, the tests and the assistant share them (ADR 0032).
- Collaboration is a records CRDT on immutable JSON models for non-tree kinds (
collab/office-records.js).
Decision#
-
A new studio,
proto, on the generic project container. A Proto document is an OpenFini document whose project (doc.office) has kind"proto"(like Scene, ADR 0029). This reuses undo (commitOffice), autosave, sessions, the file format's version rule, media storage (office/proto/media/) and the records-based live editing. The studio definition (studios/proto.js) is the only start-up code; everything else loads on first use. -
One pure, versioned document model.
engine/proto/holds the schema (schema: 1, migrations, validation), a flat map of nodes with parent ids and fractional order keys, components with variants, properties and overrides, variables with collections and modes, styles as composite tokens, and prototype interactions. Its vocabulary is CSS's: sizing, flex and grid layout, constraints, fills, strokes and effects all have one documented CSS meaning. -
One operation layer for every caller.
engine/proto/ops.jsis the only way the model changes. The editor tools, the Vibe tools, the MCP server andofini protoall call the same pure operations, so a capability exists for one caller only if it is deliberately hidden from the others. -
The canvas is rendered as real DOM and CSS. One compiler (
engine/proto/css.js) turns nodes into CSS declarations; the editor renders them as keyed DOM inside a shadow root per top-level frame, and the code exporter emits the same declarations. The browser's layout engine is the layout engine, so what the designer sees is what the exported code does. Selection, guides, measurements and remote cursors are drawn on one Canvas 2D overlay. A small pure layout solver (engine/proto/layout.js, flex, grid and constraints with approximate text metrics) serves the places without a browser: the CLI's SVG render and lint, and headless MCP. Its results are labeled approximate, as with the CLI's text metrics today (ADR 0032). -
Design tokens in the W3C DTCG format. Variables and styles import and export as Design Tokens Community Group JSON (stable format 2025.10), and compile to CSS custom properties, a Tailwind v4
@theme, and Swift. A Code studio project can own atokens.jsonthat the Proto document links to; the file is the source of truth while linked. -
Code export through one intermediate representation.
engine/proto/codegen/lowers the model to an element tree with semantic tags, classes and token references; emitters write HTML + CSS, React (CSS Modules or Tailwind), Tailwind HTML and SwiftUI. Output is deterministic and snapshot-tested. Import of HTML runs in the Code studio's sandboxed preview (computed styles and boxes); the CLI has a static best-effort path. -
An MCP server over the same operations, off by default. A transport-neutral JSON-RPC handler (
engine/proto/mcp/) implements MCP 2025-11-25 tools and resources overops.js. Transports: on the desktop, Streamable HTTP on127.0.0.1from the Tauri shell (random port, bearer token, Host and Origin checks, per-client approval, read-only until the user allows writes); in a terminal,ofini mcpover stdio, either working headless on a file or proxying to the running desktop app. The browser build cannot listen on a port and offers no server. Proto also uses MCP as a client through the existingai/mcp.js. -
Live collaboration from the first release. A records adapter (
proto/collab.js) maps the model to keyed records (structure, layout, style, text, component, variable, interaction records per node), and"proto"joinsLIVE_OFFICE_KINDS. Comments anchor to node ids through the existing comments system; presence shows cursors and selections in canvas coordinates. -
No
.figimport (superseded by amendment A: a read-only, best-effort import behind Labs). Figma's.figcontainer has no public specification; reading it would mean reverse engineering, which the clean-room policy rules out (rule 4, and clean-room.md ▸ Formats we deliberately do not read). Routes from Figma are SVG (copy or export), Figma's official REST API with the user's own token (a later, optional importer, after a review of the API terms), and whatever the user's own MCP connections return. SVG, Sketch (existing reader, extended to symbols) and Penpot exports (an open, documented format of an open-source product, read by our own code) are imported. -
Built in small, independently mergeable tasks across the 1.3.x releases, listed in the concept document. 1.3.0 ships a preview (model, renderer, core tools, components and variables in the engine, live collaboration, assistant tools, CLI); 1.3.1 adds the panels for components and variables, code export, imports and prototyping; 1.3.2 the MCP server and the Code studio live link.
Rendering: why DOM and not Canvas 2D or WebGL#
| DOM + CSS (chosen) | Canvas 2D display list (as Vector) | WebGL / WASM engine (as Figma) | |
|---|---|---|---|
| Layout fidelity with exported code | Exact: the same CSS | Needs our own flex, grid and text engine with browser parity | Same as Canvas 2D, plus a GPU renderer |
| Text (shaping, fallback, wrapping, variable fonts) | The browser's | Our layout engine (good for print, not for CSS parity) | Our own |
| Effort | Small renderer, large performance care | Large | Very large |
| Large documents | Needs culling and level of detail | Scales well | Scales best |
| Headless (CLI, Node) | Needs a second, approximate solver | Same code | Same code |
| Smart animate in the player | Native (FLIP + Web Animations) | Own interpolation | Own interpolation |
The decisive argument is fidelity: Proto exists to produce interfaces that become HTML, React or SwiftUI. Every
point where the canvas and the browser disagree is a bug the user finds in production. Paper shows that an HTML and
CSS canvas works for this class of tool. The costs are accepted and bounded: culling and content-visibility per
frame, a simplified level of detail below 25 % zoom, a transform-only pan and zoom with re-rasterization when idle,
keyed incremental patching, and the performance targets in the concept document, measured in CI on a fixture.
Vector-style drawing inside a frame (paths, boolean results) renders as inline SVG, which is also what the exporter
writes.
Consequences#
- A designer's frame, its prototype in the player, its HTML export and its React export share one CSS meaning.
- Agents inside and outside the app get the same capabilities, through the same tested operations, with one security model; external agents cannot do anything the user has not allowed, and every write is one undo step.
- The pure solver is a second layout implementation. It is kept small, documented as approximate, and tested against geometry recorded from Chromium and Firefox; it is never used to draw the canvas.
- Performance depends on the browser engine (WebView2, WKWebView, WebKitGTK). WebKitGTK is the slowest; the level of detail and culling are mandatory, not optional.
- The start-up bundle grows by the studio definition and menu rows only (about 1 KiB); the studio itself adds an estimated 120 to 160 KiB gzip of lazy JavaScript over the 1.3.x releases, budgeted per task.
- Two new network surfaces (the MCP HTTP endpoint and, later, the Figma API importer) need security review; both are off by default.
Alternatives considered#
- Extending the Vector studio with auto layout and components. Its Canvas 2D display list and print-oriented model (pages, artboards, text stories for layout) would need a CSS layout engine with browser parity anyway, and the Vector studio would carry UI-design concepts that illustrators never use. Rejected; Vector keeps its role and Proto imports and exports SVG to exchange artwork with it.
- Extending the Code studio's visual designer. It edits arbitrary hand-written HTML and CSS with offset-preserving source edits; it has no components with variants, no variables with modes, no free canvas with many frames and no prototypes. Making the source text the model would make every design operation a text edit. Rejected; the two studios link instead (tokens, components, HTML import and export).
- Vendoring an open-source design tool or layout engine (Penpot is Clojure on a server; Yoga is C++/WASM, about 100 KiB gzip, and covers flex only). Rejected for size, language and fidelity with grid.
- A
.figreader based on community reverse engineering. Rejected by the clean-room policy (see Decision 9); revisited by the owner in amendment A, which allows a read-only reader written from public open-source knowledge. - An MCP server in the browser over a local WebSocket bridge. Possible later through Chrome's Local Network Access permission and a pairing code, but it adds a listening helper the user must install; not part of this plan.
Amendment A (2026-11-26): read-only .fig import#
- Status: Accepted (owner decision, 2026-11-26)
- Replaces: Decision 9 and the
.figalternative above, for reading only
Decision. Proto imports Figma .fig files read only and best effort, behind Labs (Settings ▸ Labs ▸ Figma
File Import in the app; an explicit ofini proto import --from fig in the terminal). OpenFini never writes .fig:
there is no .fig export, no save to .fig and no round trip. An imported design is an ordinary Proto design saved as
.ofini.
Rationale.
- Interoperability. People who move to OpenFini, or work with people who use Figma, have their work in
.figfiles they own. SVG export loses auto layout, components and variables; the REST API needs an account, a token and network access. Reading the user's own files on their own device is the most direct route, and reading a file format for interoperability is not using anyone's code. - Read only. Writing
.figwould make OpenFini a producer of a proprietary format it cannot validate and invite files that Figma might misread. Reading keeps the risk on our side: a misread layer shows in the import report and in the result the user checks. - Public, openly licensed knowledge only. The reader is OpenFini's own code written from public descriptions: the
Kiwi encoding (evanw/kiwi, MIT; the file carries its own Kiwi schema, so field names
come from the file), the container and node structure as described by public, openly licensed tools and write-ups
(Sketch's fig2sketch, MIT, license checked 2026-11-26; Grida's
notes on the format), Zstandard from
RFC 8878 (our own decoder,
import/zstd.js) and DEFLATE through the vendored fflate (MIT). No code was copied or translated from any of them, and no Figma application or code was disassembled or decompiled. Tests use synthetic files built from the same public description; no third-party.figfile is committed. - Best effort, clearly labeled. The format has no public specification and can change without notice. The feature
is a Labs preview, the import report lists every node type and property that was not mapped, and the app says after
each import that the result is best effort and that
.figcannot be saved.
Consequences.
- clean-room.md records
.figas a deliberate, owner-approved exception to rule 4, limited to reading for interoperability, with the sources above. - New pure modules
engine/proto/import/{fig,kiwi,zstd}.js(lazy, part of the importer chunk). Limits: the importers' archive limits, at most 512 MiB of decompressed design data and 16 MiB of schema, the Kiwi reader's value, depth and length checks, and 50,000 layers per import. - If Figma or a rights holder objects, the feature can be removed without touching the rest of Proto: it is one importer behind one switch.
Amendment B (2026-11-26): Figma plugin compatibility layer#
- Status: Accepted (owner decision, 2026-11-26); built in 1.3.x
- Details: docs/figma-plugins.md (user guide, safety model and API coverage table)
Decision. The Proto Studio runs Figma plugins: a figma.* global implemented on top of the Proto model and the
operation layer (Decision 3), loaded from the plugin's own manifest.json, main code and UI.
- Sandbox. Main code runs in a dedicated worker inside a hidden
sandbox="allow-scripts"frame (opaque origin, a policy without network), reusing the extension host's relay (extensions/html.js); network, storage and worker globals are removed before the plugin runs. The UI is a second sandboxed frame with its own policy; the two talk only throughpluginMessage, as in Figma. - Synchronous API over an asynchronous host. The runtime (
engine/proto/plugins/runtime.js, pure and self-contained) keeps a mirror of the design, applies writes to it at once and records them as engine operations with ids it assigns; the host (bridge.js) applies each batch (one task, or up tofigma.commitUndo()) as one undo step named after the plugin, validated by the engine, and answers with a fresh snapshot. - Network only for domains the manifest lists in
networkAccess.allowedDomainsand the user approved at the first run; requests from the main code are proxied and checked by the host, and the UI frame'sconnect-srclists exactly those domains. - Only allowed operations. The bridge accepts a fixed list of operations (layers, pages, components, variables, styles, images); everything else is refused.
Rationale. Figma's plugin ecosystem is a large part of what designers rely on; a compatible API lets many
existing plugins and their authors work in OpenFini without a port. The plugin API is publicly documented, and its
type definitions (@figma/plugin-typings) are MIT-licensed; implementing a documented API is our own code (no Figma
code is used or copied). Mapping it onto the existing operations keeps one security model (validated operations,
one undo step per change) for the editor, the assistant, MCP and plugins.
Consequences. Plugins that depend on Figma-only concepts (vector networks, libraries, users, FigJam, Dev Mode, codegen) do not work; the coverage table says which APIs are supported, partial or missing, and missing APIs throw a clear error. Plugin code is untrusted: it is sandboxed like extensions and every write passes the engine's validation. About 20 KiB gzip of lazy code; start-up unchanged.
Edit on GitHub → docs/adr/0034-proto-studio.md