
Tauri là framework mã nguồn mở cho phép xây dựng ứng dụng desktop (Windows, macOS, Linux) bằng công nghệ web (HTML, CSS, JavaScript/TypeScript) nhưng sử dụng Rust làm backend thay vì Node.js như Electron. Kết quả là ứng dụng nhẹ hơn, nhanh hơn và an toàn hơn đáng kể.

Tại sao Tauri khác biệt so với Electron?
| Tiêu chí | Electron | Tauri |
|---|---|---|
| Backend runtime | Node.js (Chromium + V8) | Rust (WebView hệ điều hành) |
| Kích thước bundle tối thiểu | ~50-60 MB | ~3-5 MB |
| RAM usage (app đơn giản) | 80-150 MB | 20-40 MB |
| Khởi động | Chậm (khởi động Node.js + Chromium) | Nhanh (dùng WebView native) |
| Bảo mật | Node.js có quyền truy cập filesystem đầy đủ | Rust sandbox, capability-based security |
| Hệ sinh thái npm | Truy cập đầy đủ | Giới hạn (chỉ frontend), backend dùng crate Rust |
Kiến trúc Tauri: Rust + WebView
Tauri không bundle Chromium. Thay vào đó, nó sử dụng WebView2 trên Windows (Edge), WebKit trên macOS/iOS, và WebKitGTK trên Linux. Backend Rust giao tiếp với frontend qua IPC (Inter-Process Communication) dựa trên message passing an toàn kiểu.
Một ứng dụng Tauri điển hình có cấu trúc:
src-tauri/
├── Cargo.toml # Rust dependencies
├── tauri.conf.json # Cấu hình Tauri
├── src/
│ ├── main.rs # Entry point Rust
│ └── lib.rs # Commands, state management
└── icons/ # App icons
src/ # Frontend (React, Vue, Svelte, Vanilla JS...)
├── index.html
└── ...
Tính năng nổi bật của Tauri v2 (2024)
- Mobile support: Build iOS và Android từ cùng codebase (experimental).
- Sidecar: Chạy binary riêng biệt (Python, Go, Node.js) bên cạnh app Tauri.
- Plugin system: Hệ thống plugin chính thức cho filesystem, dialog, notification, store, sql, websocket…
- Strong typing: TypeScript types tự động generate từ Rust commands.
- Updater built-in: Tự động cập nhật ứng dụng (GitHub releases, custom server).
Ví dụ: Tạo lệnh Rust gọi từ frontend
Rust (src-tauri/src/lib.rs):
#[tauri::command]
fn greet(name: &str) -> String {
format!("Xin chào, {}! Từ Rust backend.", name)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
TypeScript (frontend):
import { invoke } from '@tauri-apps/api/core';
async function sayHello() {
const result = await invoke('greet', { name: 'Hùng' });
console.log(result); // "Xin chào, Hùng! Từ Rust backend."
}

Khi nào nên chọn Tauri?
- Ứng dụng cần nhẹ, nhanh: Tool hệ thống, launcher, monitor, editor nhẹ.
- Yêu cầu bảo mật cao: Password manager, crypto wallet, app xử lý dữ liệu nhạy cảm.
- Team biết Rust hoặc sẵn sàng học: Backend logic viết bằng Rust.
- Cross-platform desktop + mobile: Một codebase cho mọi nền tảng.
Khi nào nên giữ Electron?
- Cần truy cập đầy đủ npm ecosystem cho backend logic.
- Team chỉ biết JavaScript/TypeScript, không muốn học Rust.
- App phức tạp, đã đầu tư nhiều vào Electron codebase.
- Cần các API Node.js cụ thể (child_process, native modules phức tạp).
Các ứng dụng nổi tiếng dùng Tauri
- Ripcord: Discord/Slack client nhẹ.
- Tauri Dashboard: Chính thức của Tauri team.
- Arctica: File manager hiện đại.
- Nhiều dự án open-source trên GitHub trending.
Lộ trình học Tauri cho developer Việt Nam
- Học cơ bản Rust (ownership, borrowing, async/await) – 2-3 tuần.
- Làm theo Tauri Official Guide – tạo app Hello World.
- Thử các plugin chính thức:
tauri-plugin-fs,tauri-plugin-dialog,tauri-plugin-store. - Xây dựng project thật: note-taking app, system monitor, hoặc todo app có sync.
- Tìm hiểu Sidecar để tích hợp Python/ML model vào app desktop.

Tham khảo thêm:
