Introducing a new way to review your PRs.

Read the announcement

triliumnext / trilium

Build your personal knowledge base with Trilium Notes

View on GitHub

20 documents · Updated Nov 23, 2026

docs / server-platform

Server platform

The server platform is the Node.js service that makes one Trilium document available to browser, desktop, mobile, sync, and automation clients. It prepares the shared product core, supplies host services, composes the client-facing application, and keeps persistence and client updates behind clear boundaries.

System boundary

The server joins clients to shared note behavior and durable state. It receives a request or background task, applies the shared product contract, stores approved changes, and returns a response or live event without making any client the source of truth.

This diagram shows the platform boundary and the main direction of state flow.

flowchart LR
    Client[Browser, desktop, mobile, or automation client]
    App[Node server application]
    Core[Shared product core]
    Providers[Runtime providers]
    Document[(SQLite document)]
    Events[HTTP responses and live events]
    Client --> App --> Core
    Core --> Providers
    Providers --> Document
    Core --> Events --> Client

Deployment boundary

The same server capability runs as a dedicated service or inside the desktop application. A dedicated service supports browser and mobile use as well as synchronization across devices. The embedded service runs only while the desktop application runs.

The desktop server is disabled for network use by default. When network access is off, the web application and published notes are disabled, while ETAPI, MCP, and supported local integrations remain available on the local device. Enabling network access allows the web interface and sharing surface to answer on the local network.

Desktop network access limits which web-facing services can answer beyond the local device. A reverse proxy can provide the public entry point and TLS. It must preserve the client address rules and live connection upgrades.

References: apps/…/help_content.json• L4 apps/…/help_content.json• L7 apps/…/help_content.json• L10-18 apps/…/help_content.json• L21-24

Startup lifecycle

Startup makes the document and its host services ready before it exposes normal client work. It restores an interrupted database change when needed, opens the document, initializes the shared core, builds the application, binds the listener, attaches supported live messaging, and then marks the service ready.

The startup sequence has these stages:

  1. Load configuration and resolve the data and resource locations.
  2. Recover an interrupted document restore.
  3. Open the SQLite document in the selected read-write or read-only mode.
  4. Register Node providers and platform state with the shared core.
  5. Build the web application and bind HTTP, HTTPS, or the selected local socket.
  6. Attach live messaging only when the provider supports an HTTP connection.
  7. Register OCR and server intelligence extensions.
  8. Start normal background work and publish readiness.

Setup state can keep normal document access closed while the first-run wizard or a restore replaces the document. A failure before readiness stops the process. A later background failure is contained and reported so that normal note access can continue.

References: apps/…/main.ts• L12-25 apps/…/core_init.ts• L31-102 apps/…/www.ts• L27-94 apps/…/routes.ts• L59-74 apps/…/process_errors.ts• L14-23

Application composition

The application composition layer turns the prepared core into a client-facing service. Middleware establishes request context and security behavior before the server selects static resources, setup, authentication, shared APIs, integrations, publishing, or feature services.

Request surface

The HTTP application serves the web client and routes requests to the product boundaries. It applies cross-origin rules, security headers, request parsing, compression where safe, session handling, and the desktop network gate before the main route groups.

The bootstrap response tells each client whether the document is initialized and whether the request is a trusted desktop renderer. It supplies the matching setup, login, or signed-in application state. Browsers that reach a desktop listener do not inherit the desktop renderer's trust.

References: apps/…/app.ts• L29-35 apps/…/app.ts• L37-107 apps/…/app.ts• L115-134 apps/…/index.ts• L20-109 apps/…/index.ts• L113-193

Route composition

The route registry connects server-only paths with shared route builders. Shared builders keep common note contracts in the core. Node routes add host-dependent work such as network discovery, metrics, OCR, media access, imports, resources, and local database operations.

The registry also selects the trust path for each client. Browser sessions use session and CSRF checks. ETAPI and integrations use tokens where a browser session is not suitable. MCP uses its own token guard. Desktop-only access uses the trusted renderer or local extension origin.

References: apps/…/routes.ts• L48-110 apps/…/routes.ts• L118-176 apps/…/routes.ts• L182-220 apps/…/route_api.ts• L31-48 apps/…/route_api.ts• L71-121

Authentication boundary

Authentication connects a client to protected HTTP and live access. Local password login can include a time-based one-time password. OpenID Connect delegates sign-in to an external identity provider. Sync and token clients use separate credential checks because they do not follow the browser login flow.

All credential paths share a failed-login limit. A successful login creates a fresh session. A desktop browser request still follows the normal web trust path even when the server runs inside the desktop application.

References: apps/…/login.ts• L13-21 apps/…/login.ts• L57-92 apps/…/login.ts• L125-141 apps/…/login.ts• L16-67 apps/…/login.ts• L69-83

