Platform clients
Trilium delivers one note-taking product through several client hosts. The desktop app adds native operating-system features around a local server. The standalone web app keeps the workspace in browser storage. Mobile packages that web runtime in Capacitor, while the web clipper captures content from other pages and sends it to Trilium.
Client delivery model
The platform clients keep the note workspace separate from the environment that hosts it. The shared client supplies the product experience. Each host supplies the local data path, request path, file handling, and native features that its environment can support.
| Client | Main purpose | Data and service location | Host boundary |
|---|---|---|---|
| Desktop | Native local use | Local Trilium server and SQLite database | Electron main process, preload bridge, and IPC |
| Standalone web | Local use in a normal browser | SQLite in browser persistent storage | Service worker and browser messaging |
| Mobile | Local use on Android and iOS | Standalone runtime in a Capacitor WebView | Native WebView request and file services |
| Web clipper | Capture content from other pages | A local desktop instance or configured server | Browser extension messages and clipper API |
Desktop and standalone web both provide the full workspace. Mobile reuses the standalone data and worker model. The clipper is an integration client, so it prepares content for Trilium instead of rendering the full workspace.
Shared client experience
The shared client starts the note services after the host has prepared its platform bridge. It selects a desktop or touch-oriented layout without changing the product role of the workspace. For the main browser workspace, see Client experience.
References: apps/…/desktop.ts• L19-76 apps/…/mobile.ts• L9-21 apps/…/desktop.ts• L1-2
Desktop client
The desktop client is an Electron shell around a local Trilium server. It provides native windows, system integration, file access, printing, backups, sign-in callbacks, and local meeting transcription. Packaging turns the same shell into installers and portable artifacts for supported desktop systems.
The desktop build assembles the server, preload bridge, native database support, workers, client assets, editor assets, and transcription resources. Linux delivery includes Flatpak and RPM paths. The Flatpak package also declares the desktop launcher, app metadata, icon, screenshots, network access for sync, and access to common folders for file import. Artifact checks confirm that the packaged output still has the client and native resources needed to start the app. See Desktop shell and IPC for the native boundary.
References: apps/…/main.ts• L67-82 apps/…/main.ts• L214-305 apps/…/package.json• L13-32 apps/…/build.ts• L9-46 apps/…/artifacts.spec.ts• L5-45 apps/…/forge.config.ts• L38-151 apps/…/rpm-spec.ejs• L28-43 apps/…/org.triliumnotes.Trilium.desktop• L1-15 apps/…/org.triliumnotes.Trilium.metainfo.xml• L18-78 apps/…/org.triliumnotes.Trilium.yml• L14-63
Desktop request and update paths
Desktop renderer requests use the privileged trilium-app://app application scheme to reach the local server in the main process. The bridge carries normal request bodies, binary responses, and live streams back to the renderer, so the shared client keeps one request model for pages, APIs, assets, and streaming features. Requests are accepted only from trusted app frames, while an explicitly enabled LAN listener remains a separate path for other browser clients.
The following diagram shows the protected internal desktop path and the optional external browser path.
flowchart LR
UI[Electron renderer] -->|trilium-app requests| GATE[Trusted frame gate]
GATE -->|local dispatch| SERVER[Local Trilium server]
SERVER --> DB[(Local database)]
SERVER -->|IPC live messages| UI
BROWSER[Optional browser client] -->|HTTP and WebSocket| SERVER
The internal path marks requests as coming from the desktop shell only after the frame and origin checks pass. This lets the local renderer use its internal request contract without granting the same trust to a public HTTP request. Streaming responses release data as it arrives, apply backpressure when the renderer reads slowly, and notify the server when the renderer stops reading.
References: apps/…/protocol.ts• L27-82 apps/…/protocol.ts• L86-186 apps/…/protocol.ts• L188-420 apps/…/protocol.spec.ts• L636-905 apps/…/preload.ts• L285-296
Native feature bridge
The preload bridge exposes limited native capabilities instead of direct Node.js access. It covers window control, clipboard actions, printing, file exchange, navigation, system integration, backups, and transcription. The main process remains responsible for sensitive actions and validates the context that supports them.
File import uses a user-selected file as the capability. The renderer passes a token or a path resolved from a real dropped file, rather than an arbitrary path supplied by page code. Protected backup passphrases can be set or cleared through the bridge, but the plaintext value is never returned to the renderer. See Desktop shell and IPC for the contract and security boundary.
References: apps/…/preload.ts• L14-113 apps/…/preload.ts• L215-361 apps/…/preload.spec.ts• L600-687 packages/…/electron_api_interface.ts• L49-72
Desktop startup integration
The desktop host maps shared platform needs to the operating system. It owns database location, startup errors, single-instance rules, tray behavior, launch-at-login behavior, and window state. It also adapts title bars, background effects, spell-check settings, and window reveal behavior to each operating system.
The desktop initializes the core and database before it starts the local server. It can create the main window while server startup continues, because requests wait for the server readiness signal. A failed server startup rejects waiting requests instead of leaving them open. The single-instance guard focuses the existing app, while a second launch can request a new window.
The desktop keeps each app window hidden until its first usable frame is ready. A first-paint gate holds the initial app request until the renderer reports that its layout and note tree are ready, while a short timeout and a separate window reveal timeout prevent a stalled renderer from leaving the app invisible. Window state is restored before reveal and saved across moves, resizes, maximize, and full-screen changes. Invalid or off-screen state falls back to safe defaults.
Startup metrics and compile-cache work remain diagnostic or performance aids. A failure in those paths does not replace the normal startup path.
References: apps/…/main.ts• L54-82 apps/…/main.ts• L161-190 apps/…/main.ts• L210-323 apps/…/first_paint_gate.ts• L7-67 apps/…/window.ts• L127-230 apps/…/window_state.ts• L21-85 apps/…/window_state.ts• L91-151 apps/…/window.spec.ts• L449-541 apps/…/window_state.spec.ts• L73-216 apps/…/entry.ts• L1-34 apps/…/startup_metrics.ts• L7-87 apps/…/trilium.sh• L1-16
Desktop meeting transcription
Desktop meeting transcription turns microphone and system audio into a live transcript attached to a meeting note. Audio capture and speech work run outside the main desktop window. The session can retain source recordings and reports capture or recognition errors without removing transcript text that it already saved.
References: apps/…/index.ts• L71-153 apps/…/protocol.ts• L22-59 apps/…/session.ts• L61-124 apps/…/transcription_worker.ts• L1-11
Standalone web and mobile clients
The standalone client makes Trilium a self-contained web application. It runs the shared client with SQLite WebAssembly and browser persistent storage. Mobile points Capacitor at this same build, so Android and iOS use the same local workspace instead of a separate mobile server.
The build includes the local worker, SQLite files, service-worker entry point, help content, share assets, and PDF viewer resources. Content-hashed assets allow a deployment to switch as one build. The service worker keeps a stable URL so the browser can replace an old worker. Startup shows progress in an inline splash screen and reports a clear error when the browser cannot provide the required runtime.
References: apps/…/package.json• L1-14 apps/…/package.json• L16-31 apps/…/index.html• L13-146 apps/…/main.ts• L11-29 apps/…/main.ts• L123-173 apps/…/vite.config.mts• L93-124 apps/…/vite.config.mts• L198-271 apps/…/vite.config.mts• L452-485
Standalone browser runtime
The browser service worker routes local API, sync, search, custom-handler, shared-note, and backup requests to the tab that owns the local database. The standalone API keeps the browser workspace compatible with the shared server API, including note operations, uploads, media ranges, share pages, and custom request handlers. A Web Lock selects one database owner. Other tabs forward requests through the service worker and receive live changes from that owner.
The browser host converts requests and responses at the local boundary instead of opening a network server. It preserves the status, headers, files, and binary bodies that the shared client needs. Mobile can replace service-worker interception with a native request bridge. The local route model remains the same, so the workspace still uses one browser-safe server worker. Shared-note pages need an open Trilium tab because the static host does not own the database or render those pages.
The following diagram shows how multiple browser tabs use one database owner.
flowchart LR
LEADER[Database owner tab] --> WORKER[Local server worker]
WORKER --> DB[(Browser storage)]
FOLLOWER[Follower tab] --> SW[Service worker]
OTHER[Other tab] --> SW
SW -->|forward local requests| LEADER
LEADER -->|relay live changes| SW
SW --> FOLLOWER
SW --> OTHER
References: apps/…/main.ts• L106-133 apps/…/local-server-worker.ts• L231-369 apps/…/sw.ts• L22-30 apps/…/sw.ts• L62-77 apps/…/sw.ts• L119-228 apps/…/sw.ts• L400-459 apps/…/browser_router.ts• L157-360 apps/…/browser_routes.ts• L71-171 apps/…/db_lock.ts• L23-75
Standalone platform services
The standalone host represents browser capabilities through the shared platform contract. The browser owns the database without exposing a file path, and the host carries only supported startup flags such as safe mode and a starting note. Browser requests follow same-origin and CORS rules. Mobile can send the same request purpose through native HTTP when the WebView cannot provide the required access. The native response path preserves status, headers, content type, cookies, and streamed body data for the WebView.
Android also supports a local streaming path for suitable GET and HEAD requests. It falls back to the native HTTP plugin when that path is not available. The browser and native paths therefore share a request goal while following different host rules.
References: apps/…/platform_provider.ts• L14-58 apps/…/request_provider.ts• L10-158 apps/…/bridged_request_provider.ts• L11-237 apps/…/capacitor_http_handler.ts• L38-190 apps/…/InterceptedResponse.java• L10-75 apps/…/LocalRequestBrokerTest.java• L71-109 apps/…/NativeHttpProxyTest.java• L66-145
Standalone browser data services
The browser runtime supplies crypto, backup, restore, ZIP, image, and export services without a native file system. These services keep protected note data and archive exchange compatible with desktop and server clients. Browser imports accept bytes or a picked file rather than a local path. Archive reads stay bounded and preserve common legacy filename encodings, while archive creation produces one browser-held result for download or sharing. Restore stages and checks a candidate database before it replaces the active database.
ZIP export supports HTML, Markdown, and share-theme output. Share-theme export needs the production manifest and its bundled theme, translation, font, and optional diagram assets. This lets standalone and mobile produce a self-contained share package.
References: apps/…/crypto_provider.ts• L19-183 apps/…/backup-download.ts• L12-209 apps/…/database_restore.ts• L18-139 apps/…/zip_provider.ts• L60-125 apps/…/zip_export_provider_factory.ts• L18-114 apps/…/zip_export_provider_factory.spec.ts• L35-131 apps/…/image_provider.ts• L21-64
Standalone security controls
The standalone client keeps backend scripting and the SQL console off by default. A browser-owned confirmation is required before either capability is enabled. The database-owning worker controls these settings, so a follower tab cannot change them through its normal page message path.
References: apps/…/security_gate.ts• L5-25 apps/…/security_gate.ts• L42-76 apps/…/security_settings.ts• L4-95 apps/…/local-server-worker.ts• L585-624
Mobile application shell
The mobile app is a Capacitor shell whose web directory points to the standalone build. Android and iOS use the same local database and worker model. Native code supplies platform-specific request interception, keyboard and safe-area behavior, file saving, sharing, and URL handling.
Android and iOS do not use the same request mechanism. Android can intercept local WebView requests and use a native streaming proxy. iOS attaches its own request bridge to the Capacitor WebView. These differences stay in the shell; the note workspace remains the standalone client.
See Standalone browser runtime for the request, storage, and tab coordination model.
References: apps/…/package.json• L8-23 apps/…/capacitor.config.json• L1-17 apps/…/MainActivity.java• L19-33 apps/…/InterceptedResponse.java• L25-73 apps/…/ViewController.swift• L6-42 apps/…/SceneDelegate.swift• L4-23 apps/…/native-request-bridge.ts• L4-124 apps/…/TriliumRequestBridge.java• L18-103 apps/…/TriliumRequestBridge.swift• L5-96
Web clipper integration
The web clipper is a browser extension that turns page content into Trilium notes. It can capture a page, selected text, links, images, or a screenshot. It prepares the content in the browser and sends it to a local desktop instance or a configured Trilium server. The extension can build for the main browser target and Firefox.
See Web clipper extension for the extension boundary and capture contract.
Capture workflow
The content script reads data from the active page and makes links and image references usable outside that page. The background process sends the prepared capture to Trilium and reports the created note back to the browser tab.
The following diagram shows the capture path from a page to a Trilium note.
sequenceDiagram
participant Page as Active page
participant Extension as Extension background
participant Trilium as Trilium API
participant Notes as Note store
Page->>Extension: Send captured page content
Extension->>Trilium: Send prepared clipping
Trilium->>Notes: Create or update clip note
Trilium-->>Extension: Return note identity
Extension-->>Page: Show result and open-note action
References: apps/…/package.json• L1-15 apps/…/package.json• L19-29 apps/…/index.ts• L145-240 apps/…/index.ts• L203-288
Trilium instance discovery
The extension first checks for a local desktop endpoint through the clipper handshake. If no desktop instance answers, it can use a server URL and token saved in extension storage. A major protocol check stops capture before it sends a payload to an incompatible server.
References: apps/…/trilium_server_facade.ts• L1-19 apps/…/trilium_server_facade.ts• L91-155 apps/…/trilium_server_facade.ts• L199-227 apps/…/index.ts• L19-69
Clipper note handling
The server places clips under the configured clipper inbox or the current day note. A page URL identifies an existing clip, so later captures can append to that note. The server sanitizes HTML and stores captured images as note attachments before it rewrites image references.
When the extension opens a captured note, a desktop instance sends an open-note message to its windows. A non-desktop server returns a browser-open result instead. The same capture contract therefore works with local and remote destinations.
References: apps/…/clipper.ts• L16-77 apps/…/clipper.ts• L89-215
Cross-platform boundaries
The shared client asks for capabilities through a host contract. Each host then maps that request to its own storage, message, file, or native boundary. A feature that works in one client is not automatically available in another.
| Boundary | Desktop | Standalone web | Mobile | Web clipper |
|---|---|---|---|---|
| Local data | Native SQLite file | SQLite in browser storage | Standalone storage in WebView | Does not own note data |
| Live local updates | Electron IPC | Service worker and tab relay | Native bridge or service worker | Ordinary API responses |
| Large files | Native file and backup services | Worker streams and browser downloads | Worker streams and Capacitor file or share paths | Image data sent for attachment storage |
| Native behavior | Electron APIs | Browser APIs | Capacitor and platform code | Browser extension APIs |
| Main integration target | Protected local app scheme and server | Local worker in the browser | Local worker in the WebView | Desktop handshake or configured server |
The platform boundary is the main reason to inspect the host contract when adding a client-facing feature. The shared client can request a capability, but the host must provide it or the feature must use a browser-safe fallback.
References: packages/…/electron_api_interface.ts• L49-72 packages/…/standalone_api_interface.ts• L1-12 apps/…/protocol.ts• L86-186 apps/…/preload.ts• L14-362 apps/…/composite_messaging_provider.ts• L27-69 apps/…/local-bridge.ts• L47-73 apps/…/native-request-bridge.ts• L5-23 apps/…/MainActivity.java• L20-31 apps/…/ViewController.swift• L31-42 apps/…/trilium_server_facade.ts• L91-155
Change checklist
When these files or sections are changed, remember to consider these:
- If a standalone local route changes, keep the page bridge, service worker, browser router, and native mobile request paths aligned.
- If standalone tab ownership changes, keep leader selection, request forwarding, live-update relay, backup, restore, and security-setting writes tied to the same owner.
- If the standalone build changes, keep the splash screen, stable service-worker URL, hashed assets, SQLite files, share assets, help assets, PDF assets, and Capacitor web directory aligned.
- If browser ZIP export changes, keep HTML, Markdown, share-theme assets, translations, fonts, and optional diagram files compatible with the production manifest.
- If the native request bridge changes, keep message IDs, headers, cookies, binary encoding, status handling, response limits, and Android fallback behavior aligned.
- If the desktop application scheme changes, keep privileged scheme registration, trusted frame checks, origin checks, internal request marking, response conversion, and the renderer request path aligned.
- If desktop streaming changes, keep flush, write, end, cancellation, disconnect, and backpressure behavior compatible with server producers and renderer consumers.
- If the desktop native surface changes, update the shared contract, preload exposure, main-process handler, and client feature use as one boundary.
- If desktop file import changes, keep user-granted file resolution and token-based import separate from arbitrary renderer-controlled paths.
- If desktop packaging changes, keep the local server, preload bundle, native database support, workers, copied client assets, locale resources, launcher metadata, icon and screenshot assets, sandbox permissions, and artifact checks aligned.
- If desktop startup or window behavior changes, keep first-paint release, reveal fallback, state restoration, state persistence, startup metrics, tray behavior, and platform title-bar rules aligned.
- If mobile WebView behavior changes, check Android interception separately from iOS scene, scheme, keyboard, safe-area, and file handling.
- If the clipper API changes, keep the handshake version, extension facade, capture payload, and server-side note and image handling compatible.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A renderer request reaches the desktop application scheme from a foreign frame | The request could receive the local server's trusted response path | Check the full frame chain before dispatch and reject a foreign origin |
| The renderer aborts a streamed request without closing the server side | A producer can keep writing and the client can hang | Propagate cancellation as a disconnect and stop accepting later chunks |
| A stream producer outruns the renderer | Unread response data can grow without bound | Apply a high-water mark and resume the producer only after the reader drains data |
| The desktop response bridge forwards incompatible transport headers or body status | Chromium can reject media, custom-scheme, or bodyless responses | Normalize headers, restore exact buffered length, and remove bodies for null-body statuses |
| The first-paint renderer never releases its gate | The window can remain hidden | Release after a short gate timeout and use a separate window reveal timeout |
| A saved window position is no longer visible on the current displays | The app can open outside the user's work area | Validate visible overlap and clear unsafe positions before window creation |
| The preload exposes a path-controlled import operation | Renderer code could ask the main process to read an arbitrary file | Resolve only paths granted by a real dropped file or use an import token |
| A desktop package lacks a preload, native dependency, client asset, or worker | The app cannot start or a native feature is unavailable | Assemble the full runtime and check packaged artifacts |
| A Flatpak package lacks its launcher metadata, icon, screenshots, or required filesystem and network permissions | Linux users can see an incomplete app listing or lose sync and file import access | Keep Flatpak metadata, runtime permissions, and packaged resources aligned |
| A startup metric or compile-cache write fails | Startup diagnostics are incomplete | Keep diagnostics non-blocking and retain in-memory startup behavior |
| Standalone runs outside HTTPS, localhost, or another secure context | The local runtime cannot start | Check the secure context before service-worker setup and show the startup error |
| Two standalone tabs open the database | Browser state can conflict or become stale | Give one tab database ownership and route other tabs through the service worker |
| A mobile WebView keeps an old service worker after switching to the native bridge | Requests go to a worker that no longer answers them | Remove stale registrations and reload only after a successful unregister |
| A standalone build lacks SQLite WebAssembly or share-theme assets | The workspace or share export cannot start or complete | Keep build copy rules, stable worker output, manifest files, and Capacitor output aligned |
| Android or iOS uses the wrong request mechanism | Local API, media, or font requests do not reach the worker | Keep Android interception and iOS scheme handling separate |
| Clipper and Trilium report different major protocol versions | The extension refuses the connection | Check the handshake before enabling capture actions |
| No desktop instance is found and the clipper has no valid server settings | Capture has no destination | Show the disconnected state and keep capture disabled |
Key files
| File | Why to read it |
|---|---|
| apps/…/main.ts | Desktop startup, local server composition, and host lifecycle |
| apps/…/entry.ts | Early desktop startup and compile-cache setup |
| apps/…/protocol.ts | Renderer-to-server request bridge, stream delivery, and request trust boundary |
| apps/…/first_paint_gate.ts | First-frame coordination between the renderer and native window |
| apps/…/window.ts | Window creation, reveal, platform behavior, and startup milestones |
| apps/…/window_state.ts | Safe window placement and state persistence across restarts |
| apps/…/preload.ts | Controlled native API exposed to the shared client |
| apps/…/build.ts | Desktop runtime assembly and packaged resources |
| apps/…/forge.config.ts | Installer, Flatpak, RPM, archive, and package checks |
| apps/…/org.triliumnotes.Trilium.metainfo.xml | Linux app identity, product capabilities, screenshots, and release presentation |
| apps/…/org.triliumnotes.Trilium.yml | Flatpak runtime permissions and desktop package assembly |
| apps/…/main.ts | Browser and Capacitor bootstrap, leadership, and host selection |
| apps/…/sw.ts | Local request routing, tab forwarding, shared pages, and backup streaming |
| apps/…/browser_router.ts | Browser request and response boundary for the local API |
| apps/…/browser_routes.ts | Shared API, share, maintenance, and custom-route integration |
apps/standalone/vite.config.mts | Standalone runtime assets, worker output, and share resources |
| apps/…/platform_provider.ts | Browser-owned storage and platform capability contract |
| apps/…/zip_provider.ts | Browser archive exchange without filesystem paths |
| apps/…/InterceptedResponse.java | Mobile response shape passed to the Android WebView |
| apps/…/index.ts | Browser-page capture and content preparation |
| apps/…/trilium_server_facade.ts | Destination discovery, protocol checks, and clipper API calls |
| apps/…/clipper.ts | Server contract that turns captures into notes and attachments |