# jtroo/kanata architecture

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

- Interactive diagram: https://gitdiagram.com/jtroo/kanata
- Repository: https://github.com/jtroo/kanata

## Overview

##### Main System Components

a) Core Components:
- Input Handlers (Platform-specific)
- Linux handler
- macOS handler
- Windows handlers (LLHook and Interception)
- Parser Module
- Key Processing Engine
- Output Generation System
- TCP Server (Optional component)

b) Supporting Components:
- Configuration Manager
- GUI System (Windows-specific)
- Dynamic Macro System
- Layer Manager
- Sequence Manager

##### Component Relationships and Data Flow

a) Primary Data Flow:
**Physical Keyboard Input → Platform-specific Input Handler → Key Processing Engine → Output Generator → System Output**

b) Configuration Flow:
**Config File → Parser → Configuration Manager → Key Processing Engine**

##### Architectural Patterns to Highlight

- Platform abstraction layer (oskbd module)
- Plugin architecture for different input methods
- Event-driven processing system
- Layer management system

##### Implementation Details

Technical elements:
- Keyberon integration for key processing
- TCP protocol for external communication
- Configuration parsing system
- Platform-specific drivers/APIs

**Top: Input Sources (Physical keyboards, Configuration files)**
**Middle: Core Processing (Parser, Key Processing, Layer Management)**
**Bottom: Output Generation (Platform-specific output handlers)**
**Side: Optional Components (TCP Server, GUI)**

##### Additional Elements

Include:
- Version information
- Platform support indicators
- Key feature callouts (layers, macros, tap-hold)

##### Integration Points

Highlight:
- External tool integration points (TCP protocol)
- Configuration file processing
- Platform-specific hooks
- Driver interfaces (especially for Windows Interception)

This design reflects Kanata's nature as a sophisticated input processing system with cross-platform support and extensive customization capabilities, while clearly showing the separation between platform-specific and platform-independent components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        KB[Physical Keyboard]:::input
        CF[Configuration Files]:::config
    end

    subgraph "Platform Input Handlers"
        LH["Linux Handler"]:::platform
        MH["macOS Handler"]:::platform
        WH["Windows Handlers"]:::platform
        subgraph "Windows Specific"
            LLH["LLHook"]:::platform
            INT["Interception"]:::platform
        end
    end

    subgraph "Core Processing"
        PM["Parser Module"]:::core
        KPE["Key Processing Engine"]:::core
        LM["Layer Manager"]:::core
        SM["Sequence Manager"]:::core
        DM["Dynamic Macro System"]:::core
    end

    subgraph "Configuration"
        CP["Configuration Parser"]:::config
        KM["Key Mappings"]:::config
        CM["Configuration Manager"]:::config
    end

    subgraph "Output"
        OG["Output Generator"]:::core
        SO["System Output"]:::output
    end

    subgraph "Optional Components"
        TCP["TCP Server"]:::optional
        GUI["GUI System"]:::optional
    end

    %% Main Data Flow
    KB --> LH & MH & WH
    WH --> LLH & INT
    LH & MH & LLH & INT --> KPE
    KPE --> OG
    OG --> SO

    %% Configuration Flow
    CF --> CP
    CP --> CM
    CM --> KPE
    CP --> KM
    KM --> KPE

    %% Layer and Sequence Management
    KPE <--> LM
    KPE <--> SM
    KPE <--> DM

    %% Optional Component Integration
    TCP <--> KPE
    GUI <--> KPE

    %% Styling
    classDef core fill:#2196F3,stroke:#000,color:white
    classDef platform fill:#4CAF50,stroke:#000,color:white
    classDef config fill:#FFC107,stroke:#000,color:black
    classDef optional fill:#9C27B0,stroke:#000,color:white
    classDef input fill:#F44336,stroke:#000,color:white
    classDef output fill:#F44336,stroke:#000,color:white

    %% Click Events
    click LH "https://github.com/jtroo/kanata/blob/main/src/oskbd/linux.rs"
    click MH "https://github.com/jtroo/kanata/blob/main/src/oskbd/macos.rs"
    click LLH "https://github.com/jtroo/kanata/blob/main/src/oskbd/windows/llhook.rs"
    click INT "https://github.com/jtroo/kanata/blob/main/src/oskbd/windows/interception.rs"
    click PM "https://github.com/jtroo/kanata/blob/main/parser/src/lib.rs"
    click CP "https://github.com/jtroo/kanata/blob/main/parser/src/cfg/defcfg.rs"
    click KPE "https://github.com/jtroo/kanata/blob/main/keyberon/src/lib.rs"
    click OG "https://github.com/jtroo/kanata/blob/main/src/kanata/output_logic.rs"
    click TCP "https://github.com/jtroo/kanata/blob/main/src/tcp_server.rs"
    click GUI "https://github.com/jtroo/kanata/blob/main/src/gui/win.rs"
    click DM "https://github.com/jtroo/kanata/blob/main/src/kanata/dynamic_macro.rs"
    click LM "https://github.com/jtroo/kanata/blob/main/parser/src/layers.rs"
    click SM "https://github.com/jtroo/kanata/blob/main/src/kanata/sequences.rs"
    click KM "https://github.com/jtroo/kanata/blob/main/parser/src/keys/mod.rs"
```
