Gateway

One-line summary

The Gateway is the single Node.js process that runs everything — WebSocket/HTTP server, channel plugins, agent runtime, cron, memory, and the Control UI — serving as OpenClaw's central orchestration point.

Responsibilities

  • Bootstrap and manage the lifecycle of all subsystems (channels, agents, cron, memory, canvas)
  • Serve WebSocket connections for real-time communication with Control UI and CLI
  • Handle HTTP requests: webhooks, OpenAI-compatible endpoints, canvas, Slack integration
  • Manage authentication, rate limiting, and trusted proxy resolution
  • Coordinate config migration, plugin loading, and health monitoring

Architecture diagram

Key source files

FileLinesRole
src/gateway/server.impl.ts784Main bootstrap: startGatewayServer() — config migration, subsystem init, lifecycle management
src/gateway/server-http.ts649HTTP layer: createGatewayHttpServer(), webhook routing, canvas, OpenAI endpoints, auth
src/gateway/server.ts3Thin re-export wrapper
src/gateway/session-utils.ts876Session listing/loading for API layer

Key interfaces

GatewayBindMode = "loopback" | "lan" | "tailnet" | "auto"

GatewayServerOptions = {
  bind?: GatewayBindMode;
  host?: string;
  controlUiEnabled?: boolean;
  openAiChatCompletionsEnabled?: boolean;
  openResponsesEnabled?: boolean;
  auth?: GatewayAuthConfig;
  tailscale?: GatewayTailscaleConfig;
}

How it connects to other modules

  • Depends on: Every other module (this is the top-level orchestrator)
  • Depended by: CLI (openclaw gateway start/stop/restart), native apps (WebSocket client)

My blind spots

  • Tailscale integration details — tailnet bind mode
  • OpenAI-compatible endpoint implementation
  • Health monitoring and discovery service
  • How gateway restart preserves active sessions

Change frequency

  • server.impl.ts: High — new subsystem integrations and lifecycle changes
  • server-http.ts: Medium — new HTTP endpoints and auth features