Skip to main content
The Tauri backend for the Palyra desktop application serves as the orchestration layer for the local agent infrastructure. It manages the lifecycle of two primary sidecar processes: palyrad (the core daemon) and palyra-browserd (the browser automation service). This backend is responsible for process supervision, state persistence, and providing a secure IPC (Inter-Process Communication) bridge between the desktop UI and the underlying system.

Control Center and Process Supervision

The ControlCenter is the central struct managing the runtime state of the desktop application apps/desktop/src-tauri/src/supervisor.rs#201-218. It coordinates the ManagedService instances for both the gateway and the browser daemon.

Service Management Lifecycle

Each sidecar is wrapped in a ManagedService struct which tracks its desired state, PID, restart attempts, and captured logs apps/desktop/src-tauri/src/supervisor.rs#97-107. The supervisor maintains a “tick” loop (defaulting to 500ms) to ensure services remain in their desired state apps/desktop/src-tauri/src/lib.rs#1-1.
ComponentRoleDefault Ports
Gateway (palyrad)Core orchestration, API, and gRPC7142 (Admin), 7443 (gRPC), 7444 (QUIC)
BrowserdHeadless Chrome management7143 (Health), 7543 (gRPC)
Sources: apps/desktop/src-tauri/src/lib.rs#16-20, apps/desktop/src-tauri/src/supervisor.rs#30-60, apps/desktop/src-tauri/src/supervisor.rs#201-218

Code Entity Map: Supervision Flow

This diagram maps the natural language concept of “Service Supervision” to the specific Rust entities that implement it. Sources: apps/desktop/src-tauri/src/supervisor.rs#201-218, apps/desktop/src-tauri/src/supervisor.rs#97-107, apps/desktop/src-tauri/src/lib.rs#1-1, apps/desktop/src-tauri/src/lib.rs#60-70

IPC Commands and Handlers

The commands.rs file defines the tauri::command handlers that the frontend calls via invoke(). These commands interact with the DesktopAppState, which holds an Arc<Mutex<ControlCenter>> apps/desktop/src-tauri/src/commands.rs#49-51.

Key IPC Handlers

Sources: apps/desktop/src-tauri/src/commands.rs#1-182

Desktop State and Persistence

State that must persist across application restarts is managed via DesktopStateFile and the palyra-vault crate.

State Schema and Versioning

The state is versioned (Current: 4) to handle migrations as the desktop app evolves apps/desktop/src-tauri/src/lib.rs#9-9. Key persistent fields include: Sources: apps/desktop/src-tauri/src/desktop_state.rs#1-101, apps/desktop/src-tauri/src/lib.rs#35-39

Onboarding and Diagnostic Flow

The onboarding flow is a state machine that transitions users from a fresh installation to a fully configured environment.

Onboarding Steps

The sequence is defined by the DesktopOnboardingStep enum apps/desktop/src-tauri/src/desktop_state.rs#209-219:
  1. Welcome: Initial landing.
  2. Environment: System dependency checks (Preflight).
  3. StateRoot: Database and config location selection.
  4. GatewayInit: Initializing the palyrad configuration.
  5. OperatorAuth: Setting up the local admin credentials.
  6. Provider Connect: Linking OpenAI and Discord connectors.

Diagnostic Snapshots

The snapshot.rs module performs “probes” to determine the health of the system. It checks if the dashboard is reachable, validates port availability, and captures redacted error logs apps/desktop/src-tauri/src/snapshot.rs#107-115. Sources: apps/desktop/src-tauri/src/onboarding.rs#78-110, apps/desktop/src-tauri/src/snapshot.rs#173-182

Data Flow: Frontend to Sidecar

This diagram illustrates the path of a request from the TypeScript UI through the Tauri command layer to the managed sidecar processes. Sources: apps/desktop/ui/src/App.tsx#33-33, apps/desktop/ui/src/lib/desktopApi.ts#1-20, apps/desktop/src-tauri/src/commands.rs#154-162, apps/desktop/src-tauri/src/supervisor.rs#97-107

Log Management and Sanitization

To prevent sensitive information (like API keys or tokens) from appearing in the Desktop UI, the backend implements log sanitization. Sources: apps/desktop/src-tauri/src/supervisor.rs#80-94, apps/desktop/src-tauri/src/snapshot.rs#33-33