# robertwhurst/keyboardjs architecture

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

- Interactive diagram: https://gitdiagram.com/robertwhurst/keyboardjs
- Repository: https://github.com/robertwhurst/keyboardjs

## Overview

##### Project type and purpose
- This is an open-source, browser-compatible JavaScript library (also Node.js-compatible) for setting up keyboard bindings, key combinations, contexts, and managing key events. It is not a full-stack application but rather a client-side toolkit distributed via NPM and UMD.

##### File structure
- Top-level source lives in `lib/`:
- lib/keyboard.js   – core module that exposes the public API for binding, context, pause/resume, etc.
- lib/key-combo.js – interprets and matches multi-key combos and sequences.
- lib/locale.js   – maps key codes to names based on locale.
- Locales: `locales/us.js` (default US mapping).
- Build & distribution:
- rollup.config.js – bundling into UMD/CJS/ES.
- dist/keyboard.js – compiled distributable.
- Configuration and metadata:
- package.json, bower.json
- .github/, .travis.yml, tests under `test/`
- Tests reference fixtures for mocking `window`/`document`.

##### README for insights
- Describes core features: binding, key combos, contexts, locale support, preventRepeat, pause/resume, programmatic key press/release, watch/stop.
- No higher-level components beyond keyboard event handling.

##### Elements
- From Browser Events → Watcher → Combo Engine → Callbacks in App.
- From App → Public API → Context Manager / Binder.
- From Source Modules → Rollup → Dist.
- Blue for runtime modules
- Green for build/distribution
- Orange for external systems (browser, app)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    ExternalApp["Developer Application"]:::external
    Browser["Browser Event System"]:::external

    %% Runtime Modules
    subgraph "Runtime Modules"
        API["Public API<br/>(keyboard.js)"]:::runtime
        Ctx["Context Manager"]:::runtime
        Combo["Key Combo Engine<br/>(key-combo.js)"]:::runtime
        Locale["Locale Resolver<br/>(locale.js)"]:::runtime
        DefaultLocale["Default US Locale<br/>(us.js)"]:::runtime
        Watcher["Event Watcher"]:::runtime
    end

    %% Build & Distribution
    subgraph "Build & Distribution"
        Rollup["Rollup Bundler<br/>(rollup.config.js)"]:::build
        Dist["Dist Output<br/>(dist/keyboard.js)"]:::build
        MetaPackage["package.json"]:::build
        MetaBower["bower.json"]:::build
        Index["index.js"]:::build
    end

    %% Tests & CI
    subgraph "Tests & CI"
        Tests["Test Suite<br/>(test/)"]:::test
        FixturesSub["Test Fixtures"]:::test
        WindowFix["window.js"]:::test
        DocumentFix["document.js"]:::test
        CI_GH["GitHub Actions<br/>(unit-tests.yml)"]:::test
        CI_Travis["Travis CI<br/>(.travis.yml)"]:::test
    end

    %% Connections - Runtime
    ExternalApp -->|"calls bind/unbind"| API
    API -->|"manages context"| Ctx
    Ctx -->|"checks combos"| Combo
    Combo -->|"invokes callbacks"| ExternalApp
    Browser -->|"keydown/keyup"| Watcher
    Watcher -->|"feeds events"| Combo
    Combo -->|"uses resolver"| Locale
    Locale -->|"maps codes"| DefaultLocale

    %% Connections - Build
    API & Combo & Locale & DefaultLocale --> Rollup
    Rollup --> Dist
    MetaPackage & MetaBower & Index --> Dist

    %% Connections - Tests & CI
    Tests --> API & Combo & Locale
    FixturesSub --> WindowFix & DocumentFix
    Watcher -->|tested with fixtures| FixturesSub
    CI_GH & CI_Travis --> Tests

    %% Click Events
    click API "https://github.com/robertwhurst/keyboardjs/blob/master/lib/keyboard.js"
    click Combo "https://github.com/robertwhurst/keyboardjs/blob/master/lib/key-combo.js"
    click Locale "https://github.com/robertwhurst/keyboardjs/blob/master/lib/locale.js"
    click DefaultLocale "https://github.com/robertwhurst/keyboardjs/blob/master/locales/us.js"
    click Rollup "https://github.com/robertwhurst/keyboardjs/blob/master/rollup.config.js"
    click Dist "https://github.com/robertwhurst/keyboardjs/blob/master/dist/keyboard.js"
    click MetaPackage "https://github.com/robertwhurst/keyboardjs/blob/master/package.json"
    click MetaBower "https://github.com/robertwhurst/keyboardjs/blob/master/bower.json"
    click Index "https://github.com/robertwhurst/keyboardjs/blob/master/index.js"
    click Tests "https://github.com/robertwhurst/keyboardjs/tree/master/test/"
    click WindowFix "https://github.com/robertwhurst/keyboardjs/blob/master/test/fixtures/window.js"
    click DocumentFix "https://github.com/robertwhurst/keyboardjs/blob/master/test/fixtures/document.js"
    click CI_GH "https://github.com/robertwhurst/keyboardjs/blob/master/.github/workflows/unit-tests.yml"
    click CI_Travis "https://github.com/robertwhurst/keyboardjs/blob/master/.travis.yml"

    %% Styles
    classDef external fill:#fdd,stroke:#a33,stroke-width:1px
    classDef runtime fill:#ccf,stroke:#55a,stroke-width:1px
    classDef build fill:#cfc,stroke:#5a5,stroke-width:1px
    classDef test fill:#fcf,stroke:#a5a,stroke-width:1px
```
