# alex/what-happens-when architecture

> Architecture diagram of the GitHub repository alex/what-happens-when, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alex/what-happens-when
- Repository: https://github.com/alex/what-happens-when

## Overview

This repository is an explanatory guide, not an executable application: its documented workflow follows Enter from keyboard input through operating-system event delivery to browser address-bar handling and URL parsing. It describes separate USB and virtual-keyboard input paths, then Windows, macOS, and GNU/Linux event-delivery paths. The excerpt also documents autocomplete while typing and fallback to a search engine when the input is not a valid URL. The tree contains only README.rst, and the supplied README excerpt ends during URL parsing, so later navigation and response stages are not represented.

Main entry points: [`README.rst`](https://github.com/alex/what-happens-when/blob/master/README.rst) (OS input handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input"]
  node_keyboard_switch["Key switch<br/>[README.rst]"]
  node_keyboard_controller["Keyboard controller<br/>[README.rst]"]
  node_usb_transport["USB transport<br/>[README.rst]"]
  node_virtual_keyboard["Virtual keyboard<br/>[README.rst]"]
end

subgraph group_os_delivery["OS event delivery"]
  node_os_input["OS input handling<br/>[README.rst]"]
  node_windows_driver["Windows keyboard drivers<br/>[README.rst]"]
  node_windows_message["Windows message pump<br/>[README.rst]"]
  node_mac_windowserver["macOS WindowServer<br/>[README.rst]"]
  node_mac_event_queue["macOS event queue<br/>[README.rst]"]
  node_linux_xorg["X server and evdev<br/>[README.rst]"]
  node_linux_window_manager["Window manager<br/>[README.rst]"]
end

subgraph group_browser_handling["Browser handling"]
  node_browser_address["Browser address bar<br/>[README.rst]"]
  node_autocomplete["Autocomplete<br/>[README.rst]"]
  node_url_parser["URL parser<br/>[README.rst]"]
  node_search_fallback["Search fallback<br/>[README.rst]"]
end

node_user(("User"))
node_search_engine["Default search engine"]

node_user -->|"presses key"| node_keyboard_switch
node_keyboard_switch -->|"generates keycode"| node_keyboard_controller
node_keyboard_controller -->|"encodes keycode"| node_usb_transport
node_usb_transport -->|"delivers keycode"| node_os_input
node_user -->|"presses key"| node_virtual_keyboard
node_virtual_keyboard -->|"sends key event"| node_os_input
node_os_input -->|"delivers keydown"| node_windows_driver
node_windows_driver -->|"sends message"| node_windows_message
node_windows_message -->|"dispatches keydown"| node_browser_address
node_os_input -->|"passes keycode"| node_mac_windowserver
node_mac_windowserver -->|"dispatches event"| node_mac_event_queue
node_mac_event_queue -->|"delivers keydown"| node_browser_address
node_os_input -->|"delivers keycode"| node_linux_xorg
node_linux_xorg -->|"sends character"| node_linux_window_manager
node_linux_window_manager -->|"forwards character"| node_browser_address
node_browser_address -->|"refines suggestions"| node_autocomplete
node_browser_address -->|"parses input"| node_url_parser
node_url_parser -->|"checks validity"| node_search_fallback
node_search_fallback -->|"feeds search text"| node_search_engine

click node_keyboard_switch "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_keyboard_controller "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_usb_transport "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_virtual_keyboard "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_os_input "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_windows_driver "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_windows_message "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_mac_windowserver "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_mac_event_queue "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_linux_xorg "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_linux_window_manager "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_browser_address "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_autocomplete "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_url_parser "https://github.com/alex/what-happens-when/blob/master/README.rst"
click node_search_fallback "https://github.com/alex/what-happens-when/blob/master/README.rst"

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_keyboard_switch,node_keyboard_controller,node_usb_transport,node_virtual_keyboard,node_user toneBlue
class node_os_input,node_windows_driver,node_windows_message,node_mac_windowserver,node_mac_event_queue,node_linux_xorg,node_linux_window_manager toneAmber
class node_browser_address,node_autocomplete,node_url_parser,node_search_fallback toneMint
class node_search_engine toneIndigo
```

## Components

### Input

- [Key switch](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [Keyboard controller](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [USB transport](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [Virtual keyboard](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`

### OS event delivery

- [OS input handling](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [Windows keyboard drivers](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [Windows message pump](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [macOS WindowServer](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [macOS event queue](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [X server and evdev](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [Window manager](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`

### Browser handling

- [Browser address bar](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [Autocomplete](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [URL parser](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`
- [Search fallback](https://github.com/alex/what-happens-when/blob/master/README.rst): `README.rst`

### Other components

- **User**
- **Default search engine**

## Connections

- User → Key switch: presses key (evidence: `README.rst`)
- Key switch → Keyboard controller: generates keycode (evidence: `README.rst`)
- Keyboard controller → USB transport: encodes keycode (evidence: `README.rst`)
- USB transport → OS input handling: delivers keycode (evidence: `README.rst`)
- User → Virtual keyboard: presses key (evidence: `README.rst`)
- Virtual keyboard → OS input handling: sends key event (evidence: `README.rst`)
- OS input handling → Windows keyboard drivers: delivers keydown (evidence: `README.rst`)
- Windows keyboard drivers → Windows message pump: sends message (evidence: `README.rst`)
- Windows message pump → Browser address bar: dispatches keydown (evidence: `README.rst`)
- OS input handling → macOS WindowServer: passes keycode (evidence: `README.rst`)
- macOS WindowServer → macOS event queue: dispatches event (evidence: `README.rst`)
- macOS event queue → Browser address bar: delivers keydown (evidence: `README.rst`)
- OS input handling → X server and evdev: delivers keycode (evidence: `README.rst`)
- X server and evdev → Window manager: sends character (evidence: `README.rst`)
- Window manager → Browser address bar: forwards character (evidence: `README.rst`)
- Browser address bar → Autocomplete: refines suggestions (evidence: `README.rst`)
- Browser address bar → URL parser: parses input (evidence: `README.rst`)
- URL parser → Search fallback: checks validity (evidence: `README.rst`)
- Search fallback → Default search engine: feeds search text (evidence: `README.rst`)
