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
TheControlCenter 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 aManagedService 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.
| Component | Role | Default Ports |
|---|---|---|
Gateway (palyrad) | Core orchestration, API, and gRPC | 7142 (Admin), 7443 (gRPC), 7444 (QUIC) |
| Browserd | Headless Chrome management | 7143 (Health), 7543 (gRPC) |
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-70IPC Commands and Handlers
Thecommands.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
get_snapshot: Aggregates the current state of processes, logs, and diagnostics into aControlCenterSnapshotapps/desktop/src-tauri/src/commands.rs#53-62.get_onboarding_status: Calculates the user’s progress through the multi-step onboarding flow apps/desktop/src-tauri/src/commands.rs#83-92.set_onboarding_state_root_command: Allows the user to select or confirm the directory where Palyra stores its persistent data apps/desktop/src-tauri/src/commands.rs#135-151.update_desktop_companion_preferences: Updates UI-specific state like the active chat session or current section apps/desktop/src-tauri/src/commands.rs#165-174.
Desktop State and Persistence
State that must persist across application restarts is managed viaDesktopStateFile 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:
- Onboarding Progress: Tracks completed steps (Welcome, Environment, StateRoot, etc.) apps/desktop/src-tauri/src/desktop_state.rs#209-219.
- Companion State: Stores the
active_section,notifications, andoffline_draftsapps/desktop/src-tauri/src/desktop_state.rs#90-101. - Secrets: The
DesktopSecretStoreusespalyra-vaultto securely store thedesktop_admin_tokenanddesktop_browser_auth_tokenapps/desktop/src-tauri/src/lib.rs#11-12.
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 theDesktopOnboardingStep enum apps/desktop/src-tauri/src/desktop_state.rs#209-219:
- Welcome: Initial landing.
- Environment: System dependency checks (Preflight).
- StateRoot: Database and config location selection.
- GatewayInit: Initializing the
palyradconfiguration. - OperatorAuth: Setting up the local admin credentials.
- Provider Connect: Linking OpenAI and Discord connectors.
Diagnostic Snapshots
Thesnapshot.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-107Log Management and Sanitization
To prevent sensitive information (like API keys or tokens) from appearing in the Desktop UI, the backend implements log sanitization.MAX_LOG_LINES_PER_SERVICE: Limits the in-memory buffer to 400 lines per service to prevent memory exhaustion apps/desktop/src-tauri/src/lib.rs#2-2.sanitize_log_line: Invokes redaction logic before sending logs to the frontend apps/desktop/src-tauri/src/snapshot.rs#12-16.- Log Streams: Captures
Stdout,Stderr, and internalSupervisorevents apps/desktop/src-tauri/src/supervisor.rs#64-68.