# itanmayi/open-gestures architecture

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

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

## Overview

1. This repository is a webcam-driven gesture control runtime. The top-level flow is: capture video frames, run MediaPipe gesture recognition asynchronously, match the latest recognition result against a set of gesture rules, then execute a mapped system action.

2. `main.py` is the orchestrator. It owns the camera loop, configures the MediaPipe recognizer, feeds frames into `recognize_async()`, receives results through a callback, and passes the most recent result to the router. It also draws the on-screen overlay and opens the OpenCV display window.

3. There is an explicit threading boundary between MediaPipe and the main loop. MediaPipe runs recognition in live-stream mode on an internal thread, and the callback writes the latest `GestureRecognizerResult` into a shared slot guarded by a `threading.Lock`. The main loop consumes that slot on each frame, which keeps rendering and input capture responsive.

4. `core/` contains the central control logic:
   - `core/router.py` decides which gesture module matches the current result and which action should fire.
   - `core/cooldown.py` prevents repeated firing from a held pose or slow-changing gesture.
   - `core/config.py` appears to centralize runtime configuration and/or loading of stored bindings from `data/config.json`.

5. The gesture layer is modular and data-driven. `gestures/static/` contains one Python module per gesture pose, with files named like `thumb_up_1.py` and `thumb_up_2.py`. The naming suggests `_2` variants represent two-hand gestures and are treated with higher priority than `_1` single-hand variants, matching the README’s two-hand-first rule.

6. Each gesture module is a small rule object rather than a standalone feature. The contract described in the README is: export a unique `GESTURE_NAME` and a `matches(result)` function. That means gesture detection is separated from execution; modules only decide whether the current MediaPipe result satisfies their pose or temporal pattern.

7. The action layer is also modular, with a clear boundary between “what was recognized” and “what should happen.” `actions/base.py` and `actions/system.py` suggest a shared action abstraction, while feature-specific actions live under subpackages:
   - `actions/media/` for playback and volume control
   - `actions/util/` for brightness, screenshots, zoom, and window management
   - `actions/app/` for launching apps, browser, files
   - `actions/linux/`, `actions/mac/`, and `actions/win/` for OS-specific commands

8. The OS-specific folders are important architectural boundaries. They indicate that the repo aims to support Linux, macOS, and Windows with the same gesture-to-action pipeline, while the final execution step is delegated to platform-tailored action modules. This keeps recognition portable and pushes OS dependency to the edges.

9. `data/config.json` is the persistence layer for user-facing bindings and/or preferences. Based on the README, the UI lets users switch actions and reset defaults, so this file likely stores the current gesture-to-action mapping that the router reads at startup.

10. `models/` holds the MediaPipe model assets used at runtime. `gesture_recognizer.task` is the primary recognition model referenced in the README, and `hand_landmarker.task` is also present as a model artifact. These files are external ML dependencies rather than application code, so they form the ML inference boundary of the system.

11. The repository also includes a `.wip/swipe_tracker.py`, which looks like an experimental or unfinished gesture-tracking component. It is separate from the main runtime path and should be treated as non-production or in-progress logic.

12. For an architecture diagram, the key runtime path is: webcam/OpenCV input → MediaPipe recognizer callback → thread-safe latest-result buffer → gesture router with cooldown checks → action modules → OS/system effects, with config and bindings loaded from `data/config.json` and overlay/UI rendered back through OpenCV.

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

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["main.py<br/>orchestrator<br/>[main.py]"]
  node_cv_loop(("Camera loop<br/>opencv loop<br/>[main.py]"))
  node_mp_async(("MediaPipe async<br/>gesture inference<br/>[main.py]"))
  node_result_slot[("Latest result<br/>shared buffer<br/>[main.py]")]
  node_overlay_ui["Overlay UI<br/>rendering<br/>[main.py]"]
end

subgraph group_core["Core"]
  node_router["router.py<br/>gesture router<br/>[router.py]"]
  node_cooldown["cooldown.py<br/>rate limit<br/>[cooldown.py]"]
  node_config["config.py<br/>runtime config<br/>[config.py]"]
end

