# oniatsu/hotswitch-hs architecture

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

- Interactive diagram: https://gitdiagram.com/oniatsu/hotswitch-hs
- Repository: https://github.com/oniatsu/hotswitch-hs

## Overview

##### Project Type and Purpose
- HotSwitch-HS is a macOS utility that replaces the system window switcher by using a customized hotkey mechanism integrated with Hammerspoon.
- The README explains its operation—registering a fixed key to windows and then switching between them via that key—and hints at its two main phases: key/registration handling and window switching.
- The project is not a traditional full-stack system but rather a focused desktop tool that leverages macOS “glue” software (Hammerspoon) to interact with windows.

##### File Structure for Key Architectural Insights
- The “lib” directory is divided into several key parts:
– /lib/common: Contains generic utilities (like constants for canvas, debugging, frame calculations, time checks, and updating) that support the overall operations.
– /lib/controller: Contains the MainController and HotkeyController, which likely serve to orchestrate the interactions between user input and internal logic.
– /lib/model: Includes different model files (the AppWatchModel, KeyStatusModel, PreferenceModel, etc.) that represent application data – the current window states, user settings, and key registrations.
– /lib/view: Contains the view components (BaseCanvasView, PanelLayoutView, SelectedRowCanvasView, ToastView) responsible for displaying the panel and window information.
- The main entry point appears to be the “hotswitch-hs.lua” file, which ties the module to Hammerspoon.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Integration
    HS_API["Hammerspoon API"]:::hs

    %% Entry Point
    ENTRY["hotswitch-hs.lua"]:::entry

    %% Controllers Layer
    subgraph "Controllers Layer"
        CTRL1["Main Controller"]:::controller
        CTRL2["Hotkey Controller"]:::controller
    end

    %% Models Layer
    subgraph "Models Layer"
        MODEL1["AppWatch Model"]:::model
        MODEL2["KeyStatus Model"]:::model
        MODEL3["Preference Model"]:::model
        MODEL4["Window Model"]:::model
    end

    %% Views Layer
    subgraph "Views Layer"
        VIEW1["BaseCanvas View"]:::view
        VIEW2["PanelLayout View"]:::view
        VIEW3["SelectedRowCanvas View"]:::view
        VIEW4["Toast View"]:::view
    end

    %% Common Utilities and Documentation
    COMMON["Common Utilities"]:::common
    DOC["UML Documentation"]:::doc

    %% Data Flow Connections
    HS_API -->|"bindsHotkeys"| ENTRY
    ENTRY -->|"initializes"| CTRL1
    ENTRY -->|"initializes"| CTRL2

    CTRL1 -->|"updates"| MODEL1
    CTRL1 -->|"updates"| MODEL2
    CTRL1 -->|"updates"| MODEL3
    CTRL1 -->|"updates"| MODEL4

    CTRL2 -->|"handlesHotkeyEvents"| MODEL2

    MODEL1 -->|"stateChange"| VIEW1
    MODEL2 -->|"stateChange"| VIEW2
    MODEL3 -->|"stateChange"| VIEW3
    MODEL4 -->|"stateChange"| VIEW4

    CTRL1 -->|"triggersViewUpdate"| VIEW1
    CTRL2 -->|"triggersViewUpdate"| VIEW4

    COMMON --> CTRL1
    COMMON --> CTRL2
    COMMON --> VIEW1
    COMMON --> VIEW2
    COMMON --> VIEW3
    COMMON --> VIEW4

    DOC --- ENTRY
    DOC --- CTRL1
    DOC --- CTRL2
    DOC --- MODEL1
    DOC --- MODEL2
    DOC --- MODEL3
    DOC --- MODEL4
    DOC --- VIEW1
    DOC --- VIEW2
    DOC --- VIEW3
    DOC --- VIEW4

    %% Click Events
    click ENTRY "https://github.com/oniatsu/hotswitch-hs/blob/main/hotswitch-hs.lua"
    click CTRL1 "https://github.com/oniatsu/hotswitch-hs/blob/main/lib/controller/MainController.lua"
    click CTRL2 "https://github.com/oniatsu/hotswitch-hs/blob/main/lib/controller/HotkeyController.lua"
    click COMMON "https://github.com/oniatsu/hotswitch-hs/tree/main/lib/common"
    click MODEL1 "https://github.com/oniatsu/hotswitch-hs/tree/main/lib/model"
    click VIEW1 "https://github.com/oniatsu/hotswitch-hs/tree/main/lib/view"
    click DOC "https://github.com/oniatsu/hotswitch-hs/blob/main/doc/uml/class_diagram.pu"

    %% Styling Classes
    class HS_API hs
    class ENTRY entry
    class CTRL1,CTRL2 controller
    class MODEL1,MODEL2,MODEL3,MODEL4 model
    class VIEW1,VIEW2,VIEW3,VIEW4 view
    class COMMON common
    class DOC doc

    %% Class Definitions with Colors
    classDef hs fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;
    classDef entry fill:#f5b7b1,stroke:#e74c3c,stroke-width:2px;
    classDef controller fill:#aed6f1,stroke:#3498db,stroke-width:2px;
    classDef model fill:#abebc6,stroke:#27ae60,stroke-width:2px;
    classDef view fill:#f9e79f,stroke:#f39c12,stroke-width:2px;
    classDef common fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
    classDef doc fill:#f7dc6f,stroke:#f1c40f,stroke-width:2px;
```
