# godkode69/open-gestures architecture

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

- Interactive diagram: https://gitdiagram.com/godkode69/open-gestures
- Repository: https://github.com/godkode69/open-gestures

## Overview

1. **Composition root: `main.py`**
   - `main.py` is the runtime entry point and the place where the whole system is wired together.
   - It opens the webcam, configures MediaPipe’s `GestureRecognizer`, runs the frame loop, receives recognition results, calls the router, and draws the on-screen overlay/window.

2. **Camera + inference pipeline**
   - The system reads frames from OpenCV (`cv2.VideoCapture`), converts them for MediaPipe, and sends them to the recognizer in `LIVE_STREAM` mode.
   - MediaPipe runs recognition asynchronously and returns results through a callback, so the main loop and the ML callback are separated by a thread-safe handoff.

3. **Thread boundary / result handoff**
   - Recognition results arrive on a MediaPipe callback thread.
   - A lock in the core layer is used to safely transfer the latest `GestureRecognizerResult` to the main loop, which then consumes the most recent result when deciding what action to fire.

4. **Gesture definition layer: `gestures/`**
   - Gesture logic is split into many small modules under `gestures/static/` and `gestures/motion/`.
   - Static gestures represent single-frame hand poses; motion gestures represent temporal or directional movement.
   - Files ending in `_2` are treated as two-hand gestures and are prioritized above `_1` single-hand gestures.

5. **Dynamic gesture discovery**
   - Gestures are not hard-coded into the router.
   - They are discovered and imported dynamically at runtime, which makes the gesture catalog extensible without editing the main pipeline.
   - Each gesture module exposes a name and a `matches(result)` predicate so the router can test it against the latest MediaPipe output.

6. **Routing and priority: `core/router.py`**
   - The router is the decision layer that maps recognized gestures to actions.
   - It evaluates gesture modules in priority order, so more specific or two-hand gestures can preempt simpler ones.
   - This is the main control boundary between perception and actuation.

7. **Temporal state: `core/cooldown.py` and `core/swipe_tracker.py`**
   - `Cooldown` prevents repeated firing from a held pose or slowly changing gesture by gating each gesture name for a period of time.
   - `swipe_tracker.py` likely maintains frame-to-frame state for motion gestures, allowing swipe-style recognition to span multiple frames instead of relying on a single snapshot.

8. **Action layer: `actions/`**
   - Actions are modular and grouped by concern and platform:
     - `actions/media/` for playback and volume control
     - `actions/util/` for brightness, screenshots, zoom, window management
     - `actions/app/` for launching apps or files
     - `actions/linux/`, `actions/mac/`, `actions/win/` for OS-specific launch/search behavior
   - These modules are the system’s side-effect boundary: they translate a recognized gesture into a real desktop action.

9. **OS-specific boundaries**
   - The repo is cross-platform at the architecture level, but some actions are explicitly platform-bound.
   - For example, there are Linux terminal and macOS Spotlight modules, plus Windows Start Menu support.
   - This means the gesture pipeline is shared, while the final action execution path diverges by operating system.

10. **Configuration and user bindings: `core/config.py` and `data/config.json`**
   - `data/config.json` is the persistent configuration store.
   - It likely holds gesture-to-action assignments, defaults, and user-customized bindings, since the README mentions switching actions and resetting them to default.
   - `core/config.py` is the code boundary that loads, interprets, and updates that persisted state.

11. **Model assets: `models/`**
   - The ML assets are shipped separately from code:
     - `gesture_recognizer.task` for gesture classification
     - `hand_landmarker.task` for landmark detection
   - These are the runtime ML dependencies used by MediaPipe Tasks, and they define the inference capabilities of the app.

12. **Runtime output**
   - The application displays an OpenCV window with gesture labels and the last fired action, plus preview/overlay feedback.
   - That UI is not a separate frontend; it is part of the main camera loop and serves as the operator feedback layer for the gesture control system.

13. **Overall data flow**
   - Webcam frame → OpenCV preprocessing → MediaPipe asynchronous recognition → thread-safe latest result → gesture router → cooldown check → action module execution → OS-level effect.
   - The key architectural boundaries are perception, gesture classification, routing/state, and platform action execution.

14. **Key architectural style**
   - This repo is a modular desktop control system built around plug-in-like gesture and action modules.
   - The central design goal is extensibility: new gestures or actions can be added by dropping in a module, while the main loop and router remain largely unchanged.

