# alexfrmn/ruswitch architecture

> Architecture diagram of the GitHub repository alexfrmn/ruswitch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexfrmn/ruswitch
- Repository: https://github.com/alexfrmn/ruswitch

## Overview

RuSwitch is a Windows RU/EN keyboard-layout switcher. Its main workflow captures keystrokes, buffers words until a boundary, checks the detected script and dictionary, remaps likely wrong-layout words, and replaces the typed text. Users can also manually remap, undo recent corrections, configure exclusions and hotkeys, and manage learned words through the tray and settings GUI. The excerpts show the detector, dictionary, replacement, configuration, and UI responsibilities; some wiring is supported only by the SOURCE INDEX or README.

Main entry points: [`main.py`](https://github.com/alexfrmn/ruswitch/blob/main/main.py) (App orchestrator), [`dictionary.py`](https://github.com/alexfrmn/ruswitch/blob/main/dictionary.py) (Dictionary manager), [`config.py`](https://github.com/alexfrmn/ruswitch/blob/main/config.py) (Configuration), [`detector.py`](https://github.com/alexfrmn/ruswitch/blob/main/detector.py) (Word detector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Keyboard runtime"]
  node_main["App orchestrator<br/>[main.py]"]
  node_keyboard["Keyboard hooks"]
  node_foreground["Foreground app"]
  node_replacer["Text replacement and undo<br/>[replacer.py]"]
end

subgraph group_language["Detection and language"]
  node_detector["Word detector<br/>[detector.py]"]
  node_keymap["Layout mapping<br/>[keymap.py]"]
  node_dictionary["Dictionary manager<br/>[dictionary.py]"]
  node_basewords["Base word lists"]
end

subgraph group_state["User state"]
  node_config["Configuration<br/>[config.py]"]
  node_configstore[("Config JSON")]
  node_userwords[("User words and learning")]
end

subgraph group_interface["User interface"]
  node_tray["System tray<br/>[tray.py]"]
  node_settings["Settings GUI<br/>[settings_gui.py]"]
end

node_user(("User"))

node_user -->|"starts"| node_main
node_main -->|"loads"| node_config
node_config -->|"reads and writes"| node_configstore
node_main -->|"creates"| node_dictionary
node_dictionary -->|"loads"| node_basewords
node_dictionary -->|"persists"| node_userwords
node_dictionary -->|"reads threshold"| node_config
node_main -->|"registers hooks"| node_keyboard
node_keyboard -->|"sends keys"| node_main
node_main -->|"checks process"| node_foreground
node_main -->|"feeds characters"| node_detector
node_detector -->|"detects and remaps"| node_keymap
node_detector -->|"checks and records"| node_dictionary
node_detector -->|"reads settings"| node_config
node_main -->|"replaces detected word"| node_replacer
node_main -->|"runs and notifies"| node_tray
node_tray -->|"dispatches actions"| node_main
node_main -->|"opens settings"| node_settings
node_settings -->|"saves settings"| node_config
node_settings -->|"manages user words"| node_dictionary
node_settings -->|"applies saved settings"| node_main
node_user -->|"types or presses hotkeys"| node_keyboard
node_main -.->|"undoes recent correction"| node_replacer

click node_main "https://github.com/alexfrmn/ruswitch/blob/main/main.py"
click node_replacer "https://github.com/alexfrmn/ruswitch/blob/main/replacer.py"
click node_detector "https://github.com/alexfrmn/ruswitch/blob/main/detector.py"
click node_keymap "https://github.com/alexfrmn/ruswitch/blob/main/keymap.py"
click node_dictionary "https://github.com/alexfrmn/ruswitch/blob/main/dictionary.py"
click node_basewords "https://github.com/alexfrmn/ruswitch/tree/main/dictionaries"
click node_config "https://github.com/alexfrmn/ruswitch/blob/main/config.py"
click node_tray "https://github.com/alexfrmn/ruswitch/blob/main/tray.py"
click node_settings "https://github.com/alexfrmn/ruswitch/blob/main/settings_gui.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_keyboard,node_foreground,node_replacer,node_user toneBlue
class node_detector,node_keymap,node_dictionary,node_basewords toneAmber
class node_config,node_configstore,node_userwords toneMint
class node_tray,node_settings toneRose
```

## Components

### Keyboard runtime

- [App orchestrator](https://github.com/alexfrmn/ruswitch/blob/main/main.py): `main.py`
- **Keyboard hooks**
- **Foreground app**
- [Text replacement and undo](https://github.com/alexfrmn/ruswitch/blob/main/replacer.py): `replacer.py`

### Detection and language

- [Word detector](https://github.com/alexfrmn/ruswitch/blob/main/detector.py): `detector.py`
- [Layout mapping](https://github.com/alexfrmn/ruswitch/blob/main/keymap.py): `keymap.py`
- [Dictionary manager](https://github.com/alexfrmn/ruswitch/blob/main/dictionary.py): `dictionary.py`
- [Base word lists](https://github.com/alexfrmn/ruswitch/tree/main/dictionaries): `dictionaries`

### User state

- [Configuration](https://github.com/alexfrmn/ruswitch/blob/main/config.py): `config.py`
- **Config JSON**
- **User words and learning**

### User interface

- [System tray](https://github.com/alexfrmn/ruswitch/blob/main/tray.py): `tray.py`
- [Settings GUI](https://github.com/alexfrmn/ruswitch/blob/main/settings_gui.py): `settings_gui.py`

### Other components

- **User**

## Connections

- User → App orchestrator: starts (evidence: `README.md`)
- App orchestrator → Configuration: loads (evidence: `main.py`)
- Configuration → Config JSON: reads and writes (evidence: `config.py`)
- App orchestrator → Dictionary manager: creates (evidence: `main.py`)
- Dictionary manager → Base word lists: loads (evidence: `dictionary.py`)
- Dictionary manager → User words and learning: persists (evidence: `dictionary.py`)
- Dictionary manager → Configuration: reads threshold (evidence: `dictionary.py`)
- App orchestrator → Keyboard hooks: registers hooks (evidence: `main.py`)
- Keyboard hooks → App orchestrator: sends keys (evidence: `main.py`)
- App orchestrator → Foreground app: checks process (evidence: `main.py`)
- App orchestrator → Word detector: feeds characters (evidence: `main.py`)
- Word detector → Layout mapping: detects and remaps (evidence: `detector.py`)
- Word detector → Dictionary manager: checks and records (evidence: `detector.py`)
- Word detector → Configuration: reads settings (evidence: `detector.py`)
- App orchestrator → Text replacement and undo: replaces detected word (evidence: `main.py`)
- App orchestrator → System tray: runs and notifies (evidence: `main.py`)
- System tray → App orchestrator: dispatches actions (evidence: `tray.py`)
- App orchestrator → Settings GUI: opens settings (evidence: `main.py`)
- Settings GUI → Configuration: saves settings (evidence: `settings_gui.py`)
- Settings GUI → Dictionary manager: manages user words (evidence: `settings_gui.py`)
- Settings GUI → App orchestrator: applies saved settings (evidence: `main.py`)
- User → Keyboard hooks: types or presses hotkeys (evidence: `README.md`)
- App orchestrator → Text replacement and undo: undoes recent correction (evidence: `README.md`)
