# zmkfirmware/zmk architecture

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

- Interactive diagram: https://gitdiagram.com/zmkfirmware/zmk
- Repository: https://github.com/zmkfirmware/zmk

## Overview

ZMK is Zephyr-based mechanical-keyboard firmware. Its principal workflow scans physical key positions, interprets them through keymap behaviors, and sends HID output through USB or Bluetooth; split transports extend that workflow across keyboard halves. The repository also includes sensors, displays, pointing input, and Studio RPC. Several central runtime connections are not shown in the excerpts, so those edges are dashed and unverified; the display composition and output-status relationships have direct source evidence.

Main entry points: [`app/src/endpoints.c`](https://github.com/zmkfirmware/zmk/blob/main/app/src/endpoints.c) (Output selection), [`app/src/behavior.c`](https://github.com/zmkfirmware/zmk/blob/main/app/src/behavior.c) (Behaviors), [`app/src/keymap.c`](https://github.com/zmkfirmware/zmk/blob/main/app/src/keymap.c) (Keymap), [`app/boards/lowprokb/corneish_zen/widgets/output_status.c`](https://github.com/zmkfirmware/zmk/blob/main/app/boards/lowprokb/corneish_zen/widgets/output_status.c) (Output status widget)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and mapping"]
  node_kscan["Matrix scan"]
  node_keymap["Keymap<br/>[keymap.c]"]
  node_combos["Combos<br/>[combo.c]"]
  node_sensors["Sensor input<br/>[sensors.c]"]
end

subgraph group_runtime["Behavior and HID"]
  node_behavior["Behaviors<br/>[behavior.c]"]
  node_holdtap["Hold-tap"]
  node_hid["HID reports<br/>[hid.c]"]
  node_endpoints["Output selection<br/>[endpoints.c]"]
end

subgraph group_connectivity["Connectivity"]
  node_usb["USB HID<br/>[usb_hid.c]"]
  node_ble["Bluetooth<br/>[ble.c]"]
  node_split["Split service<br/>[service.c]"]
  node_splitcentral["Split central<br/>[central.c]"]
  node_splitperipheral["Split peripheral<br/>[peripheral.c]"]
end

subgraph group_devices["Devices and display"]
  node_battery["Battery gauge<br/>[max17048.c]"]
  node_displayruntime["Display runtime<br/>[main.c]"]
  node_statusscreen["Corneish Zen screen"]
  node_outputstatus["Output status widget<br/>[output_status.c]"]
  node_niceview["Nice!View screen"]
  node_nicestatus["Nice!View status widget<br/>[status.c]"]
  node_il0323["IL0323 display driver<br/>[il0323.c]"]
end

subgraph group_studio["Studio"]
  node_studio["Studio RPC<br/>[rpc.c]"]
  node_keymapstudio["Studio keymap<br/>[keymap_subsystem.c]"]
end

node_user(("Keyboard user"))
node_host(("HID host"))

node_user -.->|"presses keys"| node_kscan
node_kscan -.->|"reports positions"| node_keymap
node_keymap -.->|"dispatches bindings"| node_behavior
node_keymap -.->|"checks combos"| node_combos
node_sensors -.->|"triggers bindings"| node_behavior
node_behavior -.->|"produces reports"| node_hid
node_holdtap -.->|"implements behavior"| node_behavior
node_hid -.->|"selects output"| node_endpoints
node_endpoints -.->|"routes reports"| node_usb
node_endpoints -.->|"routes reports"| node_ble
node_splitcentral -.->|"uses service"| node_split
node_splitperipheral -.->|"uses service"| node_split
node_split -.->|"notifies state"| node_host
node_battery -.->|"supplies readings"| node_statusscreen
node_displayruntime -.->|"loads screen"| node_statusscreen
node_displayruntime -.->|"uses display device"| node_il0323
node_statusscreen -->|"initializes widget"| node_outputstatus
node_outputstatus -->|"reads selection"| node_endpoints
node_outputstatus -->|"reads profile state"| node_ble
node_niceview -->|"initializes widget"| node_nicestatus
node_studio -.->|"dispatches RPC"| node_keymapstudio

click node_kscan "https://github.com/zmkfirmware/zmk/blob/main/app/module/drivers/kscan/kscan_gpio_matrix.c"
click node_keymap "https://github.com/zmkfirmware/zmk/blob/main/app/src/keymap.c"
click node_combos "https://github.com/zmkfirmware/zmk/blob/main/app/src/combo.c"
click node_sensors "https://github.com/zmkfirmware/zmk/blob/main/app/src/sensors.c"
click node_behavior "https://github.com/zmkfirmware/zmk/blob/main/app/src/behavior.c"
click node_holdtap "https://github.com/zmkfirmware/zmk/blob/main/app/src/behaviors/behavior_hold_tap.c"
click node_hid "https://github.com/zmkfirmware/zmk/blob/main/app/src/hid.c"
click node_endpoints "https://github.com/zmkfirmware/zmk/blob/main/app/src/endpoints.c"
click node_usb "https://github.com/zmkfirmware/zmk/blob/main/app/src/usb_hid.c"
click node_ble "https://github.com/zmkfirmware/zmk/blob/main/app/src/ble.c"
click node_split "https://github.com/zmkfirmware/zmk/blob/main/app/src/split/bluetooth/service.c"
click node_splitcentral "https://github.com/zmkfirmware/zmk/blob/main/app/src/split/central.c"
click node_splitperipheral "https://github.com/zmkfirmware/zmk/blob/main/app/src/split/peripheral.c"
click node_battery "https://github.com/zmkfirmware/zmk/blob/main/app/module/drivers/sensor/max17048/max17048.c"
click node_displayruntime "https://github.com/zmkfirmware/zmk/blob/main/app/src/display/main.c"
click node_statusscreen "https://github.com/zmkfirmware/zmk/blob/main/app/boards/lowprokb/corneish_zen/custom_status_screen.c"
click node_outputstatus "https://github.com/zmkfirmware/zmk/blob/main/app/boards/lowprokb/corneish_zen/widgets/output_status.c"
click node_niceview "https://github.com/zmkfirmware/zmk/blob/main/app/boards/shields/nice_view/custom_status_screen.c"
click node_nicestatus "https://github.com/zmkfirmware/zmk/blob/main/app/boards/shields/nice_view/widgets/status.c"
click node_il0323 "https://github.com/zmkfirmware/zmk/blob/main/app/module/drivers/display/il0323.c"
click node_studio "https://github.com/zmkfirmware/zmk/blob/main/app/src/studio/rpc.c"
click node_keymapstudio "https://github.com/zmkfirmware/zmk/blob/main/app/src/studio/keymap_subsystem.c"

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_kscan,node_keymap,node_combos,node_sensors,node_user toneBlue
class node_behavior,node_holdtap,node_hid,node_endpoints toneAmber
class node_usb,node_ble,node_split,node_splitcentral,node_splitperipheral toneMint
class node_battery,node_displayruntime,node_statusscreen,node_outputstatus,node_niceview,node_nicestatus,node_il0323 toneRose
class node_studio,node_keymapstudio,node_host toneIndigo
```

## Components

### Input and mapping

- [Matrix scan](https://github.com/zmkfirmware/zmk/blob/main/app/module/drivers/kscan/kscan_gpio_matrix.c): `app/module/drivers/kscan/kscan_gpio_matrix.c`
- [Keymap](https://github.com/zmkfirmware/zmk/blob/main/app/src/keymap.c): `app/src/keymap.c`
- [Combos](https://github.com/zmkfirmware/zmk/blob/main/app/src/combo.c): `app/src/combo.c`
- [Sensor input](https://github.com/zmkfirmware/zmk/blob/main/app/src/sensors.c): `app/src/sensors.c`

### Behavior and HID

- [Behaviors](https://github.com/zmkfirmware/zmk/blob/main/app/src/behavior.c): `app/src/behavior.c`
- [Hold-tap](https://github.com/zmkfirmware/zmk/blob/main/app/src/behaviors/behavior_hold_tap.c): `app/src/behaviors/behavior_hold_tap.c`
- [HID reports](https://github.com/zmkfirmware/zmk/blob/main/app/src/hid.c): `app/src/hid.c`
- [Output selection](https://github.com/zmkfirmware/zmk/blob/main/app/src/endpoints.c): `app/src/endpoints.c`

### Connectivity

- [USB HID](https://github.com/zmkfirmware/zmk/blob/main/app/src/usb_hid.c): `app/src/usb_hid.c`
- [Bluetooth](https://github.com/zmkfirmware/zmk/blob/main/app/src/ble.c): `app/src/ble.c`
- [Split service](https://github.com/zmkfirmware/zmk/blob/main/app/src/split/bluetooth/service.c): `app/src/split/bluetooth/service.c`
- [Split central](https://github.com/zmkfirmware/zmk/blob/main/app/src/split/central.c): `app/src/split/central.c`
- [Split peripheral](https://github.com/zmkfirmware/zmk/blob/main/app/src/split/peripheral.c): `app/src/split/peripheral.c`

### Devices and display

- [Battery gauge](https://github.com/zmkfirmware/zmk/blob/main/app/module/drivers/sensor/max17048/max17048.c): `app/module/drivers/sensor/max17048/max17048.c`
- [Display runtime](https://github.com/zmkfirmware/zmk/blob/main/app/src/display/main.c): `app/src/display/main.c`
- [Corneish Zen screen](https://github.com/zmkfirmware/zmk/blob/main/app/boards/lowprokb/corneish_zen/custom_status_screen.c): `app/boards/lowprokb/corneish_zen/custom_status_screen.c`
- [Output status widget](https://github.com/zmkfirmware/zmk/blob/main/app/boards/lowprokb/corneish_zen/widgets/output_status.c): `app/boards/lowprokb/corneish_zen/widgets/output_status.c`
- [Nice!View screen](https://github.com/zmkfirmware/zmk/blob/main/app/boards/shields/nice_view/custom_status_screen.c): `app/boards/shields/nice_view/custom_status_screen.c`
- [Nice!View status widget](https://github.com/zmkfirmware/zmk/blob/main/app/boards/shields/nice_view/widgets/status.c): `app/boards/shields/nice_view/widgets/status.c`
- [IL0323 display driver](https://github.com/zmkfirmware/zmk/blob/main/app/module/drivers/display/il0323.c): `app/module/drivers/display/il0323.c`

### Studio

- [Studio RPC](https://github.com/zmkfirmware/zmk/blob/main/app/src/studio/rpc.c): `app/src/studio/rpc.c`
- [Studio keymap](https://github.com/zmkfirmware/zmk/blob/main/app/src/studio/keymap_subsystem.c): `app/src/studio/keymap_subsystem.c`

### Other components

- **Keyboard user**
- **HID host**

## Connections

- Keyboard user → Matrix scan: presses keys
- Matrix scan → Keymap: reports positions
- Keymap → Behaviors: dispatches bindings
- Keymap → Combos: checks combos
- Sensor input → Behaviors: triggers bindings
- Behaviors → HID reports: produces reports
- Hold-tap → Behaviors: implements behavior
- HID reports → Output selection: selects output
- Output selection → USB HID: routes reports
- Output selection → Bluetooth: routes reports
- Split central → Split service: uses service
- Split peripheral → Split service: uses service
- Split service → HID host: notifies state
- Battery gauge → Corneish Zen screen: supplies readings
- Display runtime → Corneish Zen screen: loads screen
- Display runtime → IL0323 display driver: uses display device
- Corneish Zen screen → Output status widget: initializes widget (evidence: `app/boards/lowprokb/corneish_zen/custom_status_screen.c`)
- Output status widget → Output selection: reads selection (evidence: `app/boards/lowprokb/corneish_zen/widgets/output_status.c`)
- Output status widget → Bluetooth: reads profile state (evidence: `app/boards/lowprokb/corneish_zen/widgets/output_status.c`)
- Nice!View screen → Nice!View status widget: initializes widget (evidence: `app/boards/shields/nice_view/custom_status_screen.c`)
- Studio RPC → Studio keymap: dispatches RPC
