# fly-jelly/wechat-cli architecture

> Architecture diagram of the GitHub repository fly-jelly/wechat-cli, 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/fly-jelly/wechat-cli
- Repository: https://github.com/fly-jelly/wechat-cli

## Overview

WeChat CLI is a local-data query tool: users initialize configuration and encryption keys, then invoke commands to inspect chats, messages, contacts, and related information as JSON or text. The main CLI creates shared application context and dispatches commands; that context loads configuration, keys, and a decrypted-database cache. Command modules query the local databases, with new-messages additionally persisting a check state. The README documents the full command suite and analytics/export capabilities. Some command and platform-scanner internals were not excerpted, so only indexed or documented relationships are shown.

Main entry points: [`wechat_cli/main.py`](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/main.py) (Command dispatcher), [`wechat_cli/core/contacts.py`](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/contacts.py) (Contact data access), [`wechat_cli/core/context.py`](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/context.py) (Shared app context), [`wechat_cli/core/db_cache.py`](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/db_cache.py) (Decrypted DB cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI entry and setup"]
  node_main["Command dispatcher<br/>[main.py]"]
  node_init["Initialization command<br/>[init.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_context["Shared app context<br/>[context.py]"]
  node_keyinit["Key scanner routing<br/>[__init__.py]"]
  node_scanmac["macOS key scanner<br/>[scanner_macos.py]"]
  node_scanlinux["Linux key scanner<br/>[scanner_linux.py]"]
  node_scanwindows["Windows key scanner<br/>[scanner_windows.py]"]
  node_keycommon["Shared key scanning<br/>[common.py]"]
end

subgraph group_data["Local data access"]
  node_cache["Decrypted DB cache<br/>[db_cache.py]"]
  node_crypto["Database decryption<br/>[crypto.py]"]
  node_keyutils["Key path utilities<br/>[key_utils.py]"]
  node_contactsdata["Contact data access<br/>[contacts.py]"]
  node_messagesdata["Message query engine<br/>[messages.py]"]
end

subgraph group_commands["Query capabilities"]
  node_sessions["Sessions and unread<br/>[sessions.py]"]
  node_history["Chat history<br/>[history.py]"]
  node_search["Message search<br/>[search.py]"]
  node_contacts["Contact lookup<br/>[contacts.py]"]
  node_members["Group members<br/>[members.py]"]
  node_favorites["Favorites<br/>[favorites.py]"]
  node_stats["Chat statistics<br/>[stats.py]"]
  node_export["Conversation export<br/>[export.py]"]
  node_newmessages["New messages<br/>[new_messages.py]"]
end

subgraph group_presentation["Output"]
  node_format["JSON and text formatter<br/>[formatter.py]"]
  node_state["Check-state file<br/>[new_messages.py]"]
end

node_user(("CLI user"))

node_user -->|"runs command"| node_main
node_main -->|"creates context"| node_context
node_main -->|"dispatches init"| node_init
node_main -->|"dispatches"| node_sessions
node_main -->|"dispatches"| node_history
node_main -->|"dispatches"| node_search
node_main -->|"dispatches"| node_contacts
node_main -->|"dispatches"| node_members
node_main -->|"dispatches"| node_favorites
node_main -->|"dispatches"| node_stats
node_main -->|"dispatches"| node_export
node_main -->|"dispatches"| node_newmessages
node_context -->|"loads config"| node_config
node_context -->|"creates cache"| node_cache
node_context -->|"strips key metadata"| node_keyutils
node_context -->|"finds message keys"| node_messagesdata
node_init -->|"loads setup"| node_config
node_init -->|"uses scanners"| node_keyinit
node_keyinit -->|"selects platform"| node_scanmac
node_keyinit -->|"selects platform"| node_scanlinux
node_keyinit -->|"selects platform"| node_scanwindows
node_scanmac -->|"uses shared scan"| node_keycommon
node_scanlinux -->|"uses shared scan"| node_keycommon
node_scanwindows -->|"uses shared scan"| node_keycommon
node_cache -->|"decrypts databases"| node_crypto
node_cache -->|"resolves keys"| node_keyutils
node_sessions -->|"reads session DB"| node_cache
node_sessions -->|"loads contact names"| node_contactsdata
node_search -->|"loads contact names"| node_contactsdata
node_search -->|"searches messages"| node_messagesdata
node_history -->|"queries history"| node_messagesdata
node_export -->|"queries messages"| node_messagesdata
node_export -->|"resolves contacts"| node_contactsdata
node_contacts -->|"queries contacts"| node_contactsdata
node_members -->|"loads members"| node_contactsdata
node_favorites -->|"resolves contacts"| node_contactsdata
node_stats -->|"computes statistics"| node_messagesdata
node_newmessages -->|"reads session DB"| node_cache
node_newmessages -->|"reads and writes"| node_state
node_search -->|"formats output"| node_format
node_sessions -->|"formats output"| node_format
node_newmessages -->|"formats output"| node_format

click node_main "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/main.py"
click node_init "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/init.py"
click node_config "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/config.py"
click node_context "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/context.py"
click node_keyinit "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/__init__.py"
click node_scanmac "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/scanner_macos.py"
click node_scanlinux "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/scanner_linux.py"
click node_scanwindows "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/scanner_windows.py"
click node_keycommon "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/common.py"
click node_cache "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/db_cache.py"
click node_crypto "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/crypto.py"
click node_keyutils "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/key_utils.py"
click node_contactsdata "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/contacts.py"
click node_messagesdata "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/messages.py"
click node_sessions "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/sessions.py"
click node_history "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/history.py"
click node_search "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/search.py"
click node_contacts "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/contacts.py"
click node_members "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/members.py"
click node_favorites "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/favorites.py"
click node_stats "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/stats.py"
click node_export "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/export.py"
click node_newmessages "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/new_messages.py"
click node_format "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/output/formatter.py"
click node_state "https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/new_messages.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_main,node_init,node_config,node_context,node_keyinit,node_scanmac,node_scanlinux,node_scanwindows,node_keycommon,node_user toneBlue
class node_cache,node_crypto,node_keyutils,node_contactsdata,node_messagesdata toneAmber
class node_sessions,node_history,node_search,node_contacts,node_members,node_favorites,node_stats,node_export,node_newmessages toneMint
class node_format,node_state toneRose
```

## Components

### CLI entry and setup

- [Command dispatcher](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/main.py): `wechat_cli/main.py`
- [Initialization command](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/init.py): `wechat_cli/commands/init.py`
- [Configuration](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/config.py): `wechat_cli/core/config.py`
- [Shared app context](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/context.py): `wechat_cli/core/context.py`
- [Key scanner routing](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/__init__.py): `wechat_cli/keys/__init__.py`
- [macOS key scanner](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/scanner_macos.py): `wechat_cli/keys/scanner_macos.py`
- [Linux key scanner](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/scanner_linux.py): `wechat_cli/keys/scanner_linux.py`
- [Windows key scanner](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/scanner_windows.py): `wechat_cli/keys/scanner_windows.py`
- [Shared key scanning](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/keys/common.py): `wechat_cli/keys/common.py`

### Local data access

- [Decrypted DB cache](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/db_cache.py): `wechat_cli/core/db_cache.py`
- [Database decryption](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/crypto.py): `wechat_cli/core/crypto.py`
- [Key path utilities](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/key_utils.py): `wechat_cli/core/key_utils.py`
- [Contact data access](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/contacts.py): `wechat_cli/core/contacts.py`
- [Message query engine](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/core/messages.py): `wechat_cli/core/messages.py`

### Query capabilities

- [Sessions and unread](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/sessions.py): `wechat_cli/commands/sessions.py`
- [Chat history](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/history.py): `wechat_cli/commands/history.py`
- [Message search](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/search.py): `wechat_cli/commands/search.py`
- [Contact lookup](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/contacts.py): `wechat_cli/commands/contacts.py`
- [Group members](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/members.py): `wechat_cli/commands/members.py`
- [Favorites](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/favorites.py): `wechat_cli/commands/favorites.py`
- [Chat statistics](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/stats.py): `wechat_cli/commands/stats.py`
- [Conversation export](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/export.py): `wechat_cli/commands/export.py`
- [New messages](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/new_messages.py): `wechat_cli/commands/new_messages.py`

### Output

- [JSON and text formatter](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/output/formatter.py): `wechat_cli/output/formatter.py`
- [Check-state file](https://github.com/fly-jelly/wechat-cli/blob/main/wechat_cli/commands/new_messages.py): `wechat_cli/commands/new_messages.py`

### Other components

- **CLI user**

## Connections

- CLI user → Command dispatcher: runs command (evidence: `README.md`)
- Command dispatcher → Shared app context: creates context (evidence: `wechat_cli/main.py`)
- Command dispatcher → Initialization command: dispatches init (evidence: `wechat_cli/main.py`)
- Command dispatcher → Sessions and unread: dispatches (evidence: `wechat_cli/main.py`)
- Command dispatcher → Chat history: dispatches (evidence: `wechat_cli/main.py`)
- Command dispatcher → Message search: dispatches (evidence: `wechat_cli/main.py`)
- Command dispatcher → Contact lookup: dispatches (evidence: `wechat_cli/main.py`)
- Command dispatcher → Group members: dispatches (evidence: `wechat_cli/main.py`)
- Command dispatcher → Favorites: dispatches (evidence: `wechat_cli/main.py`)
- Command dispatcher → Chat statistics: dispatches (evidence: `wechat_cli/main.py`)
- Command dispatcher → Conversation export: dispatches (evidence: `wechat_cli/main.py`)
- Command dispatcher → New messages: dispatches (evidence: `wechat_cli/main.py`)
- Shared app context → Configuration: loads config (evidence: `wechat_cli/core/context.py`)
- Shared app context → Decrypted DB cache: creates cache (evidence: `wechat_cli/core/context.py`)
- Shared app context → Key path utilities: strips key metadata (evidence: `wechat_cli/core/context.py`)
- Shared app context → Message query engine: finds message keys (evidence: `wechat_cli/core/context.py`)
- Initialization command → Configuration: loads setup (evidence: `wechat_cli/commands/init.py`)
- Initialization command → Key scanner routing: uses scanners (evidence: `wechat_cli/commands/init.py`)
- Key scanner routing → macOS key scanner: selects platform (evidence: `wechat_cli/keys/__init__.py`)
- Key scanner routing → Linux key scanner: selects platform (evidence: `wechat_cli/keys/__init__.py`)
- Key scanner routing → Windows key scanner: selects platform (evidence: `wechat_cli/keys/__init__.py`)
- macOS key scanner → Shared key scanning: uses shared scan (evidence: `wechat_cli/keys/scanner_macos.py`)
- Linux key scanner → Shared key scanning: uses shared scan (evidence: `wechat_cli/keys/scanner_linux.py`)
- Windows key scanner → Shared key scanning: uses shared scan (evidence: `wechat_cli/keys/scanner_windows.py`)
- Decrypted DB cache → Database decryption: decrypts databases (evidence: `wechat_cli/core/db_cache.py`)
- Decrypted DB cache → Key path utilities: resolves keys (evidence: `wechat_cli/core/db_cache.py`)
- Sessions and unread → Decrypted DB cache: reads session DB (evidence: `wechat_cli/commands/sessions.py`)
- Sessions and unread → Contact data access: loads contact names (evidence: `wechat_cli/commands/sessions.py`)
- Message search → Contact data access: loads contact names (evidence: `wechat_cli/commands/search.py`)
- Message search → Message query engine: searches messages (evidence: `wechat_cli/commands/search.py`)
- Chat history → Message query engine: queries history (evidence: `wechat_cli/commands/history.py`)
- Conversation export → Message query engine: queries messages (evidence: `wechat_cli/commands/export.py`)
- Conversation export → Contact data access: resolves contacts (evidence: `wechat_cli/commands/export.py`)
- Contact lookup → Contact data access: queries contacts (evidence: `wechat_cli/commands/contacts.py`)
- Group members → Contact data access: loads members (evidence: `wechat_cli/commands/members.py`)
- Favorites → Contact data access: resolves contacts (evidence: `wechat_cli/commands/favorites.py`)
- Chat statistics → Message query engine: computes statistics (evidence: `wechat_cli/commands/stats.py`)
- New messages → Decrypted DB cache: reads session DB (evidence: `wechat_cli/commands/new_messages.py`)
- New messages → Check-state file: reads and writes (evidence: `wechat_cli/commands/new_messages.py`)
- Message search → JSON and text formatter: formats output (evidence: `wechat_cli/commands/search.py`)
- Sessions and unread → JSON and text formatter: formats output (evidence: `wechat_cli/commands/sessions.py`)
- New messages → JSON and text formatter: formats output (evidence: `wechat_cli/commands/new_messages.py`)
