# claw-codes/wx4py architecture

> Architecture diagram of the GitHub repository claw-codes/wx4py, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/claw-codes/wx4py
- Repository: https://github.com/claw-codes/wx4py

## Overview

wx4py automates the Windows WeChat 4.x desktop client through UI Automation. The main workflow is to connect a client, perform chat or group-management operations, or process group messages through a listener, handlers, and serialized actions. Documented capabilities also include message forwarding, AI-assisted replies, chat-history inspection, and group administration. Edges follow the supplied excerpts, source-index references, or README; some feature internals were not sampled, so those relationships are omitted rather than inferred.

Main entry points: [`src/features/chat.py`](https://github.com/claw-codes/wx4py/blob/main/src/features/chat.py) (Chat operations), [`src/client.py`](https://github.com/claw-codes/wx4py/blob/main/src/client.py) (WeChatClient), [`src/features/groups.py`](https://github.com/claw-codes/wx4py/blob/main/src/features/groups.py) (Group management), [`src/core/window.py`](https://github.com/claw-codes/wx4py/blob/main/src/core/window.py) (Window manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client and sessions"]
  node_client_api["WeChatClient<br/>[client.py]"]
end

subgraph group_ui["Desktop automation"]
  node_window["Window manager<br/>[window.py]"]
  node_uiawrap["UIA wrapper<br/>[uia_wrapper.py]"]
  node_uia["UI Automation<br/>[uiautomation.py]"]
  node_win32["Windows controls<br/>[win32.py]"]
  node_tray["Tray handling<br/>[tray.py]"]
end

subgraph group_features["WeChat features"]
  node_base["Page base<br/>[base.py]"]
  node_chat["Chat operations<br/>[chat.py]"]
  node_groups_api["Group management<br/>[groups.py]"]
end

subgraph group_messaging["Message processing"]
  node_processor["Group processor<br/>[processor.py]"]
  node_listener["Message listener<br/>[listener.py]"]
  node_forwarder["Forward rules<br/>[forwarder.py]"]
  node_ai["AI integration<br/>[ai.py]"]
end

subgraph group_support["Configuration and support"]
  node_config["Runtime settings<br/>[config.py]"]
  node_logger["Logging and audit<br/>[logger.py]"]
  node_exceptions["Error types<br/>[exceptions.py]"]
  node_clipboard["Clipboard utilities<br/>[clipboard_utils.py]"]
  node_markdown["Markdown utilities<br/>[markdown_utils.py]"]
end

node_developer(("Python caller"))
node_wechat["WeChat desktop"]

node_developer -->|"creates client"| node_client_api
node_client_api -->|"connects window"| node_window
node_client_api -->|"creates chat API"| node_chat
node_client_api -->|"creates group API"| node_groups_api
node_client_api -->|"starts processing"| node_processor
node_window -->|"controls desktop"| node_wechat
node_window -->|"initializes UIA"| node_uiawrap
node_window -->|"uses window controls"| node_win32
node_window -->|"restores from tray"| node_tray
node_uiawrap -->|"wraps automation"| node_uia
node_chat -->|"inherits page behavior"| node_base
node_groups_api -->|"inherits page behavior"| node_base
node_groups_api -->|"uses chat operations"| node_chat
node_chat -->|"uses clipboard"| node_clipboard
node_groups_api -->|"formats announcements"| node_markdown
node_processor -->|"starts listener"| node_listener
node_listener -->|"reads UI controls"| node_uia
node_processor -->|"sends actions"| node_chat
node_forwarder -->|"emits forward actions"| node_processor
node_ai -->|"uses message events"| node_listener
node_developer -->|"manages groups"| node_groups_api
node_developer -->|"sends and inspects chats"| node_chat
node_developer -->|"configures forwarding"| node_forwarder
node_developer -->|"configures AI replies"| node_ai
node_chat -->|"logs operations"| node_logger
node_groups_api -->|"logs operations"| node_logger
node_client_api -->|"raises connection error"| node_exceptions
node_config -->|"configures logging"| node_logger
node_base -->|"minimizes window"| node_win32

click node_client_api "https://github.com/claw-codes/wx4py/blob/main/src/client.py"
click node_window "https://github.com/claw-codes/wx4py/blob/main/src/core/window.py"
click node_uiawrap "https://github.com/claw-codes/wx4py/blob/main/src/core/uia_wrapper.py"
click node_uia "https://github.com/claw-codes/wx4py/blob/main/src/core/uiautomation.py"
click node_win32 "https://github.com/claw-codes/wx4py/blob/main/src/core/win32.py"
click node_tray "https://github.com/claw-codes/wx4py/blob/main/src/core/tray.py"
click node_base "https://github.com/claw-codes/wx4py/blob/main/src/features/base.py"
click node_chat "https://github.com/claw-codes/wx4py/blob/main/src/features/chat.py"
click node_groups_api "https://github.com/claw-codes/wx4py/blob/main/src/features/groups.py"
click node_processor "https://github.com/claw-codes/wx4py/blob/main/src/features/messaging/processor.py"
click node_listener "https://github.com/claw-codes/wx4py/blob/main/src/features/messaging/listener.py"
click node_forwarder "https://github.com/claw-codes/wx4py/blob/main/src/features/messaging/forwarder.py"
click node_ai "https://github.com/claw-codes/wx4py/blob/main/src/ai.py"
click node_config "https://github.com/claw-codes/wx4py/blob/main/src/config.py"
click node_logger "https://github.com/claw-codes/wx4py/blob/main/src/utils/logger.py"
click node_exceptions "https://github.com/claw-codes/wx4py/blob/main/src/core/exceptions.py"
click node_clipboard "https://github.com/claw-codes/wx4py/blob/main/src/utils/clipboard_utils.py"
click node_markdown "https://github.com/claw-codes/wx4py/blob/main/src/utils/markdown_utils.py"

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_client_api toneBlue
class node_window,node_uiawrap,node_uia,node_win32,node_tray toneAmber
class node_base,node_chat,node_groups_api toneMint
class node_processor,node_listener,node_forwarder,node_ai toneRose
class node_config,node_logger,node_exceptions,node_clipboard,node_markdown,node_developer,node_wechat toneIndigo
```

## Components

### Client and sessions

- [WeChatClient](https://github.com/claw-codes/wx4py/blob/main/src/client.py): `src/client.py`

### Desktop automation

- [Window manager](https://github.com/claw-codes/wx4py/blob/main/src/core/window.py): `src/core/window.py`
- [UIA wrapper](https://github.com/claw-codes/wx4py/blob/main/src/core/uia_wrapper.py): `src/core/uia_wrapper.py`
- [UI Automation](https://github.com/claw-codes/wx4py/blob/main/src/core/uiautomation.py): `src/core/uiautomation.py`
- [Windows controls](https://github.com/claw-codes/wx4py/blob/main/src/core/win32.py): `src/core/win32.py`
- [Tray handling](https://github.com/claw-codes/wx4py/blob/main/src/core/tray.py): `src/core/tray.py`

### WeChat features

- [Page base](https://github.com/claw-codes/wx4py/blob/main/src/features/base.py): `src/features/base.py`
- [Chat operations](https://github.com/claw-codes/wx4py/blob/main/src/features/chat.py): `src/features/chat.py`
- [Group management](https://github.com/claw-codes/wx4py/blob/main/src/features/groups.py): `src/features/groups.py`

### Message processing

- [Group processor](https://github.com/claw-codes/wx4py/blob/main/src/features/messaging/processor.py): `src/features/messaging/processor.py`
- [Message listener](https://github.com/claw-codes/wx4py/blob/main/src/features/messaging/listener.py): `src/features/messaging/listener.py`
- [Forward rules](https://github.com/claw-codes/wx4py/blob/main/src/features/messaging/forwarder.py): `src/features/messaging/forwarder.py`
- [AI integration](https://github.com/claw-codes/wx4py/blob/main/src/ai.py): `src/ai.py`

### Configuration and support

- [Runtime settings](https://github.com/claw-codes/wx4py/blob/main/src/config.py): `src/config.py`
- [Logging and audit](https://github.com/claw-codes/wx4py/blob/main/src/utils/logger.py): `src/utils/logger.py`
- [Error types](https://github.com/claw-codes/wx4py/blob/main/src/core/exceptions.py): `src/core/exceptions.py`
- [Clipboard utilities](https://github.com/claw-codes/wx4py/blob/main/src/utils/clipboard_utils.py): `src/utils/clipboard_utils.py`
- [Markdown utilities](https://github.com/claw-codes/wx4py/blob/main/src/utils/markdown_utils.py): `src/utils/markdown_utils.py`

### Other components

- **Python caller**
- **WeChat desktop**

## Connections

- Python caller → WeChatClient: creates client (evidence: `README.md`)
- WeChatClient → Window manager: connects window (evidence: `src/client.py`)
- WeChatClient → Chat operations: creates chat API (evidence: `src/client.py`)
- WeChatClient → Group management: creates group API (evidence: `src/client.py`)
- WeChatClient → Group processor: starts processing (evidence: `src/client.py`)
- Window manager → WeChat desktop: controls desktop (evidence: `README.md`)
- Window manager → UIA wrapper: initializes UIA (evidence: `src/core/window.py`)
- Window manager → Windows controls: uses window controls (evidence: `src/core/window.py`)
- Window manager → Tray handling: restores from tray (evidence: `src/core/window.py`)
- UIA wrapper → UI Automation: wraps automation (evidence: `src/core/uia_wrapper.py`)
- Chat operations → Page base: inherits page behavior (evidence: `src/features/chat.py`)
- Group management → Page base: inherits page behavior (evidence: `src/features/groups.py`)
- Group management → Chat operations: uses chat operations (evidence: `src/features/groups.py`)
- Chat operations → Clipboard utilities: uses clipboard (evidence: `src/features/chat.py`)
- Group management → Markdown utilities: formats announcements (evidence: `src/features/groups.py`)
- Group processor → Message listener: starts listener (evidence: `src/features/messaging/processor.py`)
- Message listener → UI Automation: reads UI controls (evidence: `src/features/messaging/listener.py`)
- Group processor → Chat operations: sends actions (evidence: `src/features/messaging/processor.py`)
- Forward rules → Group processor: emits forward actions (evidence: `src/features/messaging/forwarder.py`)
- AI integration → Message listener: uses message events (evidence: `src/ai.py`)
- Python caller → Group management: manages groups (evidence: `README.md`)
- Python caller → Chat operations: sends and inspects chats (evidence: `README.md`)
- Python caller → Forward rules: configures forwarding (evidence: `README.md`)
- Python caller → AI integration: configures AI replies (evidence: `README.md`)
- Chat operations → Logging and audit: logs operations (evidence: `src/features/chat.py`)
- Group management → Logging and audit: logs operations (evidence: `src/features/groups.py`)
- WeChatClient → Error types: raises connection error (evidence: `src/client.py`)
- Runtime settings → Logging and audit: configures logging (evidence: `src/utils/logger.py`)
- Page base → Windows controls: minimizes window (evidence: `src/features/base.py`)