Live client messaging

Live messaging carries committed entity changes to connected clients so they do not need to poll for every update. The server attaches a WebSocket endpoint only when the active messaging provider can use the HTTP listener. A desktop host may use another transport and therefore does not require a WebSocket endpoint.

References: apps/…/core_init.ts• L51-61 apps/…/www.ts• L73-86 apps/…/ws_messaging_provider.ts• L13-25 apps/…/ws_messaging_provider.ts• L39-109

Operational interfaces

The platform exposes a health result for service checks, metrics for monitoring, and network addresses for setup and synchronization screens. CPU architecture checks run in the background so startup does not wait for a host command that is not needed to serve the first page.

References: apps/…/routes.ts• L123-131 apps/…/metrics.ts• L8-20 apps/…/system_info.ts• L20-33 apps/…/system_info.ts• L41-75 apps/…/routes.ts• L218-220

Runtime providers

Runtime providers translate host capabilities into contracts that the shared core can use. This lets shared product behavior stay independent of Node, Electron, file paths, native libraries, sockets, and operating-system APIs.

Provider roleShared capability
Platform and contextHost details, paths, process control, and request-scoped state
DatabaseSQLite access, transactions, document replacement, and close behavior
Request and cryptographyControlled network access and native cryptographic work
MessagingLive client events and client messages
Backup, archive, and image servicesDurable transfer, export formats, and media preparation
Feature servicesLogging, help, OCR, resources, and server-side intelligence

The server passes these providers to the core during initialization. Child pages cover the persistence services in Server storage and note services, the HTTP and publishing surface in Server HTTP API and sharing, and server-side intelligence in Server intelligence and automation.

References: apps/…/core_init.ts• L6-23 apps/…/core_init.ts• L39-102 packages/…/index.ts• L179-244 packages/…/types.ts• L21-53 packages/…/types.ts• L21-67

Configuration boundary

Configuration defines how the service binds to its host and which boundaries it exposes. Environment values override config.ini, and built-in defaults provide the last value. The settings cover the listener, HTTPS, proxy trust, sessions, network access, synchronization, backups, read-only mode, and server features.

Most settings take effect at startup. This gives long-running services and containers a stable operating mode.

References: apps/…/config.ts• L1-20 apps/…/config.ts• L224-265 apps/…/config.ts• L587-635 apps/…/www.ts• L123-159 apps/…/www.ts• L165-210

Data and resource boundary

The data directory is the durable home for the document and server state. It also supports configuration, logs, backups, temporary work, caches, and downloaded feature resources. Application assets remain read-only inputs, while managed resources stay with the data so an application update does not replace them.

Managed resources become usable only after the downloaded files pass their declared size and SHA-256 checks. This keeps optional feature files separate from the document while making their state visible to the application.

References: apps/…/data_dir.ts• L16-112 apps/…/resource_dir.ts• L4-19 apps/…/resources.ts• L120-215 apps/…/resources.ts• L221-305 apps/…/resources.ts• L7-41

Outbound request boundary

The request provider is the controlled path from server features to other HTTP services. It uses a strict policy for URLs found in notes. It uses a separate policy for operator-configured service endpoints because those endpoints have a different trust level.

Note-linked requests reject private or reserved addresses, keep the connection on the checked address, limit redirects, and bound response data. Configured endpoints can use approved private services but do not follow redirects while carrying credentials.

References: apps/…/request.ts• L204-237 apps/…/request.ts• L241-311 apps/…/safe_fetch.ts• L37-55 apps/…/safe_fetch.ts• L74-107 apps/…/safe_fetch.ts• L212-277

Host work boundary

Large or host-sensitive work stays behind controlled services. Image work can use bounded workers. Imports use temporary files and progress reporting. OCR adds derived text through the document model. External agents and model tools run outside the main server request path and report failure to the client instead of taking down the service.

These features use the same providers and request context as normal note work. Their product behavior and operational interfaces are described in Server intelligence and automation.

References: apps/…/image_worker_pool.ts• L1-25 apps/…/image_worker_pool.ts• L64-149 apps/…/importer.ts• L114-242 apps/…/ocr_service.ts• L108-121 apps/…/claude_agent.ts• L282-405

Persistence and client boundaries

The server keeps one durable document behind the shared core. A client request becomes shared state inside a transaction, the database commits that state, and the resulting entity changes return to clients through HTTP or live messaging.

Persistence boundary

The database provider owns the native SQLite connection and file lifecycle. The shared core owns note rules, queries, transactions, migrations, and its in-memory view of the document. A successful commit publishes entity changes. A rollback restores the in-memory view when a failed transaction changed tracked state.

Database initialization, restore, backups, and note services are covered in Server storage and note services.

