# rime/weasel architecture

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

- Interactive diagram: https://gitdiagram.com/rime/weasel
- Repository: https://github.com/rime/weasel

## Overview

##### Main Components
- Core Input Engine:
– RimeWithWeasel: This module integrates directly with the Rime engine. It likely contains the principal text processing and candidate selection logic.
- User Interface & Input Method Framework:
– WeaselIME: Manages the classic IME integration on Windows using Win32 and resource files.
– WeaselTSF: Implements the Text Services Framework (TSF) support for modern Windows text input.
– WeaselUI: Provides the graphical components (candidate lists, panels, overlays) essential for interacting with the user.
- Inter-process Communication (IPC):
– WeaselIPC and WeaselIPCServer: These handle communications between the various components (for example, between the UI modules and the core, or between the service and helper processes).
- Service & Background Operations:
– WeaselServer: Deals with system-level operations such as managing the system tray, background services, and perhaps handling hotkey events.
- Deployment and Setup:
– WeaselDeployer: Provides a configuration tool that lets users change input language setup, runtime options, and perform “re-deploy” actions after modifying user data.
– WeaselSetup: Contains the installer and initial setup routines.
- Build & Platform Support:
– arm64x_wrapper: Wraps or provides definitions for building the modules for different Windows architectures (e.g., x64, arm64).
- Common Libraries & Modules:
– The “include” directory gathers common headers – utility functions, IPC definitions, constants – used by various components.

##### Relationships and Data Flow
– The UI modules (WeaselIME, WeaselTSF, WeaselUI) receive user input and display candidate options.
– These modules interact with the RimeWithWeasel core to process input text and generate conversion candidates.
– The IPC components serve as the bridge between the UI and core services, ensuring that the various modules communicate efficiently.
– The WeaselDeployer and WeaselSetup modules provide entry points for configuring the system, updating settings, and installing/uninstalling the service.

##### Architectural Patterns and Design Principles
- Modularization: The project is split into several executables/libraries (each as a separate directory), emphasizing a modular design where each component handles a dedicated responsibility.
- Separation of Concerns: Input data processing (RimeWithWeasel), system communication (WeaselIPC/WeaselIPCServer), UI rendering (WeaselUI), and system integration (WeaselIME, WeaselTSF) are clearly separated.

##### Final Reminders for the Principal Software Engineer
- That every primary component is represented with a clearly marked label.
- Remember to annotate any external dependencies that significantly impact the system’s functionality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        WeaselIME["WeaselIME"]:::ui
        WeaselTSF["WeaselTSF"]:::ui
        WeaselUI["WeaselUI"]:::ui
    end

    %% Communication Layer
    subgraph "Communication Layer"
        WeaselIPC["WeaselIPC"]:::ipc
        WeaselIPCServer["WeaselIPCServer"]:::ipc
    end

    %% Core Processing Layer
    subgraph "Core Processing Layer"
        RimeWithWeasel["RimeWithWeasel"]:::core
        WeaselServer["WeaselServer"]:::core
    end

    %% Deployment & Configuration
    subgraph "Deployment & Configuration"
        WeaselDeployer["WeaselDeployer"]:::deploy
        WeaselSetup["WeaselSetup"]:::deploy
    end

    %% Build & Support
    subgraph "Build & Support"
        arm64x_wrapper["arm64x_wrapper"]:::build
        include["Common Libraries"]:::build
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Boost["Boost"]:::external
        curl["curl"]:::external
        LevelDB["LevelDB"]:::external
        librime["librime"]:::external
        WinSparkle["WinSparkle"]:::external
        yaml_cpp["yaml-cpp"]:::external
    end

    %% Data Flow Connections
    WeaselIME -->|"calls"| WeaselIPC
    WeaselTSF -->|"calls"| WeaselIPC
    WeaselUI -->|"calls"| WeaselIPC

    WeaselIPC -->|"forwards"| RimeWithWeasel
    RimeWithWeasel -->|"responds"| WeaselIPCServer

    WeaselIPCServer -->|"updates"| WeaselIME
    WeaselIPCServer -->|"updates"| WeaselTSF
    WeaselIPCServer -->|"updates"| WeaselUI

    WeaselServer -->|"communicates"| WeaselDeployer
    WeaselDeployer -->|"triggers"| WeaselSetup

    arm64x_wrapper -->|"supports"| RimeWithWeasel
    include -->|"provides"| RimeWithWeasel
    include -->|"provides"| WeaselIPC

    Boost -->|"dependency"| RimeWithWeasel
    curl -->|"dependency"| WeaselServer
    LevelDB -->|"dependency"| RimeWithWeasel
    librime -->|"dependency"| RimeWithWeasel
    WinSparkle -->|"dependency"| WeaselServer
    yaml_cpp -->|"dependency"| WeaselDeployer

    %% Click Events
    click RimeWithWeasel "https://github.com/rime/weasel/tree/master/RimeWithWeasel"
    click WeaselIME "https://github.com/rime/weasel/tree/master/WeaselIME"
    click WeaselTSF "https://github.com/rime/weasel/tree/master/WeaselTSF"
    click WeaselUI "https://github.com/rime/weasel/tree/master/WeaselUI"
    click WeaselIPC "https://github.com/rime/weasel/tree/master/WeaselIPC"
    click WeaselIPCServer "https://github.com/rime/weasel/tree/master/WeaselIPCServer"
    click WeaselServer "https://github.com/rime/weasel/tree/master/WeaselServer"
    click WeaselDeployer "https://github.com/rime/weasel/tree/master/WeaselDeployer"
    click WeaselSetup "https://github.com/rime/weasel/tree/master/WeaselSetup"
    click arm64x_wrapper "https://github.com/rime/weasel/tree/master/arm64x_wrapper"
    click include "https://github.com/rime/weasel/tree/master/include"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef ipc fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef deploy fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef build fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;
```
