LibreChat Desktop Development Guide
Expert guidance for building and maintaining LibreChat Desktop - a native cross-platform desktop application that wraps the LibreChat web UI using Tauri v2.
Project Overview
LibreChat Desktop is a cross-platform native desktop wrapper for LibreChat web UI built with Tauri v2. It provides native desktop features like global hotkeys, system tray integration, drag & drop support, offline caching, and quick capture overlay for seamless AI-powered desktop workflow integration.
**Architecture:**
**Backend**: Rust 1.75+ with Tauri v2.x framework**Frontend**: TypeScript/React with Vite build system**Target Platforms**: macOS (primary), Windows 10+, Linux (Ubuntu 20.04+)**Performance Goals**: <3s startup, <100ms UI interactions, <50MB package sizeInstructions for AI Agent
When working with this codebase, follow these guidelines:
1. Project Structure Understanding
**Directory Layout:**
```
src/ # Frontend source (TypeScript/React)
src-tauri/ # Rust backend source
├── src/ # Rust source files
├── Cargo.toml # Rust dependencies
└── tauri.conf.json # Tauri configuration
tests/ # Test files
├── contract/ # API contract tests
├── integration/ # Integration tests
└── unit/ # Unit tests
package.json # Frontend dependencies
```
Before making changes:
Identify whether the feature belongs in Rust backend (`src-tauri/`) or React frontend (`src/`)Check existing implementations in both layersReview relevant configuration files2. Key Dependencies to Use
**Rust Backend:**
`tauri` v2.x - Application framework`tokio` - Async runtime`serde` - Serialization`reqwest` - HTTP client`sqlx` - Database ORM with SQLite`tauri-plugin-store` - Local storage`tauri-plugin-global-shortcut` - Global hotkeys`tauri-plugin-system-tray` - System tray integration**Frontend:**
`react` + `react-dom` - UI framework`@tanstack/react-query` - Data fetching`zustand` - State management`axios` - HTTP client`@radix-ui/*` - UI components`tailwindcss` - Styling`framer-motion` - Animations3. Development Workflow
Follow this sequence when implementing features:
**Step 1: Write Tests First (TDD Approach)**
Identify test type: contract, unit, or integrationWrite failing tests that define expected behaviorUse `cargo test` for Rust, `npm run test` for frontend**Step 2: Implement Feature**
Backend changes: Edit files in `src-tauri/src/`Frontend changes: Edit files in `src/`Follow existing code patterns and naming conventions**Step 3: Validate and Refine**
Run tests: `cargo test && npm run test`Check formatting: `cargo fmt && npm run format`Run linting: `cargo clippy && npm run lint`Test in development: `npm run tauri dev`**Step 4: Build and Verify**
Build production version: `npm run tauri build`Verify bundle size (<50MB requirement)Test on target platforms when possible4. Core Feature Implementation Priorities
When adding features, prioritize in this order:
**Phase 1: Foundation**
1. LibreChat API integration (auth, conversations, messages)
2. Basic UI with tabbed interface
3. Encrypted local storage with SQLite
**Phase 2: Native Features**
4. System tray integration with quick access menu
5. Global hotkeys for app summoning
6. Drag & drop for files, screenshots, and text
**Phase 3: Advanced Features**
7. Quick capture floating mini-window
8. Split view for conversation comparison
9. Multi-window support (docking, floating modes)
5. API Integration Requirements
Integrate these LibreChat REST API endpoints:
`/api/auth` - Authentication (JWT, OAuth, LDAP)`/api/config` - Configuration retrieval`/api/convos` - Conversation management`/api/messages` - Message sending/receiving`/api/files` - File upload handling`/api/mcp` - MCP server integration**Important Constraints:**
Do NOT modify LibreChat server codeMaintain compatibility with standard LibreChat APIHandle offline/online state transitions gracefully6. Security Best Practices
Always implement:
**Encrypted Storage**: Use OS keychain for credentials via `tauri-plugin-store`**HTTPS Enforcement**: Warn users on HTTP connections**Input Validation**: Sanitize all user inputs and API responses**Minimal Privileges**: Request only necessary system permissions**Secure Caching**: Encrypt conversation data at rest with SQLite encryption7. Performance Requirements
Ensure all implementations meet:
**Startup Time**: <3 seconds from launch to usable UI**UI Responsiveness**: <100ms for button clicks and interactions**API Response**: <200ms for LibreChat API calls**Package Size**: <50MB total bundle size**Memory Usage**: <500MB during normal operationUse profiling tools to validate performance before finalizing features.
8. Cross-Platform Considerations
**Primary Platform**: macOS (optimize native features first)**Secondary Platforms**: Windows 10+, Linux (Ubuntu 20.04+)Test platform-specific features (system tray, global shortcuts) on each OSUse conditional compilation (`#[cfg(target_os = "...")]`) for platform-specific codeVerify UI rendering across different window managers9. Testing Strategy
Implement tests in this order:
**Contract Tests** (`tests/contract/`):
Validate LibreChat API endpoint contractsTest authentication flowsVerify conversation and message CRUD operations**Unit Tests** (`tests/unit/`):
Rust: Test individual functions and modulesReact: Test components in isolation with React Testing Library**Integration Tests** (`tests/integration/`):
End-to-end user scenariosMulti-window interactionsOffline-to-online transitionsFile drag & drop workflows10. Configuration Management
Key configuration files to update when making changes:
`src-tauri/tauri.conf.json` - App metadata, permissions, bundle settings`vite.config.ts` - Frontend build configuration`tailwind.config.js` - Styling system configuration`Cargo.toml` - Rust dependencies and metadata`package.json` - Frontend dependencies and scripts11. Common Development Commands
```bash
Start development with hot reload
npm run tauri dev
Build production bundle
npm run tauri build
Run all tests
cargo test && npm run test
Code quality checks
cargo fmt && cargo clippy
npm run format && npm run lint
Install dependencies
npm install
cd src-tauri && cargo build
```
12. Troubleshooting Guide
**Build Failures:**
Verify Rust 1.75+ installed: `rustc --version`Verify Node.js 18+ installed: `node --version`Check platform-specific prerequisites in Tauri docs**Development Server Issues:**
Use `npm run tauri dev` for hot reloadCheck `src-tauri/target/` for detailed error logsEnsure ports 5173 (Vite) and 1420 (Tauri) are available**Performance Problems:**
Use Tauri bundle analyzer to identify bloatProfile memory with Rust profiling toolsOptimize React rendering with React DevTools Profiler13. Code Quality Standards
Before submitting any changes:
Run `cargo fmt` and `npm run format` (formatting)Run `cargo clippy` and `npm run lint` (linting)Ensure all tests pass (`cargo test && npm run test`)Verify bundle size remains <50MBTest on macOS at minimum (primary platform)Examples
Example 1: Adding a New Global Hotkey
```rust
// src-tauri/src/shortcuts.rs
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
pub fn register_quick_capture(app: &tauri::App) -> Result<()> {
let shortcut = Shortcut::new(Some(Modifiers::SUPER), Code::KeySpace)?;
app.global_shortcut().on_shortcut(shortcut, |app, _event| {
// Show quick capture window
if let Some(window) = app.get_webview_window("quick-capture") {
window.show().unwrap();
window.set_focus().unwrap();
}
})?;
Ok(())
}
```
Example 2: Implementing Encrypted Storage
```rust
// src-tauri/src/storage.rs
use sqlx::SqlitePool;
use tauri_plugin_store::StoreExt;
pub async fn save_conversation(
pool: &SqlitePool,
conv_id: &str,
encrypted_data: Vec<u8>
) -> Result<()> {
sqlx::query!(
"INSERT INTO conversations (id, data) VALUES (?, ?)",
conv_id,
encrypted_data
)
.execute(pool)
.await?;
Ok(())
}
```
Example 3: React Component with Tauri Invoke
```typescript
// src/components/QuickCapture.tsx
import { invoke } from '@tauri-apps/api/core';
import { useState } from 'react';
export function QuickCapture() {
const [query, setQuery] = useState('');
const handleSubmit = async () => {
const response = await invoke('send_quick_query', {
message: query
});
console.log('AI Response:', response);
};
return (
<div className="quick-capture">
<input
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Ask AI anything..."
/>
<button onClick={handleSubmit}>Send</button>
</div>
);
}
```
Constraints
**No Server Modifications**: Do not modify LibreChat backend code**Cross-Platform First**: Test features on macOS, Windows, and Linux**Performance Budgets**: Adhere to <3s startup, <100ms UI, <50MB bundle**Security by Default**: Always encrypt cached data and credentials**TDD Required**: Write tests before implementation**Minimal Dependencies**: Only add dependencies that provide significant valueNotes
Tauri v2 uses a different plugin system than v1 - consult latest docsmacOS requires code signing for distribution (handle in CI/CD)Global shortcuts may require accessibility permissions on macOSSQLite encryption requires `sqlcipher` feature flag in `sqlx`Use `quickstart.md` for detailed environment setup instructions