# valuecell-ai/clawx architecture

> Architecture diagram of the GitHub repository valuecell-ai/clawx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/valuecell-ai/clawx
- Repository: https://github.com/valuecell-ai/clawx

## Overview

1. **What this repository is**
   ClawX is a cross-platform Electron desktop app that wraps the OpenClaw AI runtime in a graphical UI. The architecture is split into three main runtime surfaces: Electron Main, the React renderer, and a separate OpenClaw Gateway process.

2. **Renderer/UI layer**
   The `src/` tree is the user-facing app: React 19 + TypeScript, styled with Tailwind/shadcn. Major screens are Setup, Chat, Channels, Cron, Models, Skills, and Settings. UI state is organized with Zustand stores under `src/stores/`, while `src/i18n/` provides localized strings for English, Japanese, Russian, and Chinese.

3. **Frontend data boundary**
   The renderer does not talk directly to the gateway. It uses `src/lib/host-api.ts`, `api-client.ts`, and `gateway-client.ts` as the single abstraction for all backend interactions. This is an important diagram boundary: the UI calls a stable client API, not transport-specific code.

4. **Electron Main as control plane**
   `electron/main/` owns app lifecycle concerns: window creation, tray behavior, quit/focus handling, launch-at-startup, single-instance protection, and update orchestration. It also hosts the preload bridge and IPC handlers, which is where the renderer’s safe access to system capabilities is mediated.

5. **Main-side API router**
   `electron/api/` is the main-process API surface. It exposes route modules for agents, app, channels, cron, diagnostics, files, gateway, logs, providers, sessions, settings, skills, and usage. This layer is the bridge between renderer requests and local services/gateway operations.

6. **Gateway process as runtime engine**
   `electron/gateway/` manages the OpenClaw Gateway as a separate process with its own lifecycle, restart/reload/recovery policies, health monitoring, request store, and WebSocket client. It is the execution engine for agents, channels, and skill/plugin activity, isolated from the UI process for responsiveness and fault containment.

7. **Transport and recovery model**
   ClawX uses a main-owned transport strategy: WebSocket first, HTTP next, and IPC fallback when needed. That design is reinforced by connection monitoring, startup orchestration, recovery controllers, and restart governors in `electron/gateway/`. This is the critical path for how UI actions reach the AI runtime and how runtime events come back.

8. **Providers and secrets**
   Provider configuration is handled by `electron/services/providers/` and shared provider types in `electron/shared/providers/`. This subsystem validates providers, migrates configs, syncs runtime models, and persists provider accounts. Sensitive credentials are stored through `electron/services/secrets/` using the OS keychain, not plain files.

9. **Channels, auth, and local integration**
   Channel and provider helpers in `electron/utils/` handle config, aliases, status, proxying, OAuth flows, and device/browser login for specific providers. This includes OpenAI/Codex-style auth helpers, proxy propagation, and platform-specific shell/network utilities. These utilities sit below the API layer and above the gateway/runtime.

10. **Skills and extensions**
   ClawX has an extension system in both `electron/extensions/` and `src/extensions/`. Built-in extensions include diagnostics and marketplace integration, and skills are bundled from `resources/skills/` via manifests and packaging scripts. The Skills page is backed by discovery across managed, workspace, and extra skill directories.

11. **Product workflows reflected in the architecture**
   The main app flows map directly to subsystems: Setup initializes language/provider/skill state; Chat routes conversations and supports `@agent` targeting; Channels manages multi-account/channel bindings; Cron schedules automation and delivery targets; Models/Settings expose provider and runtime control. These are not separate apps—they are different views over the same gateway-backed domain model.

12. **Packaging and runtime assets**
   `electron-builder.yml`, `vite.config.ts`, and the `scripts/` directory define build/package behavior. The repo bundles CLI assets, preinstalled skills, icons, and platform-specific wrappers under `resources/`. On Windows, the packaged CLI is run through shipped node/entrypoint assets to keep terminal behavior stable.

13. **Quality and operational boundaries**
   `tests/unit/` covers stores, gateway policies, providers, auth, and UI logic; `tests/e2e/` validates Electron-level flows like setup, navigation, provider lifecycle, and gateway behavior. The `scripts/comms/` suite is specifically for regression checking message/transport scenarios, which reflects how central the gateway communication boundary is to the system.

