# huytd/goxkey architecture

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

- Interactive diagram: https://gitdiagram.com/huytd/goxkey
- Repository: https://github.com/huytd/goxkey

## Overview

##### Project Type Analysis
This is a system-level application that intercepts and processes keyboard input to enable Vietnamese text input. It's a desktop application with platform-specific implementations.

##### Main Components

A. Core Components:
- Input Handler (src/input.rs)
- Hotkey Manager (src/hotkey.rs)
- Configuration System (src/config.rs)
- UI Layer (src/ui.rs)
- Vietnamese Input Engine (external: vi-rs)

B. Platform-Specific Layers:
- macOS Implementation
- Windows Implementation
- Linux Implementation

**┌─ User Interface Layer ─────────────────┐**
- System Tray Interface               │
- Configuration UI                    │
- Core Processing Layer ────────────────┤
- ┌─ Input Processing ─┐ ┌─ Scripting ─┐│
- Key Interception │ │ - Parser    ││
- Input Handling   │ └────────────┘││
- ┘                 ││
- ┌─ Vietnamese Processing ────────────┐││
- Telex Method                    │││
- VNI Method                      │││
- ┘││
- Platform Abstraction Layer ──────────┤
- ┌─────────┐ ┌─────────┐ ┌─────────┐  │
- macOS   │ │ Windows │ │ Linux   │  │
- ┘ └─────────┘ └─────────┘  │
- ┘

##### Key Relationships to Highlight
- How keyboard events flow from the OS through the platform layer
- Processing pipeline from raw input to Vietnamese text output
- Demonstrate configuration flow from UI to core components

##### Important Implementation Details
- Use of core-foundation and core-graphics for macOS
- Integration with vi-rs engine
- Configuration persistence flow

##### Configuration management flow

This system design should effectively communicate both the high-level architecture and the specific implementation details that make Gõkey work across different platforms while maintaining its core Vietnamese text processing functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#a8d1f0,stroke:#2980b9
    classDef platform fill:#98fb98,stroke:#2ecc71
    classDef external fill:#f5b041,stroke:#d35400
    classDef ui fill:#d7bde2,stroke:#8e44ad

    subgraph UI["User Interface Layer"]
        SysTray["System Tray Interface"]:::ui
        ConfigUI["Configuration UI"]:::ui
    end

    subgraph Core["Core Processing Layer"]
        subgraph InputProc["Input Processing"]
            KeyIntercept["Key Interception"]:::core
            InputHandler["Input Handler"]:::core
            HotkeyMgr["Hotkey Manager"]:::core
        end

        subgraph Script["Scripting System"]
            ScriptEngine["Scripting Engine"]:::core
            Parser["Script Parser"]:::core
        end

        subgraph VietProc["Vietnamese Processing"]
            TelexMethod["Telex Method"]:::core
            VNIMethod["VNI Method"]:::core
            ViEngine["vi-rs Engine"]:::external
        end

        Config["Configuration System"]:::core
    end

    subgraph Platform["Platform Abstraction Layer"]
        PlatformAbs["Platform Abstraction"]:::platform
        MacOS["macOS Implementation"]:::platform
        Windows["Windows Implementation"]:::platform
        Linux["Linux Implementation"]:::platform
    end

    %% Relationships
    SysTray --> Config
    ConfigUI --> Config
    Config --> InputHandler
    Config --> HotkeyMgr

    KeyIntercept --> InputHandler
    InputHandler --> ScriptEngine
    HotkeyMgr --> InputHandler

    ScriptEngine --> Parser
    Parser --> VietProc

    InputHandler --> TelexMethod
    InputHandler --> VNIMethod
    TelexMethod --> ViEngine
    VNIMethod --> ViEngine

    PlatformAbs --> MacOS
    PlatformAbs --> Windows
    PlatformAbs --> Linux

    MacOS --> KeyIntercept
    Windows --> KeyIntercept
    Linux --> KeyIntercept

    %% Click Events
    click InputHandler "https://github.com/huytd/goxkey/blob/main/src/input.rs"
    click HotkeyMgr "https://github.com/huytd/goxkey/blob/main/src/hotkey.rs"
    click Config "https://github.com/huytd/goxkey/blob/main/src/config.rs"
    click SysTray "https://github.com/huytd/goxkey/blob/main/src/ui.rs"
    click ConfigUI "https://github.com/huytd/goxkey/blob/main/src/ui.rs"
    click PlatformAbs "https://github.com/huytd/goxkey/blob/main/src/platform/mod.rs"
    click MacOS "https://github.com/huytd/goxkey/blob/main/src/platform/macos.rs"
    click Windows "https://github.com/huytd/goxkey/blob/main/src/platform/windows.rs"
    click Linux "https://github.com/huytd/goxkey/blob/main/src/platform/linux.rs"
    click ScriptEngine "https://github.com/huytd/goxkey/blob/main/src/scripting/mod.rs"
    click Parser "https://github.com/huytd/goxkey/blob/main/src/scripting/parser.rs"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Platform-Specific"]:::platform
        L3["External Dependencies"]:::external
        L4["User Interface"]:::ui
    end
```
