Skip to main content
The Transport Layer in palyrad manages the entry points for all external and internal communications. It provides a multi-stack interface consisting of an Axum-based HTTP router for the web dashboard and administrative tools, and a Tonic-based gRPC server for high-performance agent communication, node synchronization, and browser automation control.

System Architecture

The transport layer is initialized during the daemon bootstrap process, where it binds to specific sockets defined in the LoadedConfig. It bridges the “Code Entity Space” of internal services (like GatewayRuntimeState) to the “Natural Language Space” of network protocols.

Transport Layer Overview

This diagram illustrates how external requests flow through the transport components into the core logic. Sources: crates/palyra-daemon/src/transport/http/router.rs#17-133, crates/palyra-daemon/src/app/runtime.rs#42-84, crates/palyra-daemon/src/lib.rs#162-164

Axum HTTP Router

The HTTP router is constructed via build_router and is divided into several logical namespaces. Each namespace has specific security requirements and middleware chains.

Route Namespaces

NamespaceBase PathPurpose
Admin/admin/v1/*System-level diagnostics, journal inspection, and channel management.
Console/console/v1/*Backend for the React-based Web Dashboard (Agents, Chat, Config).
Canvas/canvas/v1/*Rendering surface for agent-to-UI (A2UI) artifacts.
Compat/compat/v1/*OpenAI-compatible API surface for external LLM clients.
Web UI/*Static asset serving for the built Web Dashboard.
Sources: crates/palyra-daemon/src/transport/http/router.rs#18-134, crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#16-34

HTTP Middleware and Security

The HTTP stack implements several layers of protection:
  1. Security Headers: apply_admin_console_security_headers enforces no-store, nosniff, and frame-ancestors 'none' to prevent clickjacking and caching of sensitive data crates/palyra-daemon/src/transport/http/middleware.rs#37-52.
  2. Rate Limiting: admin_rate_limit_middleware uses an IP-based bucket system (AdminRateLimitEntry) to prevent brute-force attacks on administrative endpoints crates/palyra-daemon/src/transport/http/middleware.rs#172-204.
  3. CSRF & Session: Console routes use console_session_cookie_refresh_middleware to manage SET_COOKIE headers and validate ConsoleSession objects stored in AppState crates/palyra-daemon/src/transport/http/middleware.rs#87-107.

gRPC Services

The daemon exposes Protobuf-defined services via Tonic. These are used for low-latency, bi-directional streaming (e.g., RunStream) and secure node-to-node communication.

Key Services

Authentication Flow

Every gRPC request is intercepted to extract a RequestContext. The authorize_headers function validates the palyra-principal, palyra-device-id, and optional palyra-admin-token against the GatewayAuthConfig crates/palyra-daemon/src/lib.rs#162-164.

ControlPlaneClient

The ControlPlaneClient (defined in palyra-control-plane) is the primary consumer of the HTTP API, used by the CLI and Desktop applications to interact with the daemon.

Client Implementation Details

The client manages the lifecycle of the session, including the CSRF token and cookie store. Sources: crates/palyra-control-plane/src/client.rs#33-61

Data Flow: Web Console Authentication

The following diagram maps the authentication flow from the React UI components to the Rust backend handlers.

Key Entities in Auth Flow

Sources: crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#19-111, apps/web/src/console/components/layout/ConsoleAuthScreen.tsx#23-132