# sunnyyoung/wechattweak-macos architecture

> Architecture diagram of the GitHub repository sunnyyoung/wechattweak-macos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sunnyyoung/wechattweak-macos
- Repository: https://github.com/sunnyyoung/wechattweak-macos

## Overview

This project is a macOS tweak for the WeChat client—essentially a dynamic library that enhances and modifies the behavior of the official WeChat macOS application. The primary purpose is to add features such as blocking message revocation, allowing multiple instances of WeChat to be launched, and enhancing message handling (for example, exporting any emoji, QR code recognition, and direct link copying). It also provides a user interface for settings and integrates with other productivity tools like Alfred, Raycast, and Launchbar.

##### Main components
- Tweak Core & Injection Mechanism: The core is built as a dynamic library that hooks into WeChat. Components like “WeChatTweak.m”, “AntiRevoke.m”, and “MultipleInstances.m” represent the business logic that modifies WeChat behavior.
- UI Preferences & Controller Module: This includes the user interface elements provided by the tweak (for example, “TweakPreferencesController” in various language-specific resources) for configuration of the tweaks.
- Category Extensions: Modules in the “Category” directory (e.g., NSBundle+WeChatTweak.m) enhance or override existing classes using Objective-C categories.
- Integration Modules: Separate integration projects such as the Alfred workflow (WeChat.alfredworkflow), Launchbar action (WeChatTweak.lbaction), and potentially integration with Raycast. These ensure that the tweak communicates smoothly with external applications and services.
- Build & Configuration Artifacts: The project has an Xcode project structure (WeChatTweak.xcodeproj and WeChatTweak.xcworkspace), a Podfile for CocoaPods dependency management, and additional build scripts or configuration files (like the Makefile). These support the build and installation process.
- Injection/Linking Helpers: Files such as “insert_dylib” and “fishhook.podspec” indicate that the project might use dynamic library injection techniques (possibly using tools like fishhook) to hook into WeChat’s runtime.

##### Relationships and interactions
- The dynamic library (“WeChatTweak”) is injected into the WeChat application at runtime. It intercepts specific function calls (for message retraction, multi-instance management, etc.) and modifies behavior accordingly.
- The UI Preferences component interacts with the core tweak module, letting users enable, disable, or configure features.
- The integration modules operate as adjuncts: for instance, when triggered via Alfred or Launchbar, they might call into the tweak’s API or trigger actions within the WeChat client.
- The build system (Xcode, CocoaPods configuration, and Makefile) coordinates the compilation, linking, and packaging of the dynamic library, ensuring that the injection and integration components are properly included.

##### Architectural patterns and design principles
- Modularity: The project is cleanly separated into modules – core functionality, UI handling, and external integrations are individually managed.
- Hooking & Injection: The primary pattern is method hooking (using techniques like those provided by fishhook) to intercept and modify behaviors in WeChat.
- Extension & Localization: With multiple language folders and resource bundles (for example, localized strings in en.lproj, zh-Hans.lproj, zh-Hant.lproj), the design emphasizes internationalization alongside extensibility.
- Integration with external tools is treated as first-class citizens – their workflows (Alfred, Launchbar, Raycast) are designed to work seamlessly with the tweak.

##### Relevant technologies, frameworks, or libraries
- Objective-C and Xcode are the main development environments.
- Cocoa and macOS frameworks form the basis of the UI and system integrations.
- CocoaPods (as indicated by the Podfile and fishhook.podspec) manage third-party dependencies, likely including libraries for hooking and runtime modifications.
- Integration with third-party tools such as Alfred, Raycast, and Launchbar is handled via separate workflow and action packages.

