Skip to main content
The Tauri backend (src-tauri) serves as the orchestration layer for the Palyra Desktop application. It is responsible for the lifecycle management of sidecar processes (palyrad and palyra-browserd), managing persisted application state, and providing a secure IPC bridge between the desktop UI and the underlying system services.

Architecture Overview

The backend is built around the ControlCenter struct, which acts as the central supervisor for all desktop operations. It coordinates process execution, health monitoring, and state persistence.

Key Components

Data Flow: Frontend to Sidecar

The following diagram illustrates how a command from the UI (e.g., sending a message) traverses the Tauri backend to reach the managed sidecar. Sources: apps/desktop/ui/src/lib/desktopApi.ts#31, apps/desktop/src-tauri/src/commands.rs#215-220, apps/desktop/src-tauri/src/companion.rs#119-130

Sidecar Supervision (supervisor.rs)

The supervisor.rs module implements the ManagedService logic. It ensures that required binaries are present, starts them with correct environment variables (e.g., PALYRA_ADMIN_TOKEN), and captures their stdout/stderr for diagnostic logging apps/desktop/src-tauri/src/supervisor.rs#97-107.

Process Lifecycle

The supervisor runs a tick every 500ms to check process health and perform backoff-based restarts if a service crashes apps/desktop/src-tauri/src/lib.rs#1.
ServiceBinary NameDefault Ports
GatewaypalyradAdmin: 7142, gRPC: 7443, QUIC: 7444
Browserdpalyra-browserdHealth: 7143, gRPC: 7543
Sources: apps/desktop/src-tauri/src/lib.rs#16-20, apps/desktop/src-tauri/src/supervisor.rs#30-41

Code Entity Relationship: Supervision

Sources: apps/desktop/src-tauri/src/supervisor.rs#201-218, apps/desktop/src-tauri/src/supervisor.rs#97-107, apps/desktop/src-tauri/src/supervisor.rs#30-33

Desktop State and Persistence (desktop_state.rs)

The application state is split between a standard JSON file for preferences and a secure vault for sensitive tokens. Sources: apps/desktop/src-tauri/src/desktop_state.rs#88-101, apps/desktop/src-tauri/src/desktop_state.rs#231-232

IPC Commands (commands.rs)

Commands are the primary interface for the frontend. Key categories include:
  1. System Snapshots: get_snapshot and get_desktop_companion_snapshot provide a unified view of process health, logs, and agent sessions apps/desktop/src-tauri/src/commands.rs#54-62, apps/desktop/src-tauri/src/commands.rs#108-123.
  2. Process Control: Commands to start/stop sidecars and update preferences apps/desktop/src-tauri/src/commands.rs#154-162.
  3. Onboarding: set_onboarding_state_root_command allows users to select where Palyra stores its runtime data apps/desktop/src-tauri/src/commands.rs#135-151.
  4. Companion Interaction: send_companion_chat_message_command and decide_companion_approval_command bridge to the palyrad gRPC API apps/desktop/src-tauri/src/commands.rs#215-231.
Sources: apps/desktop/src-tauri/src/commands.rs#1-38

Diagnostics and Snapshots (snapshot.rs)

The snapshot.rs module aggregates data from multiple sources to provide the UI with a comprehensive status update. Sources: apps/desktop/src-tauri/src/snapshot.rs#87-96, apps/desktop/src-tauri/src/snapshot.rs#118-124

Onboarding Logic (onboarding.rs)

The onboarding flow is a guided process that ensures the environment is ready for operation. Sources: apps/desktop/src-tauri/src/onboarding.rs#78-110, apps/desktop/src-tauri/src/onboarding.rs#199-203