# openjiuwen-ai/jiuwenclaw architecture

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

- Interactive diagram: https://gitdiagram.com/openjiuwen-ai/jiuwenclaw
- Repository: https://github.com/openjiuwen-ai/jiuwenclaw

## Overview

1. **Top-level shape**
   JiuwenClaw is a Python-based AI assistant platform with two main client surfaces: a browser UI and a terminal UI. The backend also speaks to multiple external chat/phone channels, and it can run as a local service, a desktop app, or a packaged executable.

2. **Primary runtime entry points**
   The executable entry points are split by concern: `app.py` and `start_services.py` for orchestration, `app_gateway.py` for channel routing, `app_agentserver.py` for the agent runtime, `app_web.py` for the web backend, and `app_cli.py` for the CLI mode. This separation is important for diagramming because the gateway and agent server are not the same component.

3. **Gateway layer: inbound/outbound message hub**
   `jiuwenclaw/gateway` is the message ingress/egress boundary. It contains channel routing, session mapping, heartbeat, cron triggering, and IM pipelines. Inbound messages from channels are normalized, bound to a session, and forwarded to the agent side; outbound responses are then delivered back through the original channel adapter.

4. **Channel adapters**
   `jiuwenclaw/channel` contains concrete integrations for Discord, Feishu, WeCom, WhatsApp, Telegram, WeChat, DingTalk, Xiaoyi, CLI, web, and ACP. The channel abstraction isolates platform-specific APIs, file upload/download handling, and message formatting from the core agent logic.

5. **Agent server: conversation, orchestration, and tool execution**
   `jiuwenclaw/agentserver` is the core intelligence runtime. It manages sessions, history, metadata, agents, skills, permissions, and streamed responses. This is where user messages are turned into LLM prompts, tool calls, and final replies.

6. **Deep agent pipeline**
   Inside `agentserver/deep_agent`, the system builds prompts and applies “rails” for runtime behavior, permissions, avatar/presentation, context engineering, response shaping, and stream events. This layer is the policy and prompt-composition boundary between raw user input and model invocation.

7. **Memory and context management**
   `agentserver/memory` provides long-term memory storage, embeddings, internal memory handling, and forbidden-content rules. Combined with session history and context compression features, it supports retrieval-augmented recall and controlled offloading of old context.

8. **Tools as the action boundary**
   `jiuwenclaw/agentserver/tools` is the main capability surface exposed to the agent: browser automation, command execution, cron/todo/task helpers, web search/fetch, multimodal image/audio/video tools, file delivery, and Xiaoyi phone actions. These tools form the bridge from language output to real-world side effects.

9. **Browser automation subsystem**
   Browser automation is a distinct mini-stack under `tools/browser-move`, backed by a Playwright-based runtime and MCP-style clients. It includes managed browser control, runtime services, controller logic, and patch sources, showing that browser actions are handled as a specialized external automation boundary rather than generic tool calls.

10. **Skills and self-evolution**
   The repo has a full skill lifecycle: static skills live in `resources/agent/jiuwenclaw_workspace/skills`, runtime skill loading is handled by `skill_manager`, and the `skilldev` pipeline supports generation, planning, testing, packaging, validation, and iterative improvement. The `evolution` package adds a feedback loop for detecting dissatisfaction and triggering skill refinement.

11. **Web application architecture**
   The web frontend under `jiuwenclaw/web` is a React/Vite app. Its panels map directly to backend domains: chat, sessions, todo, cron, skills, channels, heartbeat, logs, browser, config, extensions, and updates. The UI consumes WebSocket events and REST-like client services, with local state stores for chat/session/todo data.

12. **CLI architecture**
   The TypeScript CLI under `jiuwenclaw/cli` is a separate interactive client with command registration, session state, WebSocket protocol handling, and message rendering. It is not just a thin wrapper; it has its own command model, history parsing, and UI composition for terminal interaction.

13. **ACP / E2A protocol boundary**
   The `e2a` package and `agentserver/gateway_push` provide protocol normalization and wire encoding for agent-to-application communication. This boundary matters for integration diagrams because it abstracts transport details and allows the agent system to interoperate with ACP-style clients and push channels.

14. **Extensions and plugin boundary**
   `extensions` and `agentserver/extensions` provide a plugin/registry/loader layer around custom behaviors, callbacks, and SDK support. This is the extensibility seam for adding new capabilities without changing the core gateway-agent-message flow.

15. **State, configuration, and packaging**
   Runtime state and agent assets live under `resources`, including the default workspace, base configs, built-in rules, and skill templates. Deployment is supported through Dockerfiles, shell/PowerShell build scripts, and executable packaging files, which indicates the project can run as a long-lived service or be bundled for desktop distribution.

