palyrad) exposes two primary HTTP API families via an Axum-based router: the Admin API (/admin/v1/*) and the Console API (/console/v1/*). These APIs provide the control plane for both the CLI and the React-based Web Dashboard.
Axum Router and Middleware Pipeline
The HTTP server is constructed using theaxum framework crates/palyra-daemon/src/transport/http/router.rs#1-15. The router integrates multiple layers of middleware to ensure security, rate limiting, and diagnostic visibility.
Router Composition
The router is split into several sub-routers that are merged into the main application state crates/palyra-daemon/src/transport/http/router.rs#17-157:- Admin Routes: High-privilege endpoints for system-level management, such as journal inspection, policy explanation, and channel management.
- Console Routes: Operator-facing endpoints used by the Web Dashboard for chat, session management, and configuration.
- Health and Compatibility: Basic health checks (
/healthz) and legacy compatibility layers. - Web UI: Static asset serving for the React dashboard crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#16-34.
Security Middleware
Security is enforced through several layers:- CSRF Protection: Console POST/PUT/DELETE requests require a
x-palyra-csrf-tokenheader that must match the token stored in the session crates/palyra-control-plane/src/client.rs#63-65. - Security Headers: The
admin_console_security_headers_middlewareapplies strict headers (HSTS, CSP, X-Frame-Options) to all admin and console responses crates/palyra-daemon/src/transport/http/router.rs#155-157. - Rate Limiting: The
admin_rate_limit_middlewareprevents brute-force attempts against sensitive endpoints crates/palyra-daemon/src/transport/http/router.rs#151-154.
Dependency Injection: AppState
The entire router shares a globalAppState crates/palyra-daemon/src/app/state.rs. This state is injected into every handler using Axum’s State extractor crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#6-7.
Entity Mapping: HTTP Pipeline
| System Name | Code Entity | Role |
|---|---|---|
| Main Router | build_router | Entry point for HTTP server definition crates/palyra-daemon/src/transport/http/router.rs#17 |
| Shared State | AppState | Container for JournalStore, Vault, and GatewayRuntime crates/palyra-daemon/src/app/state.rs |
| Admin Logic | admin::core | Implementation of /admin/v1 handlers crates/palyra-daemon/src/transport/http/router.rs#19 |
| Console Logic | console::* | Implementation of /console/v1 handlers crates/palyra-daemon/src/transport/http/handlers/console/mod.rs |
Admin API (/admin/v1/*)
The Admin API is primarily consumed by the palyra CLI and internal automation. It requires a valid Authorization: Bearer <token> header and specific context headers like x-palyra-principal and x-palyra-device-id crates/palyra-daemon/tests/admin_surface.rs#56-62.
Key Admin Endpoints
/admin/v1/status: Returns the health and versioning information of the daemon crates/palyra-daemon/src/transport/http/router.rs#19./admin/v1/journal/recent: Provides a snapshot of recent events from theJournalStorecrates/palyra-daemon/src/transport/http/router.rs#20./admin/v1/policy/explain: Evaluates the Cedar policy engine for a specific principal/action/resource triplet and returns the decision logic crates/palyra-daemon/src/transport/http/router.rs#21./admin/v1/channels/*: A large family of endpoints for managing Discord, Slack, and other connectors, including health refreshes and dead-letter queue management crates/palyra-daemon/src/transport/http/router.rs#25-97.
Console API (/console/v1/*)
The Console API is the backend for the Web Dashboard. It uses session-based authentication via cookies and requires CSRF tokens for state-changing operations.
Session Management and Login
Authentication is initiated viaconsole_login_handler crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#19-23.
- The client sends a
ConsoleLoginRequestcontaining the principal and device ID. - The server validates the credentials against the
GatewayAuthConfigcrates/palyra-daemon/src/transport/http/handlers/console/auth.rs#88-89. - If successful, the server issues a session token and sets a
SET_COOKIEheader crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#101-106. - The response includes a
csrf_tokenwhich the client must include in subsequent non-GET requests crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#109-110.
Diagnostics Pipeline
The/console/v1/diagnostics endpoint crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#6 provides a comprehensive snapshot of the system state for the “Operations” section of the dashboard. It aggregates data from:
- Model Providers: Current configuration and health of LLM providers crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#22-27.
- Memory Status: Usage, retention settings, and maintenance schedules crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#113-129.
- Skills & Plugins: Installed skill artifacts and their trust posture crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#38-39.
- Usage Governance: Token budgets and rate limit counters crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#88-94.
Browser Handoff
To facilitate seamless transitions between the CLI and the Web UI, theconsole_browser_handoff_handler generates short-lived tokens that allow a browser to “bootstrap” into a session without re-authenticating crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#127-160.
Data Flow: Console Authentication & Diagnostics
Sources: crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#1-160, crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#1-130, crates/palyra-control-plane/src/client.rs#67-83
Web UI Serving
The daemon can serve the built React application directly. It resolves theapps/web/dist directory by checking the PALYRA_WEB_DIST_DIR environment variable or searching relative to the current executable crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#125-148.
The web_ui_entry_handler serves index.html for any path that doesn’t match a static file, allowing React Router to handle client-side navigation crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#161-193.
Entity Mapping: Console UI Structure
| Dashboard Section | API Endpoint | UI Component |
|---|---|---|
| Chat | /console/v1/chat/* | ChatConsolePanel apps/web/src/console/ConsoleSectionContent.tsx#32 |
| Usage | /console/v1/diagnostics | UsageSection apps/web/src/console/ConsoleSectionContent.tsx#45 |
| Approvals | /console/v1/approvals/* | ApprovalsSection apps/web/src/console/ConsoleSectionContent.tsx#79 |
| Memory | /console/v1/memory/* | MemorySection apps/web/src/console/ConsoleSectionContent.tsx#89 |