Open-Source Wikis

/

Tauri

/

Crates

/

tauri

tauri-apps/tauri

tauri

Active contributors: Lucas Fernandes Nogueira, Amr Bashir, Fabian-Lars

Purpose

crates/tauri is the application core: every Tauri app cargo-depends on this crate. It owns the lifecycle (App, AppHandle, Builder), the in-process IPC bridge, the plugin loop, the window/webview manager, scopes and resources, the menu/tray modules, the path API, and the protocol handlers. Backend-agnostic logic lives here; backend-specific code lives in crates/tauri-runtime-wry. The crate is 1,254 lines just at lib.rs and roughly 25k lines including modules.

Directory layout

crates/tauri/
├── Cargo.toml                  # 11 features incl. wry, tray-icon, isolation, tracing, specta, dynamic-acl
├── build.rs                    # emits cfg(desktop)/cfg(mobile)/cfg(target_vendor="apple") aliases
├── permissions/                # default ACL permissions for built-in commands (event, app, window, …)
├── mobile/                     # Android (Kotlin) and iOS (Swift) glue
├── scripts/                    # init scripts injected into the webview
├── src/
│   ├── lib.rs                  # crate root and public re-exports
│   ├── app.rs                  # 2,636 lines: Builder, App, AppHandle, run loop hooks
│   ├── manager/                # AppManager: tracks windows, webviews, plugins
│   ├── webview/                # Webview, WebviewWindow, WebviewBuilder
│   ├── window/                 # Window, WindowBuilder
│   ├── menu/                   # menu, submenu, tray menu, predefined items
│   ├── tray/                   # system tray icon
│   ├── ipc/                    # commands, channels, authority, format_callback
│   ├── plugin.rs / plugin/     # plugin trait, lifecycle, mobile bridge
│   ├── path/                   # cross-platform path API
│   ├── protocol/               # tauri:// , asset:// , isolation handlers
│   ├── scope/                  # ACL scope evaluation helpers
│   ├── resources/              # ResourceTable, ResourceId
│   ├── pattern.rs              # brownfield vs isolation pattern
│   ├── async_runtime.rs        # the project's Tokio facade
│   ├── event/                  # event bus
│   └── test/                   # mock app/runtime (gated by `test` feature)
└── test/                       # fixture projects exercised by integration tests

Key abstractions

Type File Role
Builder<R> crates/tauri/src/app.rs Fluent builder. Consumes plugins, runtime, invoke handler, and produces an App.
App<R> / AppHandle<R> crates/tauri/src/app.rs The constructed app and a cheap clone-able handle to it.
Manager<R> (trait) crates/tauri/src/lib.rs, manager/mod.rs Trait implemented by App/AppHandle/Window/Webview for shared accessors.
AppManager<R> crates/tauri/src/manager/mod.rs Central registry of windows, webviews, plugin store, listeners.
Window<R> / WindowBuilder crates/tauri/src/window/ Native windows (TAO).
Webview<R> / WebviewBuilder / WebviewWindow crates/tauri/src/webview/ WRY webviews; WebviewWindow is "one window with one webview", the common case.
RuntimeAuthority crates/tauri/src/ipc/authority.rs Resolves whether a given webview can call a given command with given args.
Channel crates/tauri/src/ipc/channel.rs Long-lived Rust→JS streaming channel (binary-safe).
Plugin<R> / PluginStore<R> / Builder (plugin) crates/tauri/src/plugin.rs Trait, runtime registry, and builder for Tauri plugins.
Menu, Submenu, MenuItem, CheckMenuItem, IconMenuItem crates/tauri/src/menu/ Desktop menu API backed by muda.
TrayIconBuilder / TrayIcon crates/tauri/src/tray/ System tray API, gated by the tray-icon Cargo feature.
ResourceTable, Resource, ResourceId crates/tauri/src/resources/ Hand JS a u32 handle to a Rust-owned resource.
ipc::CommandArg crates/tauri/src/ipc/command.rs Trait that powers extractor types like State, Window, AppHandle.
protocol::asset / protocol::isolation crates/tauri/src/protocol/ Custom URI scheme handlers.

How it works

sequenceDiagram
    participant JS as WebView (JS)
    participant Wry as tauri-runtime-wry
    participant Mgr as AppManager
    participant Auth as RuntimeAuthority
    participant Cmd as Command function

    JS->>Wry: window.__TAURI_INTERNALS__.invoke(name, args)
    Wry->>Mgr: on_message(InvokeRequest)
    Mgr->>Auth: resolve_access(webview, name, args)
    Auth-->>Mgr: Allow / Deny
    alt Allowed
        Mgr->>Cmd: dispatch (with extractors)
        Cmd-->>Mgr: serde_json::Value | error
        Mgr-->>Wry: serialised response
        Wry-->>JS: resolve / reject promise
    else Denied
        Mgr-->>Wry: error
        Wry-->>JS: reject promise
    end

The same AppManager also drives the event bus, plugin lifecycle hooks (on_event, on_drop), and the path/resource APIs. Plugins register via Builder::plugin(...) and live for the duration of the app.

Cargo features (selection)

The full list is in crates/tauri/Cargo.toml and documented inline in crates/tauri/src/lib.rs. Highlights:

  • wry (default) — pull in tauri-runtime-wry as the runtime.
  • tray-icon — gate the tray module.
  • tracing — instrument startup, IPC, custom protocol, updater, plugin hooks with tracing spans.
  • isolation — enable the isolation pattern.
  • custom-protocol — flag set by the CLI in production builds; switches asset loading from the dev server to the embedded bundle.
  • protocol-asset — register the asset:// custom protocol.
  • dynamic-acl (default) — allow Manager::add_capability at runtime.
  • specta — emit specta types for commands so you can autogenerate JS bindings.
  • compression — compress embedded assets.
  • webview-data-url, image-png, image-ico, macos-private-api, devtools, native-tls/rustls-tls, linux-libxdo — narrower toggles.

Integration points

  • Up: every Tauri app and plugin imports tauri. Public surface is pub use ... in crates/tauri/src/lib.rs.
  • Down: depends on tauri-runtime (trait), tauri-runtime-wry (default impl), tauri-utils (config + ACL types), tauri-macros (proc macros).
  • Sideways: the build script crates/tauri/build.rs defines the desktop and mobile cfg aliases that the rest of the crate uses; it runs at compile time of tauri itself.

Entry points for modification

Goal Start here
Add a method to WebviewWindowBuilder crates/tauri/src/webview/webview_window.rs and the runtime trait
Change how a command is dispatched crates/tauri/src/ipc/mod.rs and crates/tauri/src/ipc/command.rs
Add a new built-in event crates/tauri/src/event/
Change ACL resolution logic crates/tauri/src/ipc/authority.rs
Add a new plugin lifecycle hook crates/tauri/src/plugin.rs
Tweak menu builder crates/tauri/src/menu/builders/
Add a new path API crates/tauri/src/path/

Cross-references

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

tauri – Tauri wiki | Factory