Main entry points: [`jiuwenclaw/agentserver`](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver) (agent server), [`jiuwenclaw/gateway`](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/gateway) (gateway), [`jiuwenclaw/app.py`](https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app.py) (app.py), [`jiuwenclaw/agentserver/tools`](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/tools) (tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtimes"]
  node_app_py["app.py<br/>entrypoint<br/>[app.py]"]
  node_start_services["start services<br/>service bootstrap<br/>[start_services.py]"]
  node_app_gateway["gateway app<br/>entrypoint<br/>[app_gateway.py]"]
  node_app_agentserver["agent app<br/>entrypoint<br/>[app_agentserver.py]"]
  node_app_web["web app<br/>entrypoint<br/>[app_web.py]"]
  node_app_cli["cli app<br/>entrypoint<br/>[app_cli.py]"]
end

subgraph group_core["Core backend"]
  node_gateway[("gateway<br/>message hub")]
  node_channels[("channels<br/>adapters")]
  node_agentserver[("agent server<br/>conversation runtime")]
  node_deep_agent["deep agent<br/>prompt policy"]
  node_memory[("memory<br/>retrieval store")]
  node_tools["tools<br/>capability surface"]
  node_skilldev["skilldev<br/>skill pipeline"]
  node_e2a["e2a<br/>protocol layer"]
  node_extensions["extensions<br/>plugin layer"]
end

subgraph group_clients["Clients"]
  node_web["web ui<br/>react frontend"]
  node_cli["terminal ui<br/>ts client"]
end

subgraph group_assets["Assets"]
  node_resources[("resources<br/>runtime assets")]
end

subgraph group_automation["Automation"]
  node_browser_move["browser-move<br/>browser automation"]
  node_xiaoyi_phone["xiaoyi phone<br/>phone tools"]
end

node_app_py -->|"bootstraps"| node_start_services
node_app_py -->|"starts"| node_app_gateway
node_app_py -->|"starts"| node_app_agentserver
node_app_py -->|"starts"| node_app_web
node_app_py -->|"starts"| node_app_cli
node_app_gateway -->|"hosts"| node_gateway
node_app_agentserver -->|"hosts"| node_agentserver
node_app_web -->|"serves"| node_web
node_app_cli -->|"runs"| node_cli
node_gateway -->|"routes"| node_channels
node_gateway -->|"forwards"| node_agentserver
node_gateway -->|"normalizes"| node_e2a
node_agentserver -->|"orchestrates"| node_deep_agent
node_agentserver -->|"retrieves"| node_memory
node_agentserver -->|"executes"| node_tools
node_agentserver -->|"develops skills"| node_skilldev
node_agentserver -->|"extends via"| node_extensions
node_web -->|"ws/rest"| node_gateway
node_cli -->|"ws protocol"| node_gateway
node_resources -->|"configures"| node_agentserver
node_resources -->|"templates"| node_skilldev
node_tools -->|"specializes"| node_browser_move
node_tools -->|"specializes"| node_xiaoyi_phone
node_channels -->|"adapts"| node_e2a
node_extensions -->|"hooks into"| node_agentserver

click node_app_py "https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app.py"
click node_start_services "https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/start_services.py"
click node_app_gateway "https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app_gateway.py"
click node_app_agentserver "https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app_agentserver.py"
click node_app_web "https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app_web.py"
click node_app_cli "https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app_cli.py"
click node_gateway "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/gateway"
click node_channels "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/channel"
click node_agentserver "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver"
click node_deep_agent "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/deep_agent"
click node_memory "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/memory"
click node_tools "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/tools"
click node_skilldev "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/skilldev"
click node_e2a "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/e2a"
click node_extensions "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/extensions"
click node_web "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/web"
click node_cli "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/cli"
click node_resources "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/resources"
click node_browser_move "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/tools/browser-move"
click node_xiaoyi_phone "https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/tools/xiaoyi_phone_tools"

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_app_py,node_start_services,node_app_gateway,node_app_agentserver,node_app_web,node_app_cli toneBlue
class node_gateway,node_channels,node_agentserver,node_deep_agent,node_memory,node_tools,node_skilldev,node_e2a,node_extensions toneAmber
class node_web,node_cli toneMint
class node_resources toneRose
class node_browser_move,node_xiaoyi_phone toneIndigo
```

## Components

### Runtimes

Primary process entry points and app modes.

- [app.py](https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app.py): entrypoint · Main top-level launcher and orchestration entry. · `jiuwenclaw/app.py`
- [start services](https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/start_services.py): service bootstrap · Starts and coordinates local services. · `jiuwenclaw/start_services.py`
- [gateway app](https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app_gateway.py): entrypoint · Channel-facing gateway process. · `jiuwenclaw/app_gateway.py`
- [agent app](https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app_agentserver.py): entrypoint · Agent runtime process entry. · `jiuwenclaw/app_agentserver.py`
- [web app](https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app_web.py): entrypoint · Browser backend entry. · `jiuwenclaw/app_web.py`
- [cli app](https://github.com/openjiuwen-ai/jiuwenclaw/blob/develop/jiuwenclaw/app_cli.py): entrypoint · Terminal client entry. · `jiuwenclaw/app_cli.py`

### Core backend

Gateway, agent runtime, protocol, and extension boundaries.

- [gateway](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/gateway): message hub · Ingress/egress boundary for channel messages. · `jiuwenclaw/gateway`
- [channels](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/channel): adapters · Platform-specific chat and file-transfer integrations. · `jiuwenclaw/channel`
- [agent server](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver): conversation runtime · Core session, agent, skill, and tool execution runtime. · `jiuwenclaw/agentserver`
- [deep agent](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/deep_agent): prompt policy · Prompt composition, rails, permissions, and stream shaping. · `jiuwenclaw/agentserver/deep_agent`
- [memory](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/memory): retrieval store · Long-term memory, embeddings, and forbidden-content rules. · `jiuwenclaw/agentserver/memory`
- [tools](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/tools): capability surface · Action boundary for browser, search, media, cron, files, and phone tasks. · `jiuwenclaw/agentserver/tools`
- [skilldev](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/skilldev): skill pipeline · Skill generation, validation, packaging, and improvement pipeline. · `jiuwenclaw/agentserver/skilldev`
- [e2a](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/e2a): protocol layer · Agent-to-application normalization and wire encoding. · `jiuwenclaw/e2a`
- [extensions](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/extensions): plugin layer · Extension loading, registry, and SDK boundary. · `jiuwenclaw/extensions`

### Clients

Browser and terminal user interfaces.

- [web ui](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/web): react frontend · Browser UI with panels for chat, sessions, skills, tools, and config. · `jiuwenclaw/web`
- [terminal ui](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/cli): ts client · Interactive terminal client with commands, session state, and websocket protocol. · `jiuwenclaw/cli`

### Assets

Packaged runtime state, prompts, skills, and configs.

- [resources](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/resources): runtime assets · Default workspace, prompts, rules, config, and bundled skills. · `jiuwenclaw/resources`

### Automation

Specialized browser and phone action subsystems.

- [browser-move](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/tools/browser-move): browser automation · Playwright-based managed browser runtime and MCP-style clients. · `jiuwenclaw/agentserver/tools/browser-move`
- [xiaoyi phone](https://github.com/openjiuwen-ai/jiuwenclaw/tree/develop/jiuwenclaw/agentserver/tools/xiaoyi_phone_tools): phone tools · Xiaoyi device actions for contacts, files, media, notes, and messaging. · `jiuwenclaw/agentserver/tools/xiaoyi_phone_tools`

## Connections

- app.py → start services: bootstraps · Primary launcher coordinates service startup.
- app.py → gateway app: starts · Can launch gateway mode.
- app.py → agent app: starts · Can launch agent runtime mode.
- app.py → web app: starts · Can launch web backend mode.
- app.py → cli app: starts · Can launch terminal client mode.
- gateway app → gateway: hosts · Gateway app runs the message hub.
- agent app → agent server: hosts · Agent app runs the core runtime.
- web app → web ui: serves · Web entry exposes the browser UI backend.
- cli app → terminal ui: runs · CLI entry starts the terminal client.
- gateway → channels: routes · Normalizes inbound channel messages and delivers responses back out.
- gateway → agent server: forwards · Gateway hands user sessions and messages to agent runtime.
- gateway → e2a: normalizes · Protocol boundary for ACP-style and push communication.
- agent server → deep agent: orchestrates · Conversation runtime delegates prompt and policy shaping.
- agent server → memory: retrieves · Uses long-term memory and context controls.
- agent server → tools: executes · Agent invokes tools for side effects and external actions.
- agent server → skilldev: develops skills · Manages skill generation, testing, packaging, and refinement.
- agent server → extensions: extends via · Loads plugins, callbacks, and SDK integrations.
- web ui → gateway: ws/rest · Web UI consumes live events and backend services.
- terminal ui → gateway: ws protocol · Terminal client communicates through websocket session flow.
- resources → agent server: configures · Provides workspace prompts, rules, and skill assets.
- resources → skilldev: templates · Supplies skill workspace and bundled examples.
- tools → browser-move: specializes · Browser automation is a dedicated tool subsystem.
- tools → xiaoyi phone: specializes · Phone/device actions are isolated in their own tool stack.
- channels → e2a: adapts · Channel integrations align with protocol normalization.
- extensions → agent server: hooks into · Plugin layer attaches to core agent flow.
