# ironpateli/gesture-controlled-desktop-assistant- architecture

> Architecture diagram of the GitHub repository ironpateli/gesture-controlled-desktop-assistant-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ironpateli/gesture-controlled-desktop-assistant-
- Repository: https://github.com/ironpateli/gesture-controlled-desktop-assistant-

## Overview

#### Purpose and Entry Points
Gesture Assistant is a Windows desktop utility that turns webcam hand gestures into configurable OS/media actions. The normal entry point is the persistent system-tray process in `tray.py`; it owns recognition lifecycle, preview visibility, configuration access, startup integration, and clean shutdown. Direct development entry points are `main.py` for the camera/inference engine and `config_gui.py` for settings.

Grounding: `tray.py`, `main.py`, `config_gui.py`.

#### Tray Process and Windows Lifecycle
The tray layer starts idle to minimize resource use, enforces a single instance through a named Windows mutex, and exposes start/stop recognition, preview, configuration, startup, and exit controls. It communicates state to the user through Windows notifications. Windows-specific startup shortcuts and registry integration are separated from the recognition engine.

Grounding: `tray.py`, `windows_integration.py`, `setup_shortcuts.py`.

#### Live Recognition Pipeline
When enabled, the camera engine lazily loads OpenCV/MediaPipe, captures webcam frames, extracts MediaPipe’s 21 hand landmarks, and accumulates normalized 20-frame sequences. Pose coordinates are wrist-relative and scale-normalized; handedness is normalized by mirroring left-hand poses, while wrist movement remains available for motion classification. Preview rendering is optional and recognition continues without it.

Grounding: `main.py`, `runtime_model.py`, `gesture_model_runtime.npz`.

#### Model Inference and Rejection Boundary
The packaged runtime deliberately avoids PyTorch: `main.py` loads the exported NumPy parameter archive and runs the one-layer LSTM implemented in `runtime_model.py`. Predictions are rejected when classified as `none` or below the confidence threshold, forming the boundary between noisy visual inference and OS side effects. The runtime artifact is bundled read-only with the application; user-writable data belongs under `%LOCALAPPDATA%\GestureAssistant`.

Grounding: `main.py`, `runtime_model.py`, `gesture_model_runtime.npz`.

#### Action Gating and Dispatch
Recognized gestures pass through a monotonic-clock timing gate before dispatch. `action_timing.py` applies action-category cooldowns, release-to-rearm behavior for one-shot static gestures, and longer protection for app/script launches; this makes behavior independent of camera FPS. `actions.py` then reloads gesture mappings during operation, blocks disabled gestures, and executes built-in controls, keyboard shortcuts, executables, URIs, or scripts.

Grounding: `action_timing.py`, `actions.py`, `main.py`.

#### User Configuration and Application Discovery
The Tkinter configuration editor manages gesture enablement and mappings stored in a user configuration file. Configuration is intentionally live-read so edits do not require restarting recognition. Application-oriented selection/discovery is isolated from the editor and execution layers, including Start Menu discovery and caching.

Grounding: `config_gui.py`, `actions.py`, `app_discovery.py`.

#### Training-to-Runtime Delivery Pipeline
Development data collection records labeled 20×21×3 landmark sequences. Training uses a PyTorch LSTM checkpoint, then exports weights to the NumPy runtime archive and validates inference parity. This separates heavyweight ML tooling from the distributed runtime. Legacy detector/model assets under `archive/phase1` are retained only as historical artifacts and are not part of active execution.

Grounding: `collect_data.py`, `train_classifier.py`, `export_runtime_model.py`.

#### Packaging and Infrastructure
The target runtime is Windows 10/11 with a webcam, Python during development, and bundled dependencies for end users. PyInstaller packaging creates the executable distribution; Inno Setup creates a per-user installer. Build scripts package the runtime model and application assets while excluding training-only dependencies such as PyTorch from deployment.

Grounding: `build_app.ps1`, `build_installer.ps1`, `installer/GestureAssistant.iss`.

