# theredepic/kinect-wpf architecture

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

- Interactive diagram: https://gitdiagram.com/theredepic/kinect-wpf
- Repository: https://github.com/theredepic/kinect-wpf

## Overview

#### Purpose and Runtime
This is a Windows WPF desktop application that uses Kinect input to control the system cursor. The solution is rooted at `kinect-wpf.slnx`; the application project is `Kinect/Kinect.csproj`. It runs on .NET/WPF and depends on Kinect runtime APIs plus Windows native cursor APIs.

#### Application Entry and UI Shell
WPF startup is declared by `Kinect/App.xaml` and initialized in `Kinect/App.xaml.cs`. The primary UI and likely lifecycle coordinator are `Kinect/MainWindow.xaml` and `Kinect/MainWindow.xaml.cs`. The main window owns presentation concerns while delegating sensor and cursor behavior to services.

#### Kinect Sensor Integration
`Kinect/Services/KinectService.cs` is the hardware-facing boundary. It is responsible for connecting to and managing Kinect sensor state, receiving Kinect interaction/body or pointer events, and exposing sensor-derived input to the application. This isolates Kinect SDK lifecycle and event handling from WPF UI logic.

#### Interaction Interpretation
`Kinect/Services/SimpleInteractionClient.cs` represents the Kinect interaction-client adapter. It supplies Kinect’s interaction subsystem with required callbacks or interaction decisions, enabling raw sensor/body data to be interpreted as hand/pointer interaction rather than direct UI input.

#### Cursor-Control Pipeline
`Kinect/Services/CursorController.cs` converts Kinect-derived interaction coordinates or gestures into desktop cursor actions. It is the boundary between normalized/sensor-space input and OS-level screen coordinates, movement, and clicking behavior. The expected flow is:
Kinect sensor events → interaction client/service → cursor controller → Windows cursor APIs.

#### Native OS Boundary
`Kinect/Helpers/NativeMethods.cs` contains the platform interop boundary for Windows APIs used by cursor control. Keeping P/Invoke declarations here prevents Kinect and UI layers from directly depending on unmanaged function signatures.

#### Key Boundaries and Control Flow
The WPF layer starts and stops the sensor/control pipeline through `Kinect/MainWindow.xaml.cs`. `Kinect/Services/KinectService.cs` owns external Kinect hardware/runtime interaction; `Kinect/Services/CursorController.cs` owns external Windows input interaction. This separation allows UI changes without rewriting sensor handling, and sensor interpretation changes without directly modifying native cursor calls.

