Tauri command bridge
The Tauri command bridge connects the React webview to the Rust native host. It gives the frontend typed clients for app, vault, auth, setup, sync, sharing, tools, attachments, workspace, and desktop browser actions while Rust owns secrets, storage, OS access, and session rules. This page is a child of Desktop platform integration; see Native windows, tray, and events for window life cycle and event behavior. See Entry attachments, Vault lifecycle and persistence, and Import, export, and backup for the related product flows.
Bridge boundaries
Frontend client boundary
The frontend uses small API modules under src/api as its normal entry point to native commands. Each client names a Rust command, sends a plain argument object, and returns a typed promise such as UnlockResult, EntryMeta, Attachment, Settings, or BrowserStatus. src/…/client.ts is the shared boundary, so all command failures leave the webview in one known error shape.
The clients group calls by product area rather than by Rust module. This lets screens use a stable product API while Rust remains responsible for the work behind each call. The vault and attachment clients also keep secret-heavy file work out of the webview: the UI receives metadata and chosen paths, while Rust reads, seals, unseals, and writes the file. The browser client keeps the browser host contract in one place: settings can read or change host state, and consent surfaces can answer one named association or passkey request.
References: src/…/client.ts• L1-15 src/…/attachments.ts• L1-26 src/…/app.ts• L43-117 src/…/auth.ts• L1-36 src/…/vault.ts• L1-56 src/…/browser.ts• L1-43 src/…/browser.ts• L52-116
Native command surface
Rust exposes native actions through Tauri command functions. src-tauri/…/lib.rs registers the public command set in one handler, while src-tauri/src/commands groups the actions by product area. The registered set covers the app probe, auth, vault edits, attachments, import and export, password audit, generators, file tools, setup, sync, sharing, workspaces, and the desktop browser host.
The browser host commands are desktop-only. Their registration and command module use the same desktop condition, so browser controls are not part of the native surface on other targets. The registration list is the native contract, not a list of arbitrary Rust functions. A frontend client that names a command outside this list cannot reach the host, and a registered command that has no live frontend caller is unused surface. The contract test checks both sides where the command is included in the frontend contract.
References: src-tauri/…/lib.rs• L208-275 src-tauri/…/mod.rs• L1-25 src-tauri/…/attachments.rs• L68-138 src-tauri/…/audit.rs• L16-40 src-tauri/…/browser.rs• L44-106 src/…/contract.test.ts• L149-166
Command work boundary
Commands keep UI-facing entry points small and apply native guards before they touch protected data. Rust reports a locked vault, a changed session, an unsupported platform, a bad input, or an invalid file choice instead of allowing the webview to infer those states from partial results.
Work that may use the disk, a key derivation step, a whole-vault operation, a password audit, or a blocking OS call runs away from the IPC and UI thread. Background work that reports progress or changes state uses events rather than making the frontend wait for a long request. Session epochs also stop delayed work from writing into a vault that was locked or replaced while the request was running.
References: src-tauri/…/mod.rs• L33-91 src-tauri/…/attachments.rs• L68-89 src-tauri/…/audit.rs• L16-40 src-tauri/…/import.rs• L73-146 src-tauri/…/vault.rs• L192-249 src/…/events.ts• L6-17
Command and model contract
Request and response flow
The bridge transforms a typed frontend call into a registered Rust command and then returns a JSON-shaped result or a normalized error. This diagram shows the normal request path.
flowchart LR
UI[React screen] --> API[Typed API client]
API --> CALL[Shared call boundary]
CALL --> IPC[Tauri invoke]
IPC --> CMD[Registered Rust command]
CMD --> DOMAIN[Native state and services]
DOMAIN -->|DTO or result| CMD
CMD --> IPC
IPC --> CALL
CALL --> UI
CMD -->|Error| ERR[Error DTO]
ERR --> CALL
The same boundary applies to simple actions such as appReady, data actions such as revealing or saving an entry, file actions such as adding an attachment, and browser actions such as changing host settings. The result type tells the caller what it may use, while the native side decides whether the action is allowed and how it is completed.
References: src/…/client.ts• L4-15 src/…/attachments.ts• L5-26 src/…/app.ts• L100-117 src/…/browser.ts• L37-43 src-tauri/…/lib.rs• L208-275 src-tauri/…/vault.rs• L14-52
Wire models
Rust models define the data that crosses the bridge, and TypeScript mirrors the parts the webview can use. The main shared shapes are:
Entryis a kind-tagged credential payload. Itstypeselects the entry kind.EntryMetais the safe list projection. It carries display and search data without secret fields.Attachmentis file metadata only. Attachment bytes do not cross the bridge.UnlockResult,AttachmentUsage,Audit,Settings,Workspace, tool result types, andBrowserStatusdescribe app state and native utility results.- Import reports return counts, row errors, and a refreshed metadata list so the caller can update its view from one command result.
The two sides must agree on field names, optional fields, enum values, and result shape. Rust uses wire names such as camelCase where the frontend expects them, while the entry model keeps its established field names for compatibility. A missing optional field is not the same as an empty secret, so frontend entry defaults complete the shape before the UI uses it. Attachment metadata follows the same rule: optional MIME and creation data can be absent, while the file name and size remain part of the list contract. Browser status follows the same rule: browser availability, installed state, conflicts, and remembered extension clients arrive as one current snapshot.
References: src/…/types.ts• L8-26 src/…/types.ts• L155-219 src/…/types.ts• L197-214 src/…/tools.ts• L42-50 src/…/vault.ts• L32-47 src/…/browser.ts• L10-33 src-tauri/…/attachments.rs• L34-52 src-tauri/…/import.rs• L45-60 src/…/contract.test.ts• L190-275
Browser command contract
The browser bridge carries two kinds of desktop state. Settings commands return the complete host status after each change, while response commands return no data because they only answer a pending native request. This lets Settings redraw from native state and keeps each approval tied to the request that caused its dialog.
An association ask identifies an extension by its public key and its own request ID. A passkey ask identifies the site, origin, ceremony type, and possible accounts. The frontend sends the request ID back with the decision, so a late dialog cannot answer a later request. A forgotten client must associate again before it can use the open vault.
References: src/…/browser.ts• L3-32 src/…/browser.ts• L45-116 src-tauri/…/browser.rs• L49-106
Secret boundary
Rust keeps the master key, vault cipher, native store, and attachment bytes outside the webview. The frontend receives list metadata first and asks for one entry's secret fields only when it needs to view or edit that entry. A save sends the edited entry back to Rust for sealing.
Some secrets never cross the bridge at all. For example, passkey private keys are removed from revealed entries and restored from the native record when an edit is saved. Attachment files follow the same boundary: the webview sees names and sizes, while Rust moves the bytes between the selected file, encrypted storage, and the save destination. This keeps the webview useful for display without making it the owner of signing key material or stored file contents.
References: src/…/types.ts• L28-47 src/…/types.ts• L164-214 src/…/vault.ts• L1-30 src/…/attachments.ts• L4-26 src-tauri/…/attachments.rs• L1-5 src-tauri/…/attachments.rs• L104-123 src-tauri/…/vault.rs• L14-30 src-tauri/…/vault.rs• L59-95
Error contract
Error translation
Rust command failures cross the bridge as an object with a stable kind and a human-readable message. The optional retryAfterSecs value carries structured data for failed-password backoff. File size, file type, and attachment budget failures use named kinds, so the frontend can explain the limit without parsing native text. The frontend branches on kind, not on English message text.
The frontend translates user-actionable kinds into the current language. It keeps raw text for diagnostic failures such as file, parser, crypto, or other native errors. This split gives screens stable behavior while preserving useful detail for failures that do not have shared user copy.
References: src-tauri/…/error.rs• L158-230 src/…/errors.ts• L9-57 src/…/errors.ts• L62-159 src/…/client.ts• L9-14
Error and status consistency
Some long-running work reports failure through a status event instead of rejecting the command. Sync carries both the error text and its errorKind, so the same translation rules apply to a rejected command and to a background sync failure. Import and attachment commands instead return structured reports or named failures that let the caller distinguish partial row errors, duplicate rows, file limits, and a cancelled dialog.
The bridge test keeps the error union, Rust error kinds, and translated kinds aligned. It also checks that each production client reaches a registered command, that each event name has a native counterpart, and that optional entry fields have defaults on the TypeScript side.
References: src/…/sync.ts• L4-44 src/…/events.ts• L19-33 src/…/contract.test.ts• L228-275 src-tauri/…/import.rs• L45-60 src/…/errors.ts• L144-159
Capability permissions
Window capabilities
Tauri capabilities limit what the main window and installed plugins may do. The default capability applies on every platform and permits core behavior, file open and save dialogs, HTTP and HTTPS URL opening, and logging. The desktop capability adds title-bar dragging, the updater, and process controls for desktop builds.
These permissions protect plugin and window features. They are separate from the Rust command registration list: adding a frontend wrapper does not grant a plugin permission, and adding a plugin permission does not create a Rust command. File commands add a second native check through user-purpose grants, while the browser host is made desktop-only through its command registration boundary.
References: src-tauri/…/default.json• L1-15 src-tauri/…/desktop.json• L1-12 src-tauri/…/lib.rs• L65-126 src-tauri/…/mod.rs• L6-10 src-tauri/…/tools.rs• L16-55
File access grants
File-related commands use a native picker or a user-provided path under native checks. The picker records why the user chose a path, and later scan, attachment, or read commands accept only a matching grant. This keeps a webview string from becoming unrestricted native file access.
The same boundary supports image scans, environment-file reads, and attachments. A grant is tied to the purpose that opened it, and the consuming command spends that grant before it reads the file. The frontend gets the selected path or parsed result, while Rust controls which file the operation may open.
References: src/…/tools.ts• L55-87 src/…/attachments.ts• L9-15 src/…/imports.ts• L44-53 src-tauri/…/tools.rs• L16-83 src-tauri/…/attachments.rs• L68-89 src-tauri/…/attachments.rs• L142-167
Contract maintenance
Contract checks
The bridge has one source of truth on each side, but it is maintained by hand. src/…/contract.test.ts acts as a tripwire for drift across command names, event names, error kinds, optional entry fields, and the reached-client set. Test IPC mocks also use the registered command names so a renamed command fails in frontend tests instead of resolving silently.
When a command or model changes, update the Rust registration, the typed client, and the related wire type as one contract. When a failure changes, update the Rust kind, the TypeScript union, and its user-facing translation together. For attachment and import commands, keep the returned DTO or report aligned with the TypeScript result and with the refreshed-list behavior. For desktop browser commands, keep the desktop-only module, registration, and typed client aligned so non-desktop targets do not gain an invalid surface.
References: src/…/contract.test.ts• L12-29 src/…/contract.test.ts• L124-183 src/…/contract.test.ts• L228-275 src/…/attachments.ts• L1-26 src/…/vault.ts• L32-56 src/…/ipc.ts• L7-15 src/…/ipc.ts• L218-246 src-tauri/…/mod.rs• L1-25 src-tauri/…/attachments.rs• L34-52
Change checklist
When these files or sections are changed, remember to consider these:
- A command name or argument change must stay aligned between the API wrapper, the
generate_handler!registration, and IPC mocks. - A desktop-only browser command must keep its TypeScript client,
commands::browsermodule, and conditional native registration aligned across target builds. - A Rust model field change must preserve the TypeScript wire name, optional-field default, and any list-versus-reveal secrecy rule.
- An attachment model change must preserve the metadata-only response, the entry association, and the rule that bytes stay in Rust.
- An import report change must preserve the meaning of preview counts, duplicate counts, row errors, and the refreshed metadata list.
- A password audit change must preserve the opt-in breach check and the distinction between current password reuse and password history.
- A browser status change must preserve the whole-status response used after settings changes and the distinction between detected, installed, and conflicting browsers.
- A consent request change must preserve the request ID and timeout rules so an old dialog cannot answer a new request.
- A new
Errorvariant must updateError::kind,BackendErrorKind, anddescribeError; diagnostic-only kinds must remain deliberate. - A new event-driven result must update the event payload map, the native emitter, and the store that consumes the event.
- A new native plugin action must have a capability permission for the correct window and platform.
- A file-reading command must keep its picker purpose and path grant aligned with the command that consumes the path.
- A long-running command must keep its session epoch check so work cannot commit after a lock or workspace switch.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Frontend wrapper names a command that is not registered | The request cannot reach Rust | Contract test compares reached commands with the Tauri handler list |
| Browser client is built for a target without the matching native command surface | Browser settings or consent calls fail at the bridge | Keep the client and browser command module behind the same desktop boundary |
| A browser response uses an expired or different request ID | The user's decision approves nothing or the wrong flow cannot proceed | Native side accepts the response only for the currently pending ID |
| Rust adds an error kind without a TypeScript mapping | A screen may show raw or incorrect copy | Contract test compares Rust kinds with the frontend union and translations |
| A secret field is added to the list DTO | Locked or list views may expose vault data | Separate metadata and reveal models; keep secret fields in Entry only |
| Attachment bytes are placed in an entry result | Every reveal can expose file contents to the webview | Keep attachments as separate metadata and move file bytes only in Rust |
| A path is passed without the matching user grant | Native code could read a path the user did not select through the app | Picker grants a purpose and the reader consumes that purpose once |
| An attachment exceeds its file cap or vault budget | The file is not stored and the UI must explain the limit | Native add checks both limits before sealing and writing |
| A long native task runs on the IPC or UI thread | The window stops responding during key, disk, audit, or import work | Async commands hand blocking work to the blocking pool |
| A vault locks or changes while delayed work is running | Data can be written to the wrong session or the result can be stale | Capture an epoch and reject the result when the session differs |
| An import is applied row by row | A crash can leave a partial foreign file in the vault | Import parses and commits the accepted rows as one transaction |
| A desktop-only plugin permission is added to the shared capability | Mobile capability validation or builds can fail | Keep desktop permissions in capabilities/desktop.json |
Key files
| File | Why to read it |
|---|---|
| src/…/client.ts | Shared TypeScript-to-Tauri call boundary and error normalization |
| src/…/attachments.ts | Typed attachment list, add, usage, save, and delete contract |
| src/…/vault.ts | Typed reveal, save, archive, import, export, and backup-facing vault calls |
| src/…/tools.ts | Typed native utility, picker, scan, audit, and generator calls |
| src/…/types.ts | TypeScript view of entries, metadata, attachments, usage, unlock results, and workspaces |
| src/…/errors.ts | Stable error kinds and user-facing translation rules |
| src/…/contract.test.ts | Cross-checks for reached commands, events, errors, optional fields, and wire shape |
| src/…/events.ts | Typed event payloads that complement command responses |
| src-tauri/…/lib.rs | Native startup and the complete registered command surface |
| src-tauri/…/mod.rs | Shared session, target, and blocking-work rules for commands |
| src-tauri/…/attachments.rs | Native attachment limits, file grants, encryption boundary, and session checks |
| src-tauri/…/audit.rs | Native password strength, reuse, and optional breach-check result contract |
| src-tauri/…/import.rs | Native foreign import/export reports, duplicate handling, and transaction boundary |
| src-tauri/…/tools.rs | Native picker grants and file-based utility commands |
| src-tauri/…/vault.rs | Native entry reveal/save rules, secret preservation, and vault import/export calls |
| src-tauri/…/browser.rs | Native browser host status and user-response commands |
| src-tauri/…/models.rs | Rust wire models and secret-safe projections |
| src-tauri/…/error.rs | Rust error kinds and serialized error DTO |
| src-tauri/…/default.json | Main-window permissions shared by platforms |
| src-tauri/…/desktop.json | Desktop-only window and plugin permissions |