Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 39 ยท Getting Started

Tauri Project Structure Tour

A guided tour of a Tauri 2 project: the frontend folder, src-tauri, Cargo.toml, tauri.conf.json, lib.rs, main.rs, capabilities and icons, and what each file is for.

A fresh Tauri project looks like a web project with one extra folder. Knowing what lives where saves hours later. This lesson tours the layout and reads the most important Rust file line by line.

The big picture

TEXT
hello-tauri/
โ”œโ”€โ”€ package.json          frontend dependencies and scripts
โ”œโ”€โ”€ index.html            frontend entry (varies by template)
โ”œโ”€โ”€ src/                  frontend source (JS/TS, CSS, components)
โ””โ”€โ”€ src-tauri/            everything Rust and native
    โ”œโ”€โ”€ Cargo.toml        Rust dependencies and crate settings
    โ”œโ”€โ”€ build.rs          build script (runs tauri-build)
    โ”œโ”€โ”€ tauri.conf.json   app configuration
    โ”œโ”€โ”€ capabilities/     permission files (what the frontend may do)
    โ”œโ”€โ”€ icons/            app icons for all platforms
    โ””โ”€โ”€ src/
        โ”œโ”€โ”€ main.rs       thin desktop entry point
        โ””โ”€โ”€ lib.rs        the real app code
flowchart TB
  R["project root"] --> F["frontend: src/, index.html, package.json"]
  R --> T["src-tauri/"]
  T --> C["Cargo.toml + build.rs"]
  T --> J["tauri.conf.json"]
  T --> P["capabilities/*.json"]
  T --> S["src/lib.rs + main.rs"]
  T --> I["icons/"]

Everything outside src-tauri is a normal web project.

The frontend side

The frontend is whatever the template gave you. Tauri only needs two things from it: a dev server URL while you work, and a folder of built static files for release. Those are set in tauri.conf.json and covered in Configuration files.

src-tauri/Cargo.toml

This is a normal Rust manifest. The important parts:

TOML
[package]
name = "hello-tauri"
version = "0.1.0"
edition = "2021"

[lib]
name = "hello_tauri_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

[build-dependencies]
tauri-build = { version = "2", features = [] }

[dependencies]
tauri = { version = "2", features = [] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

The [lib] section exists because the same code is built as a library so that mobile platforms can load it. The tauri dependency is the framework; serde converts Rust values to and from JSON for IPC.

src-tauri/src/main.rs and lib.rs

main.rs is deliberately tiny:

Rust
// Prevents an extra console window on Windows in release builds.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
    hello_tauri_lib::run()
}

All the real code lives in lib.rs, which is why mobile can reuse it:

Rust
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_opener::init())
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Read it from the bottom up:

  • tauri::Builder::default() starts configuring the application.
  • .plugin(...) registers a plugin (here one that opens links and files).
  • .invoke_handler(generate_handler![greet]) tells Tauri which commands the frontend may call.
  • .run(tauri::generate_context!()) loads your configuration (embedded at compile time) and starts the event loop. It does not return until the app quits.
  • #[tauri::command] turns an ordinary function into something callable from JavaScript.
  • #[cfg_attr(mobile, tauri::mobile_entry_point)] marks run as the entry point on Android and iOS.

capabilities/default.json

Tauri 2 denies everything by default. A capability file lists which windows may use which permissions:

JSON
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default",
  "description": "Permissions for the main window",
  "windows": ["main"],
  "permissions": ["core:default", "opener:default"]
}

If a plugin call fails with "not allowed", a missing permission here is usually the reason. A later chapter covers permissions in depth.

icons and gen

icons/ holds the icon set used for installers and the task bar. You can regenerate every size from one square PNG with npx tauri icon path/to/icon.png. A gen/ folder appears for generated schemas and mobile projects. Do not edit generated files by hand; most teams commit them only when the mobile projects live there.

Try it: a project explorer (stand-in)

This stand-in is a tiny lookup that explains a path, the way you might want a cheat sheet while you learn the layout.

Node.js Stand-in: what is this file for?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Try it: the builder pattern (stand-in)

The Rust Builder is a fluent configuration chain: each call returns the builder so you can chain more. This JavaScript stand-in has the same shape, so the Rust reads less strangely.

Node.js Stand-in: a Builder that collects commands and plugins

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where does the real application code live in a Tauri 2 project?

    main.rs only calls run(); lib.rs holds the Builder so that mobile targets can reuse it.
  2. 2. What does generate_handler! do?

    Only commands listed in generate_handler! can be called with invoke.
  3. 3. What is the purpose of the capabilities folder?

    Capabilities tie windows to permissions so the frontend can only do what you allow.
  4. 4. How do you regenerate all icon sizes from one image?

    tauri icon produces the platform icon set from a single square source image.

Summary

  • A Tauri project is a web project plus src-tauri.
  • lib.rs configures the Builder, plugins and commands; main.rs only calls it.
  • tauri.conf.json configures the app; capabilities/ grants permissions.
  • Cargo.toml lists Rust dependencies, including tauri and serde.
  • Icons come from one source image via tauri icon.

Next: The dev loop and building a release