Main entry points: [`actions/system.py`](https://github.com/godkode69/open-gestures/blob/main/actions/system.py) (System Actions), [`main.py`](https://github.com/godkode69/open-gestures/blob/main/main.py) (main.py), [`core/router.py`](https://github.com/godkode69/open-gestures/blob/main/core/router.py) (Router), [`gestures/static`](https://github.com/godkode69/open-gestures/tree/main/gestures/static) (Static Gestures)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["main.py<br/>entrypoint<br/>[main.py]"]
end

subgraph group_core["Core"]
  node_core_config["Config<br/>settings store<br/>[config.py]"]
  node_core_router["Router<br/>decision layer<br/>[router.py]"]
  node_core_cooldown["Cooldown<br/>rate gate<br/>[cooldown.py]"]
  node_core_swipe["Swipe Tracker<br/>motion state<br/>[swipe_tracker.py]"]
end

subgraph group_gestures["Gestures"]
  node_gest_static["Static Gestures<br/>gesture modules"]
  node_gest_motion["Motion Gestures<br/>gesture modules"]
end

subgraph group_actions["Actions"]
  node_act_base["Action Base<br/>action interface<br/>[base.py]"]
  node_act_system["System Actions<br/>desktop effects<br/>[system.py]"]
  node_act_media["Media<br/>actions"]
  node_act_util["Utilities<br/>actions"]
  node_act_app["Apps<br/>actions"]
  node_act_linux["Linux<br/>platform actions"]
  node_act_mac["macOS<br/>platform actions"]
  node_act_win["Windows<br/>platform actions"]
end

subgraph group_assets["Assets"]
  node_model_gesture[("Gesture Model<br/>ML asset")]
  node_model_hand[("Hand Model<br/>ML asset")]
end

node_main -->|"load bindings"| node_core_config
node_main -->|"route results"| node_core_router
node_main -->|"use model"| node_model_gesture
node_main -->|"use model"| node_model_hand
node_main -.->|"discover"| node_gest_static
node_main -.->|"discover"| node_gest_motion
node_core_router -->|"gate repeat"| node_core_cooldown
node_core_router -->|"track motion"| node_core_swipe
node_core_router -->|"match"| node_gest_static
node_core_router -->|"match"| node_gest_motion
node_core_router -->|"dispatch"| node_act_system
node_act_system -->|"implement"| node_act_base
node_act_system -->|"media"| node_act_media
node_act_system -->|"utility"| node_act_util
node_act_system -->|"app launch"| node_act_app
node_act_system -->|"linux"| node_act_linux
node_act_system -->|"macOS"| node_act_mac
node_act_system -->|"windows"| node_act_win

click node_main "https://github.com/godkode69/open-gestures/blob/main/main.py"
click node_core_config "https://github.com/godkode69/open-gestures/blob/main/core/config.py"
click node_core_router "https://github.com/godkode69/open-gestures/blob/main/core/router.py"
click node_core_cooldown "https://github.com/godkode69/open-gestures/blob/main/core/cooldown.py"
click node_core_swipe "https://github.com/godkode69/open-gestures/blob/main/core/swipe_tracker.py"
click node_gest_static "https://github.com/godkode69/open-gestures/tree/main/gestures/static"
click node_gest_motion "https://github.com/godkode69/open-gestures/tree/main/gestures/motion"
click node_act_base "https://github.com/godkode69/open-gestures/blob/main/actions/base.py"
click node_act_system "https://github.com/godkode69/open-gestures/blob/main/actions/system.py"
click node_act_media "https://github.com/godkode69/open-gestures/tree/main/actions/media"
click node_act_util "https://github.com/godkode69/open-gestures/tree/main/actions/util"
click node_act_app "https://github.com/godkode69/open-gestures/tree/main/actions/app"
click node_act_linux "https://github.com/godkode69/open-gestures/tree/main/actions/linux"
click node_act_mac "https://github.com/godkode69/open-gestures/tree/main/actions/mac"
click node_act_win "https://github.com/godkode69/open-gestures/tree/main/actions/win"
click node_model_gesture "https://github.com/godkode69/open-gestures/blob/main/models/gesture_recognizer.task"
click node_model_hand "https://github.com/godkode69/open-gestures/blob/main/models/hand_landmarker.task"

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 toneBlue
class node_core_config,node_core_router,node_core_cooldown,node_core_swipe toneAmber
class node_gest_static,node_gest_motion toneMint
class node_act_base,node_act_system,node_act_media,node_act_util,node_act_app,node_act_linux,node_act_mac,node_act_win toneRose
class node_model_gesture,node_model_hand toneIndigo
```

## Components

### Runtime

Entry point and frame loop

- [main.py](https://github.com/godkode69/open-gestures/blob/main/main.py): entrypoint · Wires camera, recognizer, router, and overlay loop · `main.py`

### Core

Routing, cooldown, config, and gesture state

- [Config](https://github.com/godkode69/open-gestures/blob/main/core/config.py): settings store · Loads and persists gesture/action bindings · `core/config.py`
- [Router](https://github.com/godkode69/open-gestures/blob/main/core/router.py): decision layer · Matches recognized gestures to actions by priority · `core/router.py`
- [Cooldown](https://github.com/godkode69/open-gestures/blob/main/core/cooldown.py): rate gate · Prevents repeated firing of the same gesture · `core/cooldown.py`
- [Swipe Tracker](https://github.com/godkode69/open-gestures/blob/main/core/swipe_tracker.py): motion state · Maintains frame-to-frame state for swipe gestures · `core/swipe_tracker.py`

### Gestures

Static and motion gesture modules

- [Static Gestures](https://github.com/godkode69/open-gestures/tree/main/gestures/static): gesture modules · Single-frame hand pose recognizers · `gestures/static`
- [Motion Gestures](https://github.com/godkode69/open-gestures/tree/main/gestures/motion): gesture modules · Temporal and directional gesture recognizers · `gestures/motion`

### Actions

User-facing and OS-specific side effects

- [Action Base](https://github.com/godkode69/open-gestures/blob/main/actions/base.py): action interface · Shared action abstractions and execution contracts · `actions/base.py`
- [System Actions](https://github.com/godkode69/open-gestures/blob/main/actions/system.py): desktop effects · Top-level system action dispatch and integration · `actions/system.py`
- [Media](https://github.com/godkode69/open-gestures/tree/main/actions/media): actions · Playback and volume control actions · `actions/media`
- [Utilities](https://github.com/godkode69/open-gestures/tree/main/actions/util): actions · Brightness, screenshots, zoom, and windows · `actions/util`
- [Apps](https://github.com/godkode69/open-gestures/tree/main/actions/app): actions · Launches apps, files, and browsers · `actions/app`
- [Linux](https://github.com/godkode69/open-gestures/tree/main/actions/linux): platform actions · Linux-specific terminal or launch behavior · `actions/linux`
- [macOS](https://github.com/godkode69/open-gestures/tree/main/actions/mac): platform actions · macOS-specific search and launch behavior · `actions/mac`
- [Windows](https://github.com/godkode69/open-gestures/tree/main/actions/win): platform actions · Windows Start Menu integration · `actions/win`

### Assets

ML models shipped with the app

- [Gesture Model](https://github.com/godkode69/open-gestures/blob/main/models/gesture_recognizer.task): ML asset · MediaPipe gesture recognizer task model · `models/gesture_recognizer.task`
- [Hand Model](https://github.com/godkode69/open-gestures/blob/main/models/hand_landmarker.task): ML asset · MediaPipe hand landmark detector model · `models/hand_landmarker.task`

## Connections

- main.py → Config: load bindings · Reads persistent gesture/action configuration
- main.py → Router: route results · Sends latest recognition result into decision layer
- main.py → Gesture Model: use model · Runs gesture recognition with the shipped task model
- main.py → Hand Model: use model · Uses hand landmarks for inference support
- main.py → Static Gestures: discover · Loads static gesture modules dynamically
- main.py → Motion Gestures: discover · Loads motion gesture modules dynamically
- Router → Cooldown: gate repeat · Applies cooldown before firing an action
- Router → Swipe Tracker: track motion · Consumes frame-to-frame swipe state
- Router → Static Gestures: match · Evaluates static gesture predicates
- Router → Motion Gestures: match · Evaluates motion gesture predicates
- Router → System Actions: dispatch · Triggers the selected action path
- System Actions → Action Base: implement · Builds on shared action abstractions
- System Actions → Media: media · Handles playback and volume actions
- System Actions → Utilities: utility · Handles desktop utility actions
- System Actions → Apps: app launch · Handles app, file, and browser launching
- System Actions → Linux: linux · Delegates Linux-specific actions
- System Actions → macOS: macOS · Delegates macOS-specific actions
- System Actions → Windows: windows · Delegates Windows-specific actions
