# yyax13/sparktype architecture

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

- Interactive diagram: https://gitdiagram.com/yyax13/sparktype
- Repository: https://github.com/yyax13/sparktype

## Overview

SparkType is Digispark firmware that presents a clearly identified USB boot-protocol keyboard. Its main setup demonstrates the user-to-result path: firmware invokes the PT-BR keyboard layout to type text and blinks the onboard LED. Separate HID infrastructure tracks host LED replies, reconnects USB, and can infer the host OS. The README documents USB identity and layout extensibility; the legacy PT-BR implementation is retained as a reference. Some USB-stack wiring is documented but its vendor implementation is outside the supplied tree.

Main entry points: [`src/infra/HID/LEDS/main.cpp`](https://github.com/yyax13/sparktype/blob/main/src/infra/HID/LEDS/main.cpp) (Host LED state), [`src/infra/OS/main.cpp`](https://github.com/yyax13/sparktype/blob/main/src/infra/OS/main.cpp) (Host OS detection), [`src/main.cpp`](https://github.com/yyax13/sparktype/blob/main/src/main.cpp) (Demo behavior), [`src/lib/SparkKeyboard/layouts/pt-br/main.cpp`](https://github.com/yyax13/sparktype/blob/main/src/lib/SparkKeyboard/layouts/pt-br/main.cpp) (PT-BR layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Firmware entry"]
  node_board["Digispark firmware<br/>[SparkType.ino]"]
  node_app["Demo behavior<br/>[main.cpp]"]
end

subgraph group_keyboard["Keyboard output"]
  node_ptbr["PT-BR layout<br/>[main.cpp]"]
  node_keyboard_base["Keyboard base<br/>[main.h]"]
  node_legacy["Legacy PT-BR keyboard"]
end

subgraph group_hid["HID infrastructure"]
  node_connection["USB connection control<br/>[main.cpp]"]
  node_leds["Host LED state<br/>[main.cpp]"]
  node_os["Host OS detection<br/>[main.cpp]"]
end

subgraph group_signals["Identity and signals"]
  node_blink["Onboard LED alerts<br/>[main.cpp]"]
  node_config["USB identity config<br/>[config.h]"]
end

node_usb(("USB HID host"))
node_host(("Computer host"))

node_board -->|"calls setup"| node_app
node_app -->|"types text"| node_ptbr
node_app -->|"blinks"| node_blink
node_ptbr -->|"extends"| node_keyboard_base
node_ptbr -->|"sends key reports"| node_usb
node_usb -->|"enumerates as HID"| node_host
node_host -->|"returns LED state"| node_leds
node_os -->|"reads and restores"| node_leds
node_os -->|"reconnects"| node_connection
node_os -->|"signals detection"| node_blink
node_connection -->|"clears LED replies"| node_leds
node_leds -->|"toggles lock keys"| node_usb
node_config -->|"configures identity"| node_usb
node_legacy -.->|"provides keyboard output"| node_usb

click node_board "https://github.com/yyax13/sparktype/blob/main/SparkType.ino"
click node_app "https://github.com/yyax13/sparktype/blob/main/src/main.cpp"
click node_ptbr "https://github.com/yyax13/sparktype/blob/main/src/lib/SparkKeyboard/layouts/pt-br/main.cpp"
click node_keyboard_base "https://github.com/yyax13/sparktype/blob/main/src/lib/SparkKeyboard/main.h"
click node_legacy "https://github.com/yyax13/sparktype/blob/main/src/lib/DigiKeyboardPtBr.cpp"
click node_connection "https://github.com/yyax13/sparktype/blob/main/src/infra/HID/CONNECTION/main.cpp"
click node_leds "https://github.com/yyax13/sparktype/blob/main/src/infra/HID/LEDS/main.cpp"
click node_os "https://github.com/yyax13/sparktype/blob/main/src/infra/OS/main.cpp"
click node_blink "https://github.com/yyax13/sparktype/blob/main/src/shared/utils/blink-alert/main.cpp"
click node_config "https://github.com/yyax13/sparktype/blob/main/src/config.h"

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_board,node_app toneBlue
class node_ptbr,node_keyboard_base,node_legacy toneAmber
class node_connection,node_leds,node_os toneMint
class node_blink,node_config toneRose
class node_usb,node_host toneIndigo
```

## Components

### Firmware entry

- [Digispark firmware](https://github.com/yyax13/sparktype/blob/main/SparkType.ino): `SparkType.ino`
- [Demo behavior](https://github.com/yyax13/sparktype/blob/main/src/main.cpp): `src/main.cpp`

### Keyboard output

- [PT-BR layout](https://github.com/yyax13/sparktype/blob/main/src/lib/SparkKeyboard/layouts/pt-br/main.cpp): `src/lib/SparkKeyboard/layouts/pt-br/main.cpp`
- [Keyboard base](https://github.com/yyax13/sparktype/blob/main/src/lib/SparkKeyboard/main.h): `src/lib/SparkKeyboard/main.h`
- [Legacy PT-BR keyboard](https://github.com/yyax13/sparktype/blob/main/src/lib/DigiKeyboardPtBr.cpp): `src/lib/DigiKeyboardPtBr.cpp`

### HID infrastructure

- [USB connection control](https://github.com/yyax13/sparktype/blob/main/src/infra/HID/CONNECTION/main.cpp): `src/infra/HID/CONNECTION/main.cpp`
- [Host LED state](https://github.com/yyax13/sparktype/blob/main/src/infra/HID/LEDS/main.cpp): `src/infra/HID/LEDS/main.cpp`
- [Host OS detection](https://github.com/yyax13/sparktype/blob/main/src/infra/OS/main.cpp): `src/infra/OS/main.cpp`

### Identity and signals

- [Onboard LED alerts](https://github.com/yyax13/sparktype/blob/main/src/shared/utils/blink-alert/main.cpp): `src/shared/utils/blink-alert/main.cpp`
- [USB identity config](https://github.com/yyax13/sparktype/blob/main/src/config.h): `src/config.h`

### Other components

- **USB HID host**
- **Computer host**

## Connections

- Digispark firmware → Demo behavior: calls setup (evidence: `README.md`)
- Demo behavior → PT-BR layout: types text (evidence: `src/main.cpp`)
- Demo behavior → Onboard LED alerts: blinks (evidence: `src/main.cpp`)
- PT-BR layout → Keyboard base: extends
- PT-BR layout → USB HID host: sends key reports (evidence: `src/lib/SparkKeyboard/layouts/pt-br/main.cpp`)
- USB HID host → Computer host: enumerates as HID (evidence: `README.md`)
- Computer host → Host LED state: returns LED state (evidence: `README.md`)
- Host OS detection → Host LED state: reads and restores (evidence: `src/infra/OS/main.cpp`)
- Host OS detection → USB connection control: reconnects (evidence: `src/infra/OS/main.cpp`)
- Host OS detection → Onboard LED alerts: signals detection (evidence: `src/infra/OS/main.cpp`)
- USB connection control → Host LED state: clears LED replies (evidence: `src/infra/HID/CONNECTION/main.cpp`)
- Host LED state → USB HID host: toggles lock keys (evidence: `src/infra/HID/LEDS/main.cpp`)
- USB identity config → USB HID host: configures identity (evidence: `README.md`)
- Legacy PT-BR keyboard → USB HID host: provides keyboard output
