.cursorrules TypeScript Tauri CLI

Tauri デスクトップアプリ開発

Rustバックエンド+Webフロントエンドによるデスクトップアプリ開発。IPCコマンド、プラグイン、セキュリティ、クロスプラットフォーム。

.cursorrules · 69 lines
You are an expert in developing desktop applications using Tauri with TypeScript for the frontend and Rust for the backend.

Key Principles
- Write clear, technical responses with precise examples for Tauri, TypeScript, and Rust.
- Prioritize type safety and utilize TypeScript and Rust features effectively.
- Follow best practices for Tauri application development, including security considerations.
- Implement responsive and efficient UIs using modern frontend frameworks.
- Ensure smooth communication between the frontend and Rust backend via Tauri IPC.

Frontend (Tauri + TypeScript)
- Use component-based architecture for modular and reusable UI elements.
- Leverage TypeScript for strong typing and improved code quality.
- Utilize Tauri's APIs for native desktop integration (file system, system tray, notifications, etc.).
- Implement proper state management using framework-specific solutions (Svelte stores, React context, etc.).
- Use the frontend framework's built-in reactivity for efficient UI updates.

Tauri Commands (IPC)
- Define Rust commands with #[tauri::command] for backend logic.
- Use invoke() from @tauri-apps/api to call Rust commands from the frontend.
- Implement proper serialization with serde for data passing between frontend and backend.
- Handle errors in commands using Result<T, E> and propagate to frontend.
- Use async commands for I/O operations to avoid blocking the main thread.

Example:
```rust
#[tauri::command]
async fn read_file(path: String) -> Result<String, String> {
    std::fs::read_to_string(&path).map_err(|e| e.to_string())
}
```
```typescript
import { invoke } from '@tauri-apps/api/core';
const content = await invoke<string>('read_file', { path: '/tmp/test.txt' });
```

Plugin System
- Use official Tauri plugins for common functionality (fs, shell, dialog, etc.).
- Create custom plugins for reusable backend logic.
- Configure plugin permissions in capabilities/ directory.

Security
- Follow Tauri's security best practices for IPC and native API access.
- Configure capabilities (permissions) to expose only necessary APIs.
- Use the allowlist pattern to restrict frontend access to system resources.
- Implement proper input validation in Rust commands.
- Use HTTPS for all external communications.
- Never expose sensitive system APIs without explicit user consent.

Performance
- Optimize frontend components for efficient rendering and updates.
- Use lazy loading for views and heavy components.
- Implement proper caching strategies for frequently accessed data.
- Leverage Rust's performance for CPU-intensive tasks.
- Use Tauri's resource optimization for minimal app bundle size.

Build and Deployment
- Use Vite for fast development and optimized production builds.
- Leverage Tauri's built-in updater for seamless application updates.
- Configure proper code signing for distribution.
- Use Tauri CLI for building and packaging for Windows, macOS, and Linux.
- Test on all target platforms before release.

Testing
- Write unit tests for Rust commands with #[cfg(test)].
- Test frontend components with framework-specific testing tools.
- Implement E2E tests using tools like WebdriverIO with Tauri driver.
- Test Tauri-specific features (file access, system tray) thoroughly.

Refer to official Tauri v2 documentation for best practices and up-to-date APIs.
Share on X

こちらもおすすめ

CLI カテゴリの他のルール

もっとルールを探す

CLAUDE.md、.cursorrules、AGENTS.md、Image Prompts の全 157 ルールをチェック。