-
Backlinks
-
Branch prefixes
-
Cache
Trilium implements a sophisticated three-tier caching system to optimize performance and enable offline functionality:
Located at: apps/server/src/becca/
Responsibilities:
Key Files:
Located at: apps/client/src/services/froca.ts
Responsibilities:
Loading Strategy:
Located at: apps/server/src/share/
Responsibilities:
Server-Side:
Client-Side:
Entity Change Tracking:
Sync Protocol:
-
CI
-
Deleted notes
-
Demo document
The demo document is an exported .zip that resides in apps/server/src/assets/db/demo.zip.
During on-boarding, if the user selects that they are a new user then the demo.zip is imported into the root note.
Run:
And then do the on-boarding again.
-
Entities
Trilium's data model is based on five core entities:
1. BNote (apps/server/src/becca/entities/bnote.ts)
2. BBranch (apps/server/src/becca/entities/bbranch.ts)
3. BAttribute (apps/server/src/becca/entities/battribute.ts)
4. BRevision (apps/server/src/becca/entities/brevision.ts)
5. BAttachment (apps/server/src/becca/entities/battachment.ts)
6. BBlob (apps/server/src/becca/entities/bblob.ts)
The frontend uses a widget system for modular, reusable UI components.
-
Hidden notes
-
Icons
Icons are stored in images and in images/app-icons.
The favicon is served dynamically via serve-favicon, using the icon in images/app-icons/win/icon.ico.
All the icons are now built off of the SVGs in the images directory using the bin/create-icons.sh script.
These are stored in images:
-
Internationalisation / Translations
During the initial development of Trilium Notes, internationalisation was not considered as it was meant to be an English-only product.
As the application and the user base grows, it makes sense to be able to reach out as many people as possible by providing translations in their native language.
The library used is i18next.
The translations are formatted as JSON files and they are located in src/public/translations.
-
Launchers
Launchers are items that are displayed in the launcher bar (left side of the screen). They are of two different types:
Regardless of the type, new launchers are added at server level, inside hidden_subtree.ts file.
-
Note Revisions
The revision API on the server side is managed by apps/server/src/routes/api/revisions.ts
-
Note Types
-
Options
Add the import to the service (make sure the relative path is correct):
Them simply read the option:
Refer to this example in backup.tsx:
To trigger a UI refresh (e.g. utils#reloadFrontendApp), simply pass a true as the second argument to useTriliumOption methods.
-
Printing and exporting to PDF
Note printing is handled by note_detail.js, in the printActiveNoteEvent method. Exporting to PDF works similarly.
Both printing and exporting as PDF use the same mechanism: a note is rendered individually in a separate webpage that is then sent to the browser or the Electron application either for printing or exporting as PDF.
The webpage that renders a single note can actually be accessed in a web browser.
-
Protected entities
The following entities can be made protected, via their isProtected flag:
-
Share
The share theme represents the layout, styles and scripts behind the Share notes functionality. The current implementation is a heavy adaptation of trilium.rocks which is a third-party share theme.
The share theme has no build of its own: the client's Vite build bundles it, through shareTheme() in apps/client/vite-plugins.mts, which standalone's build uses as well.
The share subsystem is in packages/trilium-core/src/share, so that every runtime that carries core can serve it:
-
Synchronisation
Trilium implements a bidirectional synchronization system that allows users to sync their note databases across multiple devices (desktop clients and server instances). The sync protocol is designed to handle:
Every modification to any entity (note, branch, attribute, etc.) creates an entity change record:
Key Properties:
Each Trilium installation tracks:
When an entity is modified:
Entity modification triggers:
Step 1: Client Initiates Sync
Step 2: Server Responds with Status
Step 3: Decision
-
Syntax highlighting
The first step to supporting a new language for either code blocks or code notes is to define the MIME type. Go to mime_type.ts in packages/commons and add a corresponding entry:
Where mdLanguageCode is a Markdown-friendly name of the language.
The Highlight.js instance in Trilium identifies the code to highlight by the mime type mappings defined in syntax_highlighting.ts in packages/highlightjs.
There are three possible cases, all involving modifying the byMimeType record:
-
Themes
-
Web Clipper
The Web Clipper is present in the monorepo in apps/web-clipper. It's based on WXT, a framework for building web extensions that allows very easy development and publishing.
Originally the Web Clipper supported only Manifest v2, which made the extension incompatible with Google Chrome. #8494 introduces Manifest v3 support for Google Chrome, alongside with Manifest v2 for Firefox.