# koekeishiya/skhd architecture

> Architecture diagram of the GitHub repository koekeishiya/skhd, 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/koekeishiya/skhd
- Repository: https://github.com/koekeishiya/skhd

## Overview

##### Main Components Identification

a) Core Components:
- Event Tap System (event_tap.c/h)
- Hotkey Manager (hotkey.c/h)
- Config Parser (parse.c/h, tokenize.c/h)
- Hot Reload System (hotload.c/h)
- Key Synthesizer (synthesize.c/h)

b) Supporting Components:
- Logging System (log.h)
- Notification System (notify.c)
- Service Management (service.h)
- Locale Handler (locale.c/h)

**┌─────────────────────────────────────────────────┐**
- macOS System                   │
- ┬─────────────────┬──────────────┘

- ▼                 ▼
**┌──────────────────────┐  ┌──────────────┐**
- Accessibility API   │  │ File System  │
- ┬───────────┘  └───────┬──────┘

**┌──────────▼──────────────────────▼──────────────┐**
- SKHD                        │
- ┌─────────────┐        ┌──────────────────┐  │
- Event Tap   ◄────────► Hotkey Manager   │  │
- ┬───────┘        └────────┬─────────┘  │

- ┌─────▼───────┐        ┌───────▼─────────┐  │
- Synthesizer │        │ Config Parser   │  │
- ┘        └───────┬─────────┘  │

- ┌───────▼─────────┐  │
- Hot Reloader   │  │
- ┘  │
- ┘

##### Data Flow Indicators

- Bidirectional communication between Event Tap and Hotkey Manager
- One-way flow from Config Parser to Hotkey Manager
- Event flow from Accessibility API to Event Tap
- Configuration file monitoring from File System to Hot Reloader

##### Additional Details

**Config File → Tokenizer → Parser → Hotkey Manager**

##### Implementation Notes

- Use of hashtable for efficient hotkey lookup
- Modal hotkey system support
- Application-specific hotkey handling
- Blacklist functionality

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "macOS System"
        AccessAPI["Accessibility API"]:::external
        FileSystem["File System"]:::external
    end

    subgraph "SKHD Core"
        Main["Main Program"]:::core
        EventTap["Event Tap System"]:::core
        HotkeyMgr["Hotkey Manager"]:::core
        ConfigParser["Config Parser"]:::core
        HotReload["Hot Reload System"]:::core
        KeySynth["Key Synthesizer"]:::core
        Carbon["Carbon Interface"]:::core
    end

    subgraph "Support Systems"
        Logger["Logging System"]:::support
        Notifier["Notification System"]:::support
        ServiceMgr["Service Management"]:::support
        LocaleHandler["Locale Handler"]:::support
    end

    subgraph "Data Structures"
        HashTable["Hash Table"]:::data
        SBuffer["String Buffer"]:::data
    end

    %% Core Connections
    AccessAPI --> EventTap
    FileSystem --> HotReload
    EventTap <--> HotkeyMgr
    HotkeyMgr --> KeySynth
    ConfigParser --> HotkeyMgr
    HotReload --> ConfigParser
    Carbon --> EventTap
    Main --> ServiceMgr
    Main --> EventTap

    %% Support Connections
    Logger --> Main
    Notifier --> Main
    LocaleHandler --> ConfigParser
    HashTable --> HotkeyMgr
    SBuffer --> ConfigParser

    %% Click Events
    click EventTap "https://github.com/koekeishiya/skhd/blob/master/src/event_tap.c"
    click HotkeyMgr "https://github.com/koekeishiya/skhd/blob/master/src/hotkey.c"
    click ConfigParser "https://github.com/koekeishiya/skhd/blob/master/src/parse.c"
    click HotReload "https://github.com/koekeishiya/skhd/blob/master/src/hotload.c"
    click KeySynth "https://github.com/koekeishiya/skhd/blob/master/src/synthesize.c"
    click Logger "https://github.com/koekeishiya/skhd/blob/master/src/log.h"
    click Notifier "https://github.com/koekeishiya/skhd/blob/master/src/notify.c"
    click ServiceMgr "https://github.com/koekeishiya/skhd/blob/master/src/service.h"
    click LocaleHandler "https://github.com/koekeishiya/skhd/blob/master/src/locale.c"
    click Main "https://github.com/koekeishiya/skhd/blob/master/src/skhd.c"
    click Carbon "https://github.com/koekeishiya/skhd/blob/master/src/carbon.c"
    click HashTable "https://github.com/koekeishiya/skhd/blob/master/src/hashtable.h"
    click SBuffer "https://github.com/koekeishiya/skhd/blob/master/src/sbuffer.h"

    %% Styling
    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef external fill:#57a773,stroke:#57a773,color:#fff
    classDef support fill:#ffc857,stroke:#ffc857,color:#000
    classDef data fill:#a8a8a8,stroke:#a8a8a8,color:#fff

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        ExtComp["External Interface"]:::external
        SuppComp["Support Component"]:::support
        DataComp["Data Structure"]:::data
    end
```
