Docs / Guides
Developer guide
For engineers who join the project. Read this first, then architecture.md and the doc of the area you touch (every area has one, see the map below). CONTRIBUTING.md covers the rules of the road; this file covers how the code is organized and how to work on it.
1. The 10-minute orientation#
OpenFini is a no-framework ES-module app in app/ (served as-is in development, bundled with esbuild for releases),
wrapped by a Tauri v2 shell in src-tauri/ and shipped as a PWA too.
UI (app/src/ui, app/src/studios) ──► commands (app/src/commands) ──► core (app/src/core) ◄── engines (app/src/engine, pure)
│ ▲
└── Vibe tools (app/src/vibe/tools) ─── the same commands/ops ──┘
Rules that explain most of the code:
- Engines are pure (no DOM, no
window, no globalfetch):app/src/engine/*,app/src/ai/*,app/src/core/*.jsmodules documented as pure (log.js,network.js,updates.js, …). They run in Node and are unit-tested. - Everything a user can do is a command with an id (
file.save,arrange.group,window.popout…), registered inapp/src/commands/*. Menus, shortcuts, the command palette, context menus, extensions and the Vibe assistant all go through commands or the same ops. Do not wire behavior directly into a button. - Every document change is undoable:
doc.tx(...)/doc.set(...); interactive tools mutate live and record once. - Heavy things are lazy. Anything not needed at start-up is loaded with
import(). CI enforces size budgets (scripts/size-budget.json: startup JS, total app JS, total download). Add features lazily or the build fails. - Everything user-visible is translatable:
t("English text")(the English text is the key).npm run i18n:checkruns in the test suite. - Security by construction: untrusted code (extensions, custom tools, website previews) only runs in sandboxed
iframes; outbound network goes through
app.network.assert(kind); secrets are never written to documents or logs.
2. Where things live#
| Area | Code | Doc |
|---|---|---|
| Document model, history, ops, app state | app/src/core/ | architecture.md, engine-contracts.md |
| Export (options schema, PNG/TIFF encoders, presets, Export popup) | app/src/engine/export/, app/src/core/export-run.js, app/src/ui/export-dialog.js | export.md |
| Color management (ICC, CMYK, PDF/X, preflight) | app/src/engine/color/, app/src/core/color-doc.js, app/src/ui/color-settings.js | color-management.md |
| Vector / Pixel / Layout engines | app/src/engine/{vector,pixel,layout,backends} | studios.md, layout-tables-charts.md, pixel-histogram.md |
| Studio registry, tools, docks | app/src/studios/ (registry.js is the single list of studios) | studios.md |
| Code studio and web engine | app/src/ui/code/, app/src/engine/web/, app/src/engine/git, engine/publish | code-studio.md, web-engine.md, frameworks.md, git-and-publishing.md |
| Office Suite (registry, launcher, apps, Office Toolkit) | app/src/office/, word processor app/src/ui/office/, app/src/engine/office/ | office-suite.md, office-studio.md |
| Vibe (AI) | runtime app/src/ai/, hub/session/tools app/src/vibe/, UI app/src/ui/vibe/ | vibe-studio.md, ai-engine.md, vibe-skills.md |
| File formats / importers | app/src/engine/formats/, app/src/core/import-*.js, app/src/platform/file-types.js (single source of truth for types) | file-compat.md, pdf-import.md, file-format-research.md |
| Extensions + SDK | app/src/extensions/, app/src/ui/extensions/, sdk/, extensions/ (bundled) | extensions.md, bundled-extensions.md |
VS Code extensions (Open VSX, .vsix, vscode API shim) | pure app/src/vscode/, UI app/src/ui/extensions/vscode*.js | vscode-extensions.md, ADR 0012 |
Figma plugins in Proto (figma.* API, sandbox, manifests) | pure app/src/engine/proto/plugins/, app app/src/proto/plugins/host.js | figma-plugins.md, ADR 0034 amendment B |
| Themes, onboarding, command palette | app/src/ui/themes.js, tour*.js, command-palette.js | themes.md, design-system.md |
| Settings and customization | app/src/ui/settings-dialog.js, app/src/customize/ | settings.md, customization.md |
| Context menus | app/src/ui/context-menu/ | context-menus.md |
| i18n | app/src/i18n/ | i18n.md, i18n-glossary.md |
| Windows (pop-out), title bar, OS integration | app/src/platform/, app/src/ui/popout.js, src-tauri/ | multi-window.md, os-integration.md |
| Collaboration (rooms, chat, comments, versions, presence, relay, Edit together, LAN rooms) | pure app/src/collab/ (incl. tree-crdt.js, text-crdt.js, qr.js), UI app/src/ui/collab/ (live.js, network.js), scripts/relay.mjs (also runs standalone: node relay.mjs), scripts/relay-tls.mjs, built-in relay src-tauri/src/relay.rs | collaboration.md, ADR 0010, ADR 0011, ADR 0018 |
| Built-in network clients (desktop): FTP/FTPS publish target, Send by email (SMTP), certificate trust on first use | Rust src-tauri/src/ftp.rs, smtp.rs, netio.rs, wire.rs (unit tests: cargo test --lib); JS app/src/platform/native-net.js, app/src/ui/send-email.js, app/src/ui/net-trust.js, app/src/ui/node-tools.js | git-and-publishing.md, ADR 0018 |
| Security, logging, diagnostics | app/src/core/{log,network,security,atrest}.js, app/src/ui/security-center.js | security.md, troubleshooting.md |
| Build, size budgets, installer, release | scripts/, src-tauri/installer, .github/workflows/ | building.md, installer.md, release-process.md |
| The wiki (user and developer manual, published to the GitHub wiki) | wiki/, scripts/wiki-sync.mjs, scripts/wiki-shortcuts.mjs, .github/workflows/wiki.yml, tests/docs/ | wiki-maintenance.md, wiki/Wiki-Style-Guide.md |
3. Recipes: how to add…#
- A command: register in
app/src/commands/<area>.js(id, label viaN_/t, run, enabled, shortcut). It then shows up in menus (add the id to the menu list inui/menus.js), the palette and the shortcut editor. Add it totests/if it has logic. - An Office app (spreadsheet, slides, whiteboard …): a manifest + lazy implementation, one line in
app/src/office/index.js; contract and worked example in office-suite.md. - The header is responsive:
ui/header-fit.jssheds items by measured width. A new header item that must not disappear needs a place in its step list; one that may goes into the "…" menu viadata-cmd. - A studio: one
registerStudio({...})entry (studios/registry.jsdocuments the fields); put heavy UI behindimport(). It appears in the header "More" menu; users choose the five visible studios in Settings. - A tool the Vibe assistant can use: a
tool()inapp/src/vibe/tools/<area>.js(helpers.jshastool,Sschema helpers), register it intools/index.jsandTOOL_GROUPS.tests/ai/tool-contract.test.jsenforces schemas, uniqueness and grouping. Mark read-only tools{ readOnly: true }; outward actions return an approval reason. - A skill: Markdown with front matter, see vibe-skills.md; built-ins in
app/src/ai/skills-library.js. - A context menu:
registerContextProvider(context-menus.md); never callshowContextMenuwith a hand-built list for new surfaces. - A setting: add it to the schema in
app/src/customize/schema.js/ the settings dialog section; prefs live inApp.prefs(defaultPrefs()). - A file format: a pure reader/writer in
engine/formats/+ tests with synthetic fixtures, a row inplatform/file-types.js(the packaging tests check that Open dialogs, drag-and-drop, Tauri associations and the PWA manifest agree), routing incommands/file.js. - An extension:
node sdk/create-extension.mjs publisher.name, see extensions.md. - A translation: wrap with
t(),npm run i18n:extract, translateapp/src/i18n/locales/de.json; new language = oneLOCALESentry. - A heavy pure job off the UI thread: add it to
app/src/core/workers/jobs.js(plain data in and out, return{ r, transfer }) and callrunJob()fromcore/workers/index.js; it falls back to running in-thread. Measure first (performance.md). - A dependency: avoid. Vendored code needs an MIT-compatible license, a folder in
app/vendor/, an entry inTHIRD_PARTY_NOTICES.md.
4. Testing#
npm testruns everytests/**/*.test.jswithnode:test(no browser, no dependencies). Aim for pure logic in testable modules.- Pure modules get unit tests with synthetic fixtures; parsers get hostile-input tests (truncation, huge sizes, bad offsets).
- UI changes need a manual check in Chromium (the repo ships a dev server:
npm start, ornode scripts/serve.mjs --port N). The app is exposed aswindow.openfinifor scripting (setStudio,run(commandId),prefs,doc,toast,emit/on). npm run build && npm run check:sizemust pass; CI runs tests on Linux, macOS and Windows plus the Rust build.- The Demo (mock) Vibe provider makes AI features testable without keys; extend
app/src/ai/providers/mock.jswhen you add tools. ofini(cli/ofini.mjs;npm linkornpm run ofini -- <command>) inspects, validates, repairs, converts and exports documents without the app, for CI and bug reports: cli.md, architecture in ADR 0032. It imports the app's pure modules, so keepcore/,engine/and the Office apps'create/open/savefree of DOM access at import time;tests/packaging/ofini-cli.test.jsruns every command in plain Node.
5. Working together: Git, branches, PRs#
mainis protected. All changes go through pull requests; required checks: Web/PWA (Ubuntu, macOS, Windows) and Rust.- Branch names:
feat/…,fix/…,docs/…,refactor/…. One topic per branch. - Commits: Conventional Commits (
feat(scope): summary), body explains what and why. PRs are squash-merged, so the PR title becomes the history line. - PR description: Summary, What changed, How verified, Limits/not verified, Docs. Keep unverified things explicit: never claim a test you did not run.
- Shared files (
core/app.js,ui/shell.js,ui/menus.js,ui/settings-dialog.js,commands/index.js,vibe/tools/index.js,CHANGELOG.md,app/index.html) are conflict hot spots when several people work in parallel: make small additive edits, put new code in new files and new CSS in your own stylesheet, mergemainoften. - Update the docs of the area you changed and add a bullet to
CHANGELOG.mdunder## [Unreleased]. - The wiki lives in
wiki/and is published to the GitHub wiki on merge tomain; if you change a shortcut or command, runnpm run wiki:shortcuts(a test fails whenwiki/Keyboard-Shortcuts.mdis stale) and update the affected wiki page (wiki-maintenance.md). - Design decisions that are hard to reverse get an ADR in adr/ (context, decision, consequences).
6. Size, performance and low-power devices#
OpenFini targets old and low-power machines. Use the budgets as a design constraint: lazy-load, prefer pure functions and plain
data, avoid per-frame allocations in canvas code, and keep undo history bounded (prefs.historyMB, low-power mode).
Measure with npm run build && npm run check:size (prints startup, total app and download sizes).
Keeping the app small and clean#
Rules (enforced where cheap, by tests/architecture/guardrails.test.js and scripts/check-size.mjs):
- Start-up is precious. Only what the shell needs to draw the first frame is imported statically from
main.js. Dialogs, studios' workspaces, importers, engines that only a command needs:import()them where they are used. The test keeps a list of lazy areas (LAZY_AREAS: collab, VS Code, extensions, Office, formats, git, publish, Code and Vibe UI, AI, locales, the export dialog, pdf.js, CodeMirror, KaTeX) out of the static start-up closure. - If start-up only needs a list, split the list from the code. Example:
engine/web/texttools-catalog.js(ids and labels for the palette) vs.texttools.js(the implementations and the HTML entity table). - No circular imports in
app/src;core/andengine/never importui/,studios/,commands/orvibe/statically (use a callback orimport()); engine code touches no DOM or browser globals. - Prefer deleting code over abstracting it. A shared helper must remove more code than it adds; tiny local one-liners in pure engines are fine.
- Long-lived listeners unsubscribe.
app.on()returns anofffunction; anything built more than once (dialog panes, popovers) must call it when it goes away. - Budgets go down, not only up. After a size win, lower
scripts/size-budget.jsonto the measured value plus about 2 % and note it in the file's$comment.
How to look:
npm run build && node scripts/check-size.mjs # the CI gate
node scripts/analyze-bundle.mjs --top 40 # chunks, start-up modules, lazy-loading candidates (runs a build)
node scripts/import-report.mjs # largest modules, fan-in/out, cycles
node scripts/import-report.mjs --why app/src/engine/web/charcodec.js # why is a file loaded at start-up?
node scripts/find-dead-exports.mjs # dead code report (never fails; read its blind spots)
refactoring-audit.md is the living record: append a dated section with numbers for every audit, including the ideas that were considered and rejected.
7. Known sharp edges#
- Rust/Tauri code cannot be compiled on every dev machine; CI is the first real build. Keep Rust changes small and
cargo fmtclean. makensis(Windows installer) and macOS DMG layout are validated only by the release build.- The English text is the i18n key: editing an English string drops its German translation until you re-run
npm run i18n:extract. - Extension and sandbox code has no module loader: bundled extensions are concatenated by
scripts/pack-extensions.mjs. - The plan lives in roadmap.md (with the 2.0 concept in concepts/roadmap-next-major.md); honest limits per area are in known-limits.md.
Edit on GitHub → docs/development.md