Main entry points: [`src/App.tsx`](https://github.com/valuecell-ai/clawx/blob/main/src/App.tsx) (App shell), [`src/lib/host-api.ts`](https://github.com/valuecell-ai/clawx/blob/main/src/lib/host-api.ts) (Host API), [`electron/gateway/manager.ts`](https://github.com/valuecell-ai/clawx/blob/main/electron/gateway/manager.ts) (Gateway manager), [`electron/main/index.ts`](https://github.com/valuecell-ai/clawx/blob/main/electron/main/index.ts) (Main process)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_renderer["Renderer UI"]
  node_src_app["App shell<br/>react app<br/>[App.tsx]"]
  node_src_pages_chat["Chat<br/>screen<br/>[index.tsx]"]
  node_src_pages_channels["Channels<br/>screen<br/>[index.tsx]"]
  node_src_pages_setup["Setup<br/>screen<br/>[index.tsx]"]
  node_src_pages_settings["Settings<br/>screen<br/>[index.tsx]"]
  node_src_pages_skills["Skills<br/>screen<br/>[index.tsx]"]
  node_src_pages_models["Models<br/>screen<br/>[index.tsx]"]
  node_src_pages_cron["Cron<br/>screen<br/>[index.tsx]"]
  node_src_stores["Stores<br/>state"]
  node_src_client["Host API<br/>client boundary<br/>[host-api.ts]"]
end

subgraph group_main["Electron Main"]
  node_electron_main["Main process<br/>control plane<br/>[index.ts]"]
  node_electron_ipc["IPC bridge<br/>[index.ts]"]
  node_electron_api["API routes<br/>router<br/>[server.ts]"]
end

subgraph group_gateway["OpenClaw Gateway"]
  node_electron_gateway_mgr["Gateway manager<br/>runtime supervisor<br/>[manager.ts]"]
  node_electron_gateway_transport["Transport<br/>ws/http/ipc<br/>[client.ts]"]
  node_electron_gateway_recovery["Recovery<br/>restart policy"]
end

subgraph group_domain["Provider & Secrets"]
  node_electron_provider_service["Providers"]
  node_electron_secrets[("Secrets<br/>secure storage<br/>[secret-store.ts]")]
end

subgraph group_ext["Extensions"]
  node_electron_extensions["Extensions<br/>registry<br/>[index.ts]"]
  node_src_extensions["UI extensions<br/>registry<br/>[index.ts]"]
end

subgraph group_assets["Packaging & Assets"]
  node_resources_skills["Skill packs<br/>asset bundle"]
  node_scripts_bundle["Bundle scripts<br/>build pipeline"]
end

subgraph group_quality["Quality"]
  node_tests_unit["Unit tests<br/>test suite"]
  node_tests_e2e["E2E tests<br/>test suite"]
end

node_src_app -->|"routes to"| node_src_pages_setup
node_src_app -->|"routes to"| node_src_pages_chat
node_src_app -->|"routes to"| node_src_pages_channels
node_src_app -->|"routes to"| node_src_pages_cron
node_src_app -->|"routes to"| node_src_pages_models
node_src_app -->|"routes to"| node_src_pages_skills
node_src_app -->|"routes to"| node_src_pages_settings
node_src_app -->|"uses state"| node_src_stores
node_src_pages_chat -->|"calls"| node_src_client
node_src_pages_channels -->|"calls"| node_src_client
node_src_pages_settings -->|"calls"| node_src_client
node_src_pages_models -->|"calls"| node_src_client
node_src_pages_skills -->|"calls"| node_src_client
node_src_pages_cron -->|"calls"| node_src_client
node_src_client -->|"bridges through"| node_electron_ipc
node_electron_ipc -->|"dispatches to"| node_electron_api
node_electron_api -->|"controls"| node_electron_gateway_mgr
node_electron_api -->|"uses"| node_electron_provider_service
node_electron_provider_service -->|"stores creds"| node_electron_secrets
node_electron_gateway_mgr -->|"communicates via"| node_electron_gateway_transport
node_electron_gateway_mgr -->|"restarts/reloads"| node_electron_gateway_recovery
node_electron_main -->|"hosts"| node_electron_ipc
node_electron_main -->|"serves"| node_electron_api
node_electron_main -->|"supervises"| node_electron_gateway_mgr
node_electron_extensions -->|"loads packs"| node_resources_skills
node_src_extensions -->|"mirrors"| node_electron_extensions
node_scripts_bundle -->|"packages"| node_resources_skills
node_tests_unit -->|"verifies"| node_src_client
node_tests_unit -->|"verifies"| node_electron_gateway_mgr
node_tests_unit -->|"verifies"| node_electron_provider_service
node_tests_e2e -->|"exercises"| node_src_app
node_tests_e2e -->|"exercises"| node_electron_main
node_tests_e2e -->|"exercises"| node_electron_gateway_mgr

click node_src_app "https://github.com/valuecell-ai/clawx/blob/main/src/App.tsx"
click node_src_pages_chat "https://github.com/valuecell-ai/clawx/blob/main/src/pages/Chat/index.tsx"
click node_src_pages_channels "https://github.com/valuecell-ai/clawx/blob/main/src/pages/Channels/index.tsx"
click node_src_pages_setup "https://github.com/valuecell-ai/clawx/blob/main/src/pages/Setup/index.tsx"
click node_src_pages_settings "https://github.com/valuecell-ai/clawx/blob/main/src/pages/Settings/index.tsx"
click node_src_pages_skills "https://github.com/valuecell-ai/clawx/blob/main/src/pages/Skills/index.tsx"
click node_src_pages_models "https://github.com/valuecell-ai/clawx/blob/main/src/pages/Models/index.tsx"
click node_src_pages_cron "https://github.com/valuecell-ai/clawx/blob/main/src/pages/Cron/index.tsx"
click node_src_stores "https://github.com/valuecell-ai/clawx/tree/main/src/stores"
click node_src_client "https://github.com/valuecell-ai/clawx/blob/main/src/lib/host-api.ts"
click node_electron_main "https://github.com/valuecell-ai/clawx/blob/main/electron/main/index.ts"
click node_electron_ipc "https://github.com/valuecell-ai/clawx/blob/main/electron/preload/index.ts"
click node_electron_api "https://github.com/valuecell-ai/clawx/blob/main/electron/api/server.ts"
click node_electron_gateway_mgr "https://github.com/valuecell-ai/clawx/blob/main/electron/gateway/manager.ts"
click node_electron_gateway_transport "https://github.com/valuecell-ai/clawx/blob/main/electron/gateway/client.ts"
click node_electron_gateway_recovery "https://github.com/valuecell-ai/clawx/blob/main/electron/gateway/startup-orchestrator.ts"
click node_electron_provider_service "https://github.com/valuecell-ai/clawx/blob/main/electron/services/providers/provider-service.ts"
click node_electron_secrets "https://github.com/valuecell-ai/clawx/blob/main/electron/services/secrets/secret-store.ts"
click node_electron_extensions "https://github.com/valuecell-ai/clawx/blob/main/electron/extensions/index.ts"
click node_src_extensions "https://github.com/valuecell-ai/clawx/blob/main/src/extensions/index.ts"
click node_resources_skills "https://github.com/valuecell-ai/clawx/blob/main/resources/skills/preinstalled-manifest.json"
click node_scripts_bundle "https://github.com/valuecell-ai/clawx/blob/main/scripts/bundle-openclaw.mjs"
click node_tests_unit "https://github.com/valuecell-ai/clawx/tree/main/tests/unit"
click node_tests_e2e "https://github.com/valuecell-ai/clawx/tree/main/tests/e2e"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_src_app,node_src_pages_chat,node_src_pages_channels,node_src_pages_setup,node_src_pages_settings,node_src_pages_skills,node_src_pages_models,node_src_pages_cron,node_src_stores,node_src_client,node_tests_unit,node_tests_e2e toneBlue
class node_electron_main,node_electron_ipc,node_electron_api toneAmber
class node_electron_gateway_mgr,node_electron_gateway_transport,node_electron_gateway_recovery toneMint
class node_electron_provider_service,node_electron_secrets toneRose
class node_electron_extensions,node_src_extensions toneIndigo
class node_resources_skills,node_scripts_bundle toneTeal
```

## Components

### Renderer UI

React frontend, screens, stores, and client boundary.

- [App shell](https://github.com/valuecell-ai/clawx/blob/main/src/App.tsx): react app · Top-level renderer app entry and composition. · `src/App.tsx`
- [Chat](https://github.com/valuecell-ai/clawx/blob/main/src/pages/Chat/index.tsx): screen · Conversation UI, execution views, and task visualization. · `src/pages/Chat/index.tsx`
- [Channels](https://github.com/valuecell-ai/clawx/blob/main/src/pages/Channels/index.tsx): screen · Multi-account channel bindings and status management. · `src/pages/Channels/index.tsx`
- [Setup](https://github.com/valuecell-ai/clawx/blob/main/src/pages/Setup/index.tsx): screen · Initial onboarding and runtime initialization flows. · `src/pages/Setup/index.tsx`
- [Settings](https://github.com/valuecell-ai/clawx/blob/main/src/pages/Settings/index.tsx): screen · Runtime, proxy, and provider configuration surfaces. · `src/pages/Settings/index.tsx`
- [Skills](https://github.com/valuecell-ai/clawx/blob/main/src/pages/Skills/index.tsx): screen · Discovery and management of installed and workspace skills. · `src/pages/Skills/index.tsx`
- [Models](https://github.com/valuecell-ai/clawx/blob/main/src/pages/Models/index.tsx): screen · Provider model views and usage history. · `src/pages/Models/index.tsx`
- [Cron](https://github.com/valuecell-ai/clawx/blob/main/src/pages/Cron/index.tsx): screen · Scheduled automation and delivery workflows. · `src/pages/Cron/index.tsx`
- [Stores](https://github.com/valuecell-ai/clawx/tree/main/src/stores): state · Zustand state for chat, gateway, providers, skills, and settings. · `src/stores`
- [Host API](https://github.com/valuecell-ai/clawx/blob/main/src/lib/host-api.ts): client boundary · Stable renderer-side API over host, IPC, and gateway transport. · `src/lib/host-api.ts`

### Electron Main

Lifecycle, IPC, windowing, and local control plane.

- [Main process](https://github.com/valuecell-ai/clawx/blob/main/electron/main/index.ts): control plane · App lifecycle, tray, focus, quit, startup, and updates. · `electron/main/index.ts`
- [IPC bridge](https://github.com/valuecell-ai/clawx/blob/main/electron/preload/index.ts): bridge · Preload and IPC handlers mediating safe renderer access. · `electron/preload/index.ts`
- [API routes](https://github.com/valuecell-ai/clawx/blob/main/electron/api/server.ts): router · Main-process route modules for app, agents, channels, cron, files, providers, sessions, settings, skills, and usage. · `electron/api/server.ts`

### OpenClaw Gateway

Separate process runtime, transport, and recovery.

- [Gateway manager](https://github.com/valuecell-ai/clawx/blob/main/electron/gateway/manager.ts): runtime supervisor · Owns gateway process lifecycle, health, and recovery policies. · `electron/gateway/manager.ts`
- [Transport](https://github.com/valuecell-ai/clawx/blob/main/electron/gateway/client.ts): ws/http/ipc · WebSocket-first transport with HTTP and IPC fallback. · `electron/gateway/client.ts`
- [Recovery](https://github.com/valuecell-ai/clawx/blob/main/electron/gateway/startup-orchestrator.ts): restart policy · Startup orchestration, restart governor, and reload/recovery controls. · `electron/gateway/startup-orchestrator.ts`

### Provider & Secrets

Provider persistence, validation, and secure storage.

- [Providers](https://github.com/valuecell-ai/clawx/blob/main/electron/services/providers/provider-service.ts): service · Provider validation, migration, runtime sync, and persistence. · `electron/services/providers/provider-service.ts`
- [Secrets](https://github.com/valuecell-ai/clawx/blob/main/electron/services/secrets/secret-store.ts): secure storage · OS keychain-backed credential storage. · `electron/services/secrets/secret-store.ts`

### Extensions

Built-in and app-side extension system.

- [Extensions](https://github.com/valuecell-ai/clawx/blob/main/electron/extensions/index.ts): registry · Built-in extension loading and registry management. · `electron/extensions/index.ts`
- [UI extensions](https://github.com/valuecell-ai/clawx/blob/main/src/extensions/index.ts): registry · Renderer-side extension registry and loading. · `src/extensions/index.ts`

### Packaging & Assets

Build, bundle, and shipped runtime assets.

- [Skill packs](https://github.com/valuecell-ai/clawx/blob/main/resources/skills/preinstalled-manifest.json): asset bundle · Preinstalled skill manifests and bundled skill resources. · `resources/skills/preinstalled-manifest.json`
- [Bundle scripts](https://github.com/valuecell-ai/clawx/blob/main/scripts/bundle-openclaw.mjs): build pipeline · Packaging and bundling scripts for CLI, plugins, icons, and skills. · `scripts/bundle-openclaw.mjs`

### Quality

Representative test and regression coverage.

- [Unit tests](https://github.com/valuecell-ai/clawx/tree/main/tests/unit): test suite · Representative coverage for stores, gateway policies, providers, auth, and UI logic. · `tests/unit`
- [E2E tests](https://github.com/valuecell-ai/clawx/tree/main/tests/e2e): test suite · Electron-level flows for setup, navigation, provider lifecycle, and gateway behavior. · `tests/e2e`

## Connections

- App shell → Setup: routes to
- App shell → Chat: routes to
- App shell → Channels: routes to
- App shell → Cron: routes to
- App shell → Models: routes to
- App shell → Skills: routes to
- App shell → Settings: routes to
- App shell → Stores: uses state
- Chat → Host API: calls
- Channels → Host API: calls
- Settings → Host API: calls
- Models → Host API: calls
- Skills → Host API: calls
- Cron → Host API: calls
- Host API → IPC bridge: bridges through
- IPC bridge → API routes: dispatches to
- API routes → Gateway manager: controls
- API routes → Providers: uses
- Providers → Secrets: stores creds
- Gateway manager → Transport: communicates via
- Gateway manager → Recovery: restarts/reloads
- Main process → IPC bridge: hosts
- Main process → API routes: serves
- Main process → Gateway manager: supervises
- Extensions → Skill packs: loads packs
- UI extensions → Extensions: mirrors
- Bundle scripts → Skill packs: packages
- Unit tests → Host API: verifies
- Unit tests → Gateway manager: verifies
- Unit tests → Providers: verifies
- E2E tests → App shell: exercises
- E2E tests → Main process: exercises
- E2E tests → Gateway manager: exercises
