A small app with a Rust core.
A Tauri 2 notes app with a web UI, Rust commands, and app-data persistence.
Download this project ↓01 The shape of the build
Tauri combines a system webview frontend with a Rust backend. The frontend invokes registered commands through the Tauri API; it does not receive arbitrary filesystem access. This project stores one bounded UTF-8 note under the app’s data directory, using a separate pure-Rust note-core crate for validation and storage tests. The web UI loads the saved note and sends edits through a narrow save_note command. Follow the linked platform prerequisites before installing the CLI. The app uses packaged HTML, CSS, and JavaScript, so no frontend development server is needed.
- 1
Install the platform prerequisites from the setup panel, then install the local Tauri CLI with npm install.
- 2
Keep validation and fixed-path persistence in the independent note-core crate.
- 3
Register only load_note and save_note, resolving their directory through AppHandle.
- 4
Invoke commands through window.__TAURI__.core.invoke; show errors as text.
- 5
Run the app, save a note, close it, and reopen to verify persistence.
02 Get it running
Install Rust stable and extract this project’s ZIP. Run these commands from the extracted tauri-notes folder. The full workbench keeps it under cookbook/tauri-notes.
cargo test --manifest-path note-core/Cargo.toml
npm install
npm run dev
# Build an unbundled native executable:
npm run buildThe native window loads a note, saves it to the app-data directory, and restores it on the next launch. Notes over 64 KiB are rejected. The core tests run without Tauri system libraries.
First builds download dependencies. The included Cargo.lock files record the versions resolved during authoring. Use --locked with Cargo commands when you want to enforce those resolutions.
03 The complete source
Every source file below is also in the download. Start with the manifest, then follow the Rust entry point and any UI or test files.
The project download also includes the PNG and ICO app icons used by the native build.
package.json1 lines +
{"name":"build-lab-tauri-notes","version":"0.1.0","private":true,"scripts":{"dev":"tauri dev","build":"tauri build --no-bundle"},"devDependencies":{"@tauri-apps/cli":"^2"}}note-core/Cargo.toml9 lines +
[package]
name = "note-core"
version = "0.1.0"
edition = "2024"
[dependencies]
[workspace]note-core/src/lib.rs55 lines +
use std::{fs, io, path::Path};
pub const MAX_BYTES: usize = 64 * 1024;
pub fn validate(text: &str) -> Result<(), &'static str> {
if text.len() > MAX_BYTES {
Err("note exceeds 64 KiB")
} else {
Ok(())
}
}
pub fn load(directory: &Path) -> io::Result<String> {
use std::io::Read;
let file = match fs::File::open(directory.join("note.txt")) {
Ok(file) => file,
Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(String::new()),
Err(error) => return Err(error),
};
let mut bytes = Vec::new();
file.take((MAX_BYTES + 1) as u64).read_to_end(&mut bytes)?;
if bytes.len() > MAX_BYTES {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"saved note exceeds 64 KiB",
));
}
String::from_utf8(bytes).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}
pub fn save(directory: &Path, text: &str) -> io::Result<()> {
validate(text).map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
fs::create_dir_all(directory)?;
fs::write(directory.join("note.txt"), text)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bounds() {
assert!(validate("").is_ok());
assert!(validate(&"a".repeat(MAX_BYTES)).is_ok());
assert!(validate(&"a".repeat(MAX_BYTES + 1)).is_err());
}
#[test]
fn round_trip() -> io::Result<()> {
let stamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos();
let dir =
std::env::temp_dir().join(format!("build-lab-note-{}-{stamp}", std::process::id()));
assert_eq!(load(&dir)?, "");
save(&dir, "hello 🦀")?;
assert_eq!(load(&dir)?, "hello 🦀");
fs::remove_dir_all(dir)?;
Ok(())
}
}src-tauri/Cargo.toml11 lines +
[package]
name = "build-lab-notes"
version = "0.1.0"
edition = "2024"
[dependencies]
tauri = { version = "2", features = [] }
note-core = { path = "../note-core" }
[build-dependencies]
tauri-build = { version = "2", features = [] }
[workspace]src-tauri/build.rs3 lines +
fn main() {
tauri_build::build()
}src-tauri/src/main.rs25 lines +
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::Manager;
#[tauri::command]
fn load_note(app: tauri::AppHandle) -> Result<String, String> {
let directory = app
.path()
.app_data_dir()
.map_err(|_| "app data directory unavailable".to_owned())?;
note_core::load(&directory).map_err(|_| "could not load the note".to_owned())
}
#[tauri::command]
fn save_note(app: tauri::AppHandle, text: String) -> Result<(), String> {
note_core::validate(&text).map_err(str::to_owned)?;
let directory = app
.path()
.app_data_dir()
.map_err(|_| "app data directory unavailable".to_owned())?;
note_core::save(&directory, &text).map_err(|_| "could not save the note".to_owned())
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![load_note, save_note])
.run(tauri::generate_context!())
.expect("Tauri app could not start");
}src-tauri/tauri.conf.json30 lines +
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "Build Lab Notes",
"version": "0.1.0",
"identifier": "com.navansami.buildlab.notes",
"build": {
"frontendDist": "../ui"
},
"app": {
"withGlobalTauri": true,
"windows": [
{
"label": "main",
"title": "Build Lab / Notes",
"width": 800,
"height": 650
}
],
"security": {
"csp": "default-src 'self'; script-src 'self'; style-src 'self'; connect-src ipc: http://ipc.localhost"
}
},
"bundle": {
"active": false,
"icon": [
"icons/icon.png",
"icons/icon.ico"
]
}
}src-tauri/capabilities/default.json1 lines +
{"$schema":"../gen/schemas/desktop-schema.json","identifier":"main-window","description":"Core capabilities for the packaged main window","windows":["main"],"permissions":["core:default"]}ui/index.html1 lines +
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Build Lab Notes</title><link rel="stylesheet" href="style.css"><script defer src="app.js"></script></head><body><main><span>THE BUILD LAB / RUST</span><h1>Make a little room<br>for an idea.</h1><label for="note">Your note · up to 64 KiB</label><textarea id="note" rows="12" disabled></textarea><button id="save" disabled>Save note ↗</button><p id="status" role="status">Loading…</p></main></body></html>ui/style.css1 lines +
body{margin:0;background:#faf9f5;color:#151515;font:18px system-ui}main{max-width:720px;margin:auto;padding:32px}span{font-size:14px;color:#a63812}h1{font-size:clamp(30px,6vw,50px);line-height:1.1}label{display:block;margin-bottom:10px}textarea{box-sizing:border-box;width:100%;font:18px system-ui;padding:16px;border:1px solid #aaa;border-radius:4px}button{font:inherit;background:#ff6034;border:0;padding:14px 24px;margin-top:16px}button:disabled{opacity:.5}p{overflow-wrap:anywhere}ui/app.js5 lines +
const invoke=window.__TAURI__.core.invoke;
const note=document.querySelector('#note'), save=document.querySelector('#save'), status=document.querySelector('#status');
async function load(){try{note.value=await invoke('load_note');note.disabled=false;save.disabled=false;status.textContent='Ready. Changes save when you press Save.'}catch{status.textContent='Could not load the note. Reopen the app to retry.'}}
save.onclick=async()=>{if(new TextEncoder().encode(note.value).length>65536){status.textContent='Note exceeds 64 KiB';return}save.disabled=true;try{await invoke('save_note',{text:note.value});status.textContent='Saved to this app’s data directory.'}catch(error){status.textContent=String(error)}finally{save.disabled=false}};
load();04 Check the behavior
- □note-core tests check empty text, a size boundary, and a filesystem round trip.
- □A saved note survives restarting the native app.
- □The UI reports backend errors without injecting HTML.
- □There is no arbitrary path parameter or unrestricted file plugin.
05 Know what you are building on
Install the operating-system prerequisites before building the native Tauri shell.
This example uses fs::write for a single local note; it is not crash-atomic storage or a multi-writer database.
Bundling, icons, signing, updates, and store distribution need platform-specific setup beyond the unbundled executable.
The app has no file-system plugin permissions; registered application commands still need their own validation.
Choose one boundary to improve. Write down the new behavior, add a test that demonstrates it, then change the implementation. Keep the original working path intact.