subgraph group_gestures["Gestures"]
  node_gesture_rules["Static rules<br/>gesture modules"]
  node_thumb_up_1["thumb_up_1<br/>single-hand rule<br/>[thumb_up_1.py]"]
  node_thumb_up_2["thumb_up_2<br/>two-hand rule<br/>[thumb_up_2.py]"]
  node_victory_1["victory_1<br/>single-hand rule<br/>[victory_1.py]"]
  node_victory_2["victory_2<br/>two-hand rule<br/>[victory_2.py]"]
end

subgraph group_actions["Actions"]
  node_action_base["base.py<br/>action contract<br/>[base.py]"]
  node_system_actions["system.py<br/>action bridge<br/>[system.py]"]
  node_media_actions["Media actions<br/>media control"]
  node_util_actions["Utility actions<br/>desktop tools"]
  node_app_actions["App actions<br/>app launch"]
  node_linux_actions["Linux<br/>os adapter"]
  node_mac_actions["macOS<br/>os adapter"]
  node_win_actions["Windows<br/>os adapter"]
end

subgraph group_assets["Assets"]
  node_config_data[("config.json<br/>bindings store<br/>[config.json]")]
  node_gesture_model{{"gesture_recognizer.task<br/>ml model"}}
  node_hand_model{{"hand_landmarker.task<br/>ml model"}}
end

subgraph group_experimental["Experimental"]
  node_swipe_tracker["swipe_tracker.py<br/>wip tracker<br/>[swipe_tracker.py]"]
end

node_main -->|"captures frames"| node_cv_loop
node_main -->|"feeds frames"| node_mp_async
node_mp_async -->|"callback writes"| node_result_slot
node_cv_loop -->|"reads latest"| node_result_slot
node_main -->|"renders"| node_overlay_ui
node_result_slot -->|"dispatches"| node_router
node_config -->|"loads bindings"| node_router
node_config_data -->|"persists"| node_config
node_router -->|"checks repeats"| node_cooldown
node_router -->|"matches rules"| node_gesture_rules
node_gesture_rules -->|"contains"| node_thumb_up_1
node_gesture_rules -->|"contains"| node_thumb_up_2
node_gesture_rules -->|"contains"| node_victory_1
node_gesture_rules -->|"contains"| node_victory_2
node_router -->|"selects"| node_action_base
node_action_base -->|"executes via"| node_system_actions
node_system_actions -->|"routes"| node_media_actions
node_system_actions -->|"routes"| node_util_actions
node_system_actions -->|"routes"| node_app_actions
node_system_actions -->|"adapts"| node_linux_actions
node_system_actions -->|"adapts"| node_mac_actions
node_system_actions -->|"adapts"| node_win_actions
node_main -->|"uses model"| node_gesture_model
node_main -->|"uses model"| node_hand_model
node_swipe_tracker -.->|"experimental path"| node_gesture_rules