Main entry points: [`Kinect/Services/KinectService.cs`](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Services/KinectService.cs) (Kinect service), [`Kinect/Kinect.csproj`](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Kinect.csproj) (Kinect project), [`Kinect/MainWindow.xaml.cs`](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/MainWindow.xaml.cs) (Lifecycle coordinator), [`Kinect/App.xaml`](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/App.xaml) (App startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_wpf["WPF Application"]
  node_project["Kinect project<br/>WPF project<br/>[Kinect.csproj]"]
  node_app_xaml["App startup<br/>WPF markup<br/>[App.xaml]"]
  node_app_code["App initialization<br/>WPF startup<br/>[App.xaml.cs]"]
  node_main_xaml["Main window<br/>WPF view<br/>[MainWindow.xaml]"]
  node_main_window["Lifecycle coordinator<br/>WPF window<br/>[MainWindow.xaml.cs]"]
end

subgraph group_kinect["Kinect Input Pipeline"]
  node_kinect_runtime{{"Kinect runtime<br/>external SDK"}}
  node_kinect_service["Kinect service<br/>sensor service<br/>[KinectService.cs]"]
  node_interaction_client["Interaction client<br/>Kinect adapter"]
end

subgraph group_windows["Windows Integration"]
  node_cursor_controller["Cursor controller<br/>cursor service"]
  node_native_methods["Native methods<br/>P/Invoke boundary<br/>[NativeMethods.cs]"]
  node_windows_cursor{{"Windows cursor APIs<br/>native OS API"}}
end

node_solution["kinect-wpf.slnx<br/>solution<br/>[kinect-wpf.slnx]"]

node_solution -->|"contains"| node_project
node_project -->|"includes"| node_app_xaml
node_app_xaml -->|"initializes"| node_app_code
node_app_code -->|"starts"| node_main_window
node_project -->|"includes"| node_main_xaml
node_main_xaml -->|"defines UI"| node_main_window
node_main_window -->|"starts / stops"| node_kinect_service
node_kinect_service -->|"connects and receives events"| node_kinect_runtime
node_kinect_service -->|"uses for interaction"| node_interaction_client
node_kinect_service -->|"forwards interaction input"| node_cursor_controller
node_cursor_controller -->|"invokes"| node_native_methods
node_native_methods -->|"P/Invoke"| node_windows_cursor

click node_solution "https://github.com/theredepic/kinect-wpf/blob/main/kinect-wpf.slnx"
click node_project "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Kinect.csproj"
click node_app_xaml "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/App.xaml"
click node_app_code "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/App.xaml.cs"
click node_main_xaml "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/MainWindow.xaml"
click node_main_window "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/MainWindow.xaml.cs"
click node_kinect_service "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Services/KinectService.cs"
click node_interaction_client "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Services/SimpleInteractionClient.cs"
click node_cursor_controller "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Services/CursorController.cs"
click node_native_methods "https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Helpers/NativeMethods.cs"

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_project,node_app_xaml,node_app_code,node_main_xaml,node_main_window toneBlue
class node_kinect_runtime,node_kinect_service,node_interaction_client toneAmber
class node_cursor_controller,node_native_methods,node_windows_cursor toneMint
class node_solution toneNeutral
```

## Components

### WPF Application

- [Kinect project](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Kinect.csproj): WPF project · `Kinect/Kinect.csproj`
- [App startup](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/App.xaml): WPF markup · `Kinect/App.xaml`
- [App initialization](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/App.xaml.cs): WPF startup · `Kinect/App.xaml.cs`
- [Main window](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/MainWindow.xaml): WPF view · `Kinect/MainWindow.xaml`
- [Lifecycle coordinator](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/MainWindow.xaml.cs): WPF window · Starts and stops the sensor and cursor pipeline. · `Kinect/MainWindow.xaml.cs`

### Kinect Input Pipeline

- **Kinect runtime**: external SDK · Hardware sensor and interaction APIs.
- [Kinect service](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Services/KinectService.cs): sensor service · Owns sensor lifecycle and publishes sensor-derived interaction input. · `Kinect/Services/KinectService.cs`
- [Interaction client](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Services/SimpleInteractionClient.cs): Kinect adapter · Provides interaction callbacks and decisions to the Kinect subsystem. · `Kinect/Services/SimpleInteractionClient.cs`

### Windows Integration

- [Cursor controller](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Services/CursorController.cs): cursor service · Maps interaction coordinates and gestures to desktop cursor actions. · `Kinect/Services/CursorController.cs`
- [Native methods](https://github.com/theredepic/kinect-wpf/blob/main/Kinect/Helpers/NativeMethods.cs): P/Invoke boundary · Declares Windows cursor API interop. · `Kinect/Helpers/NativeMethods.cs`
- **Windows cursor APIs**: native OS API

### Other components

- [kinect-wpf.slnx](https://github.com/theredepic/kinect-wpf/blob/main/kinect-wpf.slnx): solution · Solution root. · `kinect-wpf.slnx`

## Connections

- kinect-wpf.slnx → Kinect project: contains
- Kinect project → App startup: includes
- App startup → App initialization: initializes
- App initialization → Lifecycle coordinator: starts
- Kinect project → Main window: includes
- Main window → Lifecycle coordinator: defines UI
- Lifecycle coordinator → Kinect service: starts / stops
- Kinect service → Kinect runtime: connects and receives events
- Kinect service → Interaction client: uses for interaction
- Kinect service → Cursor controller: forwards interaction input
- Cursor controller → Native methods: invokes
- Native methods → Windows cursor APIs: P/Invoke