Main entry points: [`tray.py`](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/tray.py) (Tray process), [`main.py`](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/main.py) (Camera & recognition), [`gesture_model_runtime.npz`](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/gesture_model_runtime.npz) (Runtime model archive), [`config_gui.py`](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/config_gui.py) (Settings editor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop Runtime"]
  node_tray["Tray process<br/>Python entry point<br/>[tray.py]"]
  node_windows["Windows integration<br/>Windows lifecycle"]
  node_shortcuts["Shortcut setup<br/>Windows setup<br/>[setup_shortcuts.py]"]
  node_engine["Camera &amp; recognition<br/>Python entry point<br/>[main.py]"]
  node_runtime["NumPy LSTM runtime<br/>inference runtime<br/>[runtime_model.py]"]
  node_model["Runtime model archive<br/>NumPy model artifact"]
  node_timing["Action timing gate<br/>gesture gate<br/>[action_timing.py]"]
  node_actions["Action dispatcher<br/>OS action execution<br/>[actions.py]"]
end

subgraph group_config["Configuration"]
  node_settings["Settings editor<br/>Tkinter entry point<br/>[config_gui.py]"]
  node_appdiscovery["Application discovery<br/>application catalog<br/>[app_discovery.py]"]
  node_userconfig["User configuration<br/>user data"]
end

subgraph group_ml["Model Delivery"]
  node_collection["Landmark collection<br/>training data collection<br/>[collect_data.py]"]
  node_training["PyTorch training<br/>model training"]
  node_export["Runtime model export<br/>model conversion"]
end

subgraph group_distribution["Packaging"]
  node_appbuild["PyInstaller build<br/>application packaging<br/>[build_app.ps1]"]
  node_installerbuild["Installer build<br/>installer packaging"]
  node_installer["Inno Setup installer<br/>installer definition"]
  node_windowsruntime{{"Windows 10/11 + webcam<br/>target platform"}}
end

node_tray -->|"uses"| node_windows
node_tray -->|"manages startup"| node_shortcuts
node_tray -->|"starts / stops"| node_engine
node_engine -->|"runs inference"| node_runtime
node_runtime -->|"loads parameters"| node_model
node_engine -->|"accepted gestures"| node_timing
node_timing -->|"gated actions"| node_actions
node_settings -->|"writes"| node_userconfig
node_actions -->|"live reads"| node_userconfig
node_settings -->|"selects applications"| node_appdiscovery
node_collection -->|"training sequences"| node_training
node_training -->|"PyTorch checkpoint"| node_export
node_export -->|"exports"| node_model
node_appbuild -->|"bundles"| node_model
node_appbuild -->|"produces app payload"| node_installerbuild
node_installerbuild -->|"uses definition"| node_installer
node_installer -->|"installs on"| node_windowsruntime

click node_tray "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/tray.py"
click node_windows "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/windows_integration.py"
click node_shortcuts "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/setup_shortcuts.py"
click node_engine "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/main.py"
click node_runtime "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/runtime_model.py"
click node_model "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/gesture_model_runtime.npz"
click node_timing "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/action_timing.py"
click node_actions "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/actions.py"
click node_settings "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/config_gui.py"
click node_appdiscovery "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/app_discovery.py"
click node_collection "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/collect_data.py"
click node_training "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/train_classifier.py"
click node_export "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/export_runtime_model.py"
click node_appbuild "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/build_app.ps1"
click node_installerbuild "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/build_installer.ps1"
click node_installer "https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/installer/GestureAssistant.iss"

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_tray,node_windows,node_shortcuts,node_engine,node_runtime,node_model,node_timing,node_actions toneBlue
class node_settings,node_appdiscovery,node_userconfig toneAmber
class node_collection,node_training,node_export toneMint
class node_appbuild,node_installerbuild,node_installer,node_windowsruntime toneRose
```

## Components

### Desktop Runtime

Persistent Windows utility and live gesture path.

- [Tray process](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/tray.py): Python entry point · Owns recognition lifecycle, preview, startup, and shutdown. · `tray.py`
- [Windows integration](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/windows_integration.py): Windows lifecycle · Provides mutex, notifications, startup shortcuts, and registry integration. · `windows_integration.py`
- [Shortcut setup](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/setup_shortcuts.py): Windows setup · `setup_shortcuts.py`
- [Camera & recognition](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/main.py): Python entry point · Captures frames, extracts landmarks, and runs optional preview. · `main.py`
- [NumPy LSTM runtime](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/runtime_model.py): inference runtime · Runs exported one-layer LSTM inference without PyTorch. · `runtime_model.py`
- [Runtime model archive](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/gesture_model_runtime.npz): NumPy model artifact · Bundled read-only model parameters. · `gesture_model_runtime.npz`
- [Action timing gate](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/action_timing.py): gesture gate · Applies cooldowns and release-to-rearm before side effects. · `action_timing.py`
- [Action dispatcher](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/actions.py): OS action execution · Live-reloads mappings and executes enabled gesture actions. · `actions.py`

### Configuration

User-editable mappings and application selection.

- [Settings editor](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/config_gui.py): Tkinter entry point · Edits gesture enablement and mappings. · `config_gui.py`
- [Application discovery](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/app_discovery.py): application catalog · Discovers and caches Start Menu applications. · `app_discovery.py`
- **User configuration**: user data · Stored under %LOCALAPPDATA%\GestureAssistant.

### Model Delivery

Development training exports the lightweight runtime model.

- [Landmark collection](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/collect_data.py): training data collection · Records labeled 20×21×3 landmark sequences. · `collect_data.py`
- [PyTorch training](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/train_classifier.py): model training · Trains the development LSTM checkpoint. · `train_classifier.py`
- [Runtime model export](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/export_runtime_model.py): model conversion · Exports NumPy weights and validates inference parity. · `export_runtime_model.py`

### Packaging

Windows executable and installer delivery.

- [PyInstaller build](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/build_app.ps1): application packaging · Bundles runtime dependencies and application assets. · `build_app.ps1`
- [Installer build](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/build_installer.ps1): installer packaging · Builds the per-user Windows installer. · `build_installer.ps1`
- [Inno Setup installer](https://github.com/ironpateli/gesture-controlled-desktop-assistant-/blob/main/installer/GestureAssistant.iss): installer definition · `installer/GestureAssistant.iss`
- **Windows 10/11 + webcam**: target platform

## Connections

- Tray process → Windows integration: uses
- Tray process → Shortcut setup: manages startup
- Tray process → Camera & recognition: starts / stops
- Camera & recognition → NumPy LSTM runtime: runs inference
- NumPy LSTM runtime → Runtime model archive: loads parameters
- Camera & recognition → Action timing gate: accepted gestures · Rejects none and low-confidence predictions first.
- Action timing gate → Action dispatcher: gated actions
- Settings editor → User configuration: writes
- Action dispatcher → User configuration: live reads
- Settings editor → Application discovery: selects applications
- Landmark collection → PyTorch training: training sequences
- PyTorch training → Runtime model export: PyTorch checkpoint
- Runtime model export → Runtime model archive: exports
- PyInstaller build → Runtime model archive: bundles
- PyInstaller build → Installer build: produces app payload
- Installer build → Inno Setup installer: uses definition
- Inno Setup installer → Windows 10/11 + webcam: installs on