click node_main "https://github.com/itanmayi/open-gestures/blob/main/main.py"
click node_cv_loop "https://github.com/itanmayi/open-gestures/blob/main/main.py"
click node_mp_async "https://github.com/itanmayi/open-gestures/blob/main/main.py"
click node_result_slot "https://github.com/itanmayi/open-gestures/blob/main/main.py"
click node_overlay_ui "https://github.com/itanmayi/open-gestures/blob/main/main.py"
click node_router "https://github.com/itanmayi/open-gestures/blob/main/core/router.py"
click node_cooldown "https://github.com/itanmayi/open-gestures/blob/main/core/cooldown.py"
click node_config "https://github.com/itanmayi/open-gestures/blob/main/core/config.py"
click node_gesture_rules "https://github.com/itanmayi/open-gestures/tree/main/gestures/static"
click node_thumb_up_1 "https://github.com/itanmayi/open-gestures/blob/main/gestures/static/thumb_up_1.py"
click node_thumb_up_2 "https://github.com/itanmayi/open-gestures/blob/main/gestures/static/thumb_up_2.py"
click node_victory_1 "https://github.com/itanmayi/open-gestures/blob/main/gestures/static/victory_1.py"
click node_victory_2 "https://github.com/itanmayi/open-gestures/blob/main/gestures/static/victory_2.py"
click node_action_base "https://github.com/itanmayi/open-gestures/blob/main/actions/base.py"
click node_system_actions "https://github.com/itanmayi/open-gestures/blob/main/actions/system.py"
click node_media_actions "https://github.com/itanmayi/open-gestures/tree/main/actions/media"
click node_util_actions "https://github.com/itanmayi/open-gestures/tree/main/actions/util"
click node_app_actions "https://github.com/itanmayi/open-gestures/tree/main/actions/app"
click node_linux_actions "https://github.com/itanmayi/open-gestures/tree/main/actions/linux"
click node_mac_actions "https://github.com/itanmayi/open-gestures/tree/main/actions/mac"
click node_win_actions "https://github.com/itanmayi/open-gestures/tree/main/actions/win"
click node_config_data "https://github.com/itanmayi/open-gestures/blob/main/data/config.json"
click node_gesture_model "https://github.com/itanmayi/open-gestures/blob/main/models/gesture_recognizer.task"
click node_hand_model "https://github.com/itanmayi/open-gestures/blob/main/models/hand_landmarker.task"
click node_swipe_tracker "https://github.com/itanmayi/open-gestures/blob/main/.wip/swipe_tracker.py"

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,node_cv_loop,node_mp_async,node_result_slot,node_overlay_ui toneBlue
class node_router,node_cooldown,node_config toneAmber
class node_gesture_rules,node_thumb_up_1,node_thumb_up_2,node_victory_1,node_victory_2 toneMint
class node_action_base,node_system_actions,node_media_actions,node_util_actions,node_app_actions,node_linux_actions,node_mac_actions,node_win_actions toneRose
class node_config_data,node_gesture_model,node_hand_model toneIndigo
class node_swipe_tracker toneTeal
```

## Components

### Runtime

Live webcam loop and inference thread boundary

- [main.py](https://github.com/itanmayi/open-gestures/blob/main/main.py): orchestrator · Owns camera loop, async recognition, result buffering, routing, and overlay rendering · `main.py`
- [Camera loop](https://github.com/itanmayi/open-gestures/blob/main/main.py): opencv loop · Captures webcam frames and presents the UI window · `main.py`
- [MediaPipe async](https://github.com/itanmayi/open-gestures/blob/main/main.py): gesture inference · Runs live-stream gesture recognition on MediaPipe's internal thread · `main.py`
- [Latest result](https://github.com/itanmayi/open-gestures/blob/main/main.py): shared buffer · Thread-safe handoff slot guarded by a lock for the newest recognizer result · `main.py`
- [Overlay UI](https://github.com/itanmayi/open-gestures/blob/main/main.py): rendering · Draws on-screen feedback over the camera feed · `main.py`

### Core

Configuration, routing, and cooldown control

- [router.py](https://github.com/itanmayi/open-gestures/blob/main/core/router.py): gesture router · Matches recognized gestures to configured actions · `core/router.py`
- [cooldown.py](https://github.com/itanmayi/open-gestures/blob/main/core/cooldown.py): rate limit · Prevents repeated firing from held or slowly changing gestures · `core/cooldown.py`
- [config.py](https://github.com/itanmayi/open-gestures/blob/main/core/config.py): runtime config · Loads bindings and runtime settings, including data/config.json · `core/config.py`

### Gestures

Gesture rule modules and priority variants

- [Static rules](https://github.com/itanmayi/open-gestures/tree/main/gestures/static): gesture modules · Data-driven gesture pose modules under gestures/static/ · `gestures/static`
- [thumb_up_1](https://github.com/itanmayi/open-gestures/blob/main/gestures/static/thumb_up_1.py): single-hand rule · Representative static gesture module · `gestures/static/thumb_up_1.py`
- [thumb_up_2](https://github.com/itanmayi/open-gestures/blob/main/gestures/static/thumb_up_2.py): two-hand rule · Higher-priority two-hand variant of the thumb-up gesture · `gestures/static/thumb_up_2.py`
- [victory_1](https://github.com/itanmayi/open-gestures/blob/main/gestures/static/victory_1.py): single-hand rule · Representative static gesture module · `gestures/static/victory_1.py`
- [victory_2](https://github.com/itanmayi/open-gestures/blob/main/gestures/static/victory_2.py): two-hand rule · Higher-priority two-hand variant of the victory gesture · `gestures/static/victory_2.py`

### Actions

Action abstractions and platform-specific effects

- [base.py](https://github.com/itanmayi/open-gestures/blob/main/actions/base.py): action contract · Shared action abstraction used by the execution layer · `actions/base.py`
- [system.py](https://github.com/itanmayi/open-gestures/blob/main/actions/system.py): action bridge · System-facing action entrypoints and shared execution helpers · `actions/system.py`
- [Media actions](https://github.com/itanmayi/open-gestures/tree/main/actions/media): media control · Play, pause, mute, and volume-related actions · `actions/media`
- [Utility actions](https://github.com/itanmayi/open-gestures/tree/main/actions/util): desktop tools · Brightness, screenshots, zoom, and window management · `actions/util`
- [App actions](https://github.com/itanmayi/open-gestures/tree/main/actions/app): app launch · Launches browser, files, and custom apps · `actions/app`
- [Linux](https://github.com/itanmayi/open-gestures/tree/main/actions/linux): os adapter · Linux-specific command execution · `actions/linux`
- [macOS](https://github.com/itanmayi/open-gestures/tree/main/actions/mac): os adapter · macOS-specific command execution · `actions/mac`
- [Windows](https://github.com/itanmayi/open-gestures/tree/main/actions/win): os adapter · Windows-specific command execution · `actions/win`

### Assets

Runtime data and model artifacts

- [config.json](https://github.com/itanmayi/open-gestures/blob/main/data/config.json): bindings store · Persisted gesture-to-action bindings and preferences · `data/config.json`
- [gesture_recognizer.task](https://github.com/itanmayi/open-gestures/blob/main/models/gesture_recognizer.task): ml model · Primary MediaPipe gesture recognition model · `models/gesture_recognizer.task`
- [hand_landmarker.task](https://github.com/itanmayi/open-gestures/blob/main/models/hand_landmarker.task): ml model · Hand landmark model used by the inference stack · `models/hand_landmarker.task`

### Experimental

Work-in-progress gesture tracking

- [swipe_tracker.py](https://github.com/itanmayi/open-gestures/blob/main/.wip/swipe_tracker.py): wip tracker · Experimental or unfinished gesture-tracking logic · `.wip/swipe_tracker.py`

## Connections

- main.py → Camera loop: captures frames · The main runtime owns webcam input and the display loop
- main.py → MediaPipe async: feeds frames · Frames are submitted to MediaPipe in live-stream mode
- MediaPipe async → Latest result: callback writes · The recognizer callback stores the newest result under a lock
- Camera loop → Latest result: reads latest · The render loop consumes the most recent recognition result each frame
- main.py → Overlay UI: renders · Camera output is decorated with recognition feedback
- Latest result → router.py: dispatches · Latest recognition result is evaluated by the router
- config.py → router.py: loads bindings · Routing decisions are driven by configured gesture-action mappings
- config.json → config.py: persists · Stored preferences and bindings are loaded at startup
- router.py → cooldown.py: checks repeats · Cooldown prevents retriggering from held poses
- router.py → Static rules: matches rules · Router evaluates the active gesture modules
- Static rules → thumb_up_1: contains · Representative single-hand static rule
- Static rules → thumb_up_2: contains · Representative two-hand static rule
- Static rules → victory_1: contains · Representative single-hand static rule
- Static rules → victory_2: contains · Representative two-hand static rule
- router.py → base.py: selects · Matched gestures are resolved to a concrete action abstraction
- base.py → system.py: executes via · Common action contract delegates to system-facing execution
- system.py → Media actions: routes · Media-control behavior is implemented in a dedicated module set
- system.py → Utility actions: routes · Desktop utility behavior is implemented in a dedicated module set
- system.py → App actions: routes · Application-launch behavior is implemented in a dedicated module set
- system.py → Linux: adapts · Linux-specific commands live at the platform edge
- system.py → macOS: adapts · macOS-specific commands live at the platform edge
- system.py → Windows: adapts · Windows-specific commands live at the platform edge
- main.py → gesture_recognizer.task: uses model · The runtime loads the gesture recognizer task asset
- main.py → hand_landmarker.task: uses model · The runtime also depends on the hand landmark model asset
- swipe_tracker.py → Static rules: experimental path · Work-in-progress tracking is separate from the main runtime flow