##### Elements
- Clear labels for each module/component (Core Tweak, UI Preferences, Category Extensions, Integration Modules, Build Tools).
- Optionally, include the injection mechanism showing how the tweak library is injected into the running WeChat client.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Configuration Artifacts
    subgraph "Build & Configuration Artifacts"
        B1["WeChatTweak.xcodeproj"]:::build
        B2["WeChatTweak.xcworkspace"]:::build
        B3["Podfile & Podfile.lock"]:::build
        B4["Makefile"]:::build
    end

    %% Injection/Linking Helpers
    subgraph "Injection/Linking Helpers"
        I1["insert_dylib"]:::injectHelper
        I2["fishhook.podspec"]:::injectHelper
    end

    %% Core Tweak & Injection Mechanism
    subgraph "Core Tweak & Injection Mechanism"
        CT1["WeChatTweak.m"]:::core
        CT2["AntiRevoke.m"]:::core
        CT3["MultipleInstances.m"]:::core
    end

    %% UI Preferences & Controller Module
    subgraph "UI Preferences & Controller Module"
        UI1["TweakPreferencesController.m"]:::ui
        UI2["TweakPreferencesController.h"]:::ui
        UI3["TweakPreferencesController.xib"]:::ui
        UI4["LocalizedStrings"]:::ui
    end

    %% Category Extensions
    subgraph "Category Extensions"
        CE1["NSBundle+WeChatTweak.m"]:::category
        CE2["NSBundle+WeChatTweak.h"]:::category
    end

    %% Integration Modules
    subgraph "Integration Modules"
        IM1["Alfred Workflow"]:::integration
        IM2["Launchbar Action"]:::integration
        IM3["Raycast Integration"]:::integration
    end

    %% WeChat Client
    subgraph "WeChat Client"
        WC["WeChat Application Process"]:::external
    end

    %% Relationships: Build artifacts build modules
    B1 -->|"builds"| CT1
    B1 -->|"builds"| UI1
    B1 -->|"builds"| CE1
    B1 -->|"builds"| IM1

    B2 -->|"builds"| CT1
    B2 -->|"builds"| UI1
    B2 -->|"builds"| CE1
    B2 -->|"builds"| IM2

    B3 -->|"manages"| CT1
    B3 -->|"manages"| UI1
    B3 -->|"manages"| CE1
    B3 -->|"manages"| IM1

    B4 -->|"executes"| CT1
    B4 -->|"executes"| UI1
    B4 -->|"executes"| CE1
    B4 -->|"executes"| IM2

    %% Injection/Linking Helpers inject into Core Tweak
    I1 -->|"injects"| CT1
    I2 -->|"injects"| CT1

    %% Core Tweak interactions
    CT2 -->|"partof"| CT1
    CT3 -->|"partof"| CT1

    %% UI Preferences interacts with Core Tweak
    UI1 -->|"configures"| CT1
    UI2 -->|"configures"| CT1
    UI3 -->|"configures"| CT1
    UI4 -->|"configures"| CT1

    %% Category Extensions extend Core Tweak
    CE1 -->|"extends"| CT1
    CE2 -->|"extends"| CT1

    %% Integration Modules trigger Core Tweak functions
    IM1 -->|"triggers"| CT1
    IM2 -->|"triggers"| CT1
    IM3 -->|"triggers"| CT1

    %% Core Tweak gets injected into WeChat Client
    CT1 -->|"hooks"| WC

    %% Click Events for Tweak Core & Injection Mechanism
    click CT1 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak/WeChatTweak.m"
    click CT2 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak/AntiRevoke.m"
    click CT3 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak/MultipleInstances.m"

    %% Click Events for UI Preferences & Controller Module
    click UI1 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak/Controller/TweakPreferencesController.m"
    click UI2 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak/Controller/TweakPreferencesController.h"
    click UI3 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak/Controller/Base.lproj/TweakPreferencesController.xib"
    click UI4 "https://github.com/sunnyyoung/wechattweak-macos/tree/master/WeChatTweak/Controller"

    %% Click Events for Category Extensions
    click CE1 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak/Category/NSBundle+WeChatTweak.m"
    click CE2 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak/Category/NSBundle+WeChatTweak.h"

    %% Click Events for Integration Modules
    click IM1 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChat.alfredworkflow"
    click IM2 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak.lbaction"

    %% Click Events for Build & Configuration Artifacts
    click B1 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak.xcodeproj"
    click B2 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/WeChatTweak.xcworkspace"
    click B3 "https://github.com/sunnyyoung/wechattweak-macos/tree/master/Podfile"
    click B4 "https://github.com/sunnyyoung/wechattweak-macos/tree/master/Makefile"

    %% Click Events for Injection/Linking Helpers
    click I1 "https://github.com/sunnyyoung/wechattweak-macos/tree/master/insert_dylib"
    click I2 "https://github.com/sunnyyoung/wechattweak-macos/blob/master/fishhook.podspec"

    %% Styles
    classDef core fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef ui fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef category fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef integration fill:#ffedcc,stroke:#cc6600,stroke-width:2px;
    classDef build fill:#e0e0e0,stroke:#999999,stroke-width:2px;
    classDef injectHelper fill:#d0f0fd,stroke:#00aced,stroke-width:2px;
    classDef external fill:#fffacc,stroke:#ff9900,stroke-width:2px;
```