References: apps/…/sql_provider.ts• L9-89 apps/…/core_init.ts• L39-75 packages/…/types.ts• L21-53 apps/…/route_api.ts• L87-103

Client transport boundary

HTTP carries page loads, authentication, API calls, setup, uploads, downloads, integrations, publishing, and feature services. Live messaging carries committed changes after the client passes its connection check. The desktop renderer can use the same application surface through its trusted in-process path.

Large imports and share-target files use temporary transfer state instead of requiring the whole request to remain in memory. The server owns cleanup when a request closes or a process ends.

References: apps/…/routes.ts• L54-74 apps/…/routes.ts• L93-110 apps/…/routes.ts• L167-187 apps/…/route_api.ts• L199-212 apps/…/route_api.ts• L222-263 apps/…/route_api.ts• L331-365

Published content boundary

Published notes provide a read-focused surface for people who do not use the main application. The server checks share access, reads through a restricted view, renders the selected content, and applies visibility rules before returning it. Public search uses the same access rules as direct reads.

HTTP APIs and publishing details are covered in Server HTTP API and sharing.

References: apps/…/share_provider.ts• L12-51 apps/…/routes.ts• L13-100 apps/…/routes.ts• L128-155 apps/…/routes.ts• L189-203

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep provider registration aligned with every service used before the application reaches readiness.
  • Keep database open, restore, setup state, transaction hooks, and readiness in the same lifecycle order.
  • Keep shared route registration aligned with the server's authentication, CSRF, transaction, upload, and response contracts.
  • Keep the desktop network gate ahead of every route that must be local-only. Keep trusted renderer access separate from browser access.
  • Keep WebSocket attachment aligned with messaging-provider capability and reverse-proxy upgrade support.
  • Keep configuration precedence aligned with listener binding, HTTPS, proxy trust, data paths, and container deployment.
  • Keep outbound request policy aligned with URL trust. Note content must not receive operator-endpoint access.
  • Keep temporary upload ownership aligned with process lifetime, response close, size limits, and importer expectations.
  • Keep resource definitions aligned with download progress, license state, file integrity, and data-directory placement.
  • Keep bootstrap auth and view selection aligned with the per-request desktop marker rather than the process-wide desktop build flag.
  • Keep export format support aligned with the shared export contract and the CSS resources available in development and production.

Important failure modes

TriggerConsequenceGuard
Startup reports ready before the document or required services are usableClients reach partial state and fail in less clear waysComplete core setup, application binding, and provider registration before readiness
A desktop network gate is registered after a protected routeA local-only service can answer a network requestRegister the gate before static, web, sharing, API, and MCP paths
A browser on a desktop listener is treated as the trusted rendererThe browser skips login or receives renderer-only stateCheck the request marker rather than the process-wide desktop flag
A transaction commits without publishing its entity changesConnected clients keep stale note stateKeep commit hooks connected to live messaging
A reverse proxy drops the live connection upgradeThe application loads but clients do not receive updatesForward upgrade headers and configure the trusted proxy boundary
A note-linked URL reaches a private addressNote content can make the server contact an internal serviceValidate resolved addresses and pin the checked connection
A resource passes download completion without integrity checksA feature can load incomplete or corrupt filesRequire declared size and SHA-256 checks before use
A large import remains buffered in the requestMemory use grows with archive sizeStream suitable archives from temporary files and clean them after the response
An unsupported export format reaches the provider factoryExport fails instead of producing a defined resultReject formats outside the shared export contract

Key files

FileWhy to read it
apps/…/main.tsShows the Node entry point and fatal startup handling.
apps/…/core_init.tsShows document opening, provider registration, setup state, and transaction hooks.
apps/…/www.tsShows listener creation, live messaging attachment, feature registration, and readiness.
apps/…/app.tsShows middleware order and application composition.
apps/…/routes.tsShows how server-only and shared routes form the client surface.
apps/…/index.tsShows bootstrap state for setup, login, desktop, mobile, and signed-in clients.
apps/…/route_api.tsShows request context, transactions, response handling, and upload boundaries.
apps/…/sql_provider.tsShows the Node-to-core database boundary.
apps/…/config.tsDefines deployment setting resolution.
apps/…/data_dir.tsDefines durable and temporary server paths.
apps/…/request.tsShows the controlled outbound request boundary.
apps/…/safe_fetch.tsShows address, redirect, and response limits for note-linked requests.
apps/…/ws_messaging_provider.tsShows live client access and transport capability.
apps/…/resources.tsShows managed runtime resource state and integrity checks.
apps/…/factory.tsShows how the server supplies export providers and production or development content styles.
apps/…/share_provider.tsShows the read-only boundary for published content.
packages/…/index.tsDefines the shared provider set supplied by a host.
packages/…/types.tsDefines database capabilities expected by the shared core.
packages/…/types.tsDefines the live messaging contract.