# hammadzaigham/preysense architecture

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

- Interactive diagram: https://gitdiagram.com/hammadzaigham/preysense
- Repository: https://github.com/hammadzaigham/preysense

## Overview

1. **Project shape**
   - PreySense is a single Windows desktop app built with **.NET 10 / WinForms**.
   - The executable is the main user-facing control panel; there is no separate backend service in this repo.

2. **Top-level orchestration**
   - `Program.cs` launches the WinForms app.
   - `MainForm` is the central shell and is split by concern into `Core`, `Startup`, `Refresh`, `Power`, `Battery`, `Rgb`, `Layout`, and the designer file.
   - This form coordinates all hardware actions, UI refreshes, mode switching, and device state polling.

3. **Hardware control boundary**
   - The app’s core purpose is to bypass Acer Predator Sense and talk directly to hardware/vendor interfaces.
   - The main integration points are:
     - **Acer WMI / AcerService** for laptop-specific controls
     - **NVIDIA NVML / wrapper code** for GPU metrics and control
     - **PawnIO / MSR access** for CPU power-limit and low-level tuning
     - **Windows input hooks** for hotkeys and physical key integration

4. **Performance mode subsystem**
   - `Mode/` contains the logic for user-selectable performance profiles.
   - `ProfileManager`, `PerformanceProfile`, `PowerLimitController`, and `FanCurveStorage` manage per-mode settings such as power limits, fan curves, and GPU offsets.
   - This subsystem is the main state model for the app and feeds both UI and hardware actions.

5. **Fan and thermal control**
   - `Fan/` implements custom fan-curve UI and logic.
   - Fan settings are likely persisted per profile and applied through Acer-specific control paths.
   - The fan subsystem is tightly coupled to performance modes and the on-screen overlay.

6. **GPU control and mode switching**
   - `Gpu/` handles NVIDIA-related operations, including clock offsets and GPU mode switching.
   - `NvidiaWrapper`, `NvmlHelper`, and `NvidiaGpuControl` form a small abstraction over NVIDIA APIs.
   - GPU mode choices map to laptop platform modes such as iGPU-only, hybrid, or dGPU-exclusive operation.

7. **Battery, power, and display controls**
   - `Battery/` manages charge limits.
   - `MainForm.Power` and related helpers manage platform power settings and display behavior.
   - `Helpers/Display/` includes display management and RGB profile support, suggesting refresh-rate switching and color-profile coordination are first-class features.

8. **RGB lighting subsystem**
   - `Rgb/` and `Color/` provide keyboard lighting controls and color configuration UI.
   - `Helpers/Hardware/AcerServiceClient` and documentation under `docs/acer_service_rgb.md` indicate RGB control is done through Acer service protocol interactions, not generic Windows lighting APIs.

9. **Input and automation**
   - `Input/` handles global keyboard hooks and Predator-key-related shortcuts.
   - `KeyboardHook`, `WmiHotkeyWatcher`, and `QuickAccessModeWatcher` allow the app to react to physical laptop controls and trigger mode changes without needing the main window focused.

10. **Overlay / HUD subsystem**
   - `Overlay/` implements a custom hardware telemetry HUD.
   - It combines real-time metrics from ETW, process/memory helpers, and native drawing/windowing to show FPS, temperatures, power, fan RPM, and usage graphs.
   - This is a separate presentation surface from the main control UI, but it shares hardware state with the core app.

11. **UI architecture**
   - `UI/Controls/` contains a large custom control library themed for the app.
   - `RForm`, `MetricsSettingsForm`, and related controls suggest a strongly branded, custom-drawn WinForms UI rather than standard system widgets.
   - The UI layer is primarily a presentation boundary over the hardware/mode subsystems.

12. **Persistence and configuration**
   - User settings, profiles, fan curves, and app state are stored in the registry under `HKCU\SOFTWARE\PreySense`.
   - The app also appears to maintain model-specific or feature-specific state in helper classes rather than a separate database or config service.

13. **Platform assumptions and operational boundary**
   - The app is explicitly **Windows-only** and intended for **Acer Predator** hardware with compatible WMI/service interfaces.
   - Some capabilities require extra system components: **admin rights**, the **PawnIO driver**, and Acer service components for RGB or low-level control.

14. **Support files and release tooling**
   - `docs/` contains reverse-engineering notes, BIOS/service scripts, and backup service packages used for compatibility work.
   - `.github/workflows/release.yml` and `publish.ps1` indicate automated packaging/release support, but they are not part of runtime architecture.

Main entry points: [`app/MainForm/MainForm.cs`](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.cs) (Main Form), [`app/Helpers/Hardware/AcerServiceClient.cs`](https://github.com/hammadzaigham/preysense/blob/main/app/Helpers/Hardware/AcerServiceClient.cs) (Hardware APIs), [`app/Mode/ProfileManager.cs`](https://github.com/hammadzaigham/preysense/blob/main/app/Mode/ProfileManager.cs) (Profiles), [`app/MainForm/MainForm.Core.cs`](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Core.cs) (Core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_app["App shell"]
  node_program["Program<br/>entrypoint<br/>[Program.cs]"]
  node_mainform["Main Form<br/>shell<br/>[MainForm.cs]"]
  node_mainform_core["Core<br/>orchestration<br/>[MainForm.Core.cs]"]
  node_mainform_startup["Startup<br/>init"]
  node_mainform_refresh["Refresh<br/>polling"]
  node_mainform_power["Power<br/>[MainForm.Power.cs]"]
  node_mainform_battery["Battery"]
  node_mainform_rgb["RGB<br/>[MainForm.Rgb.cs]"]
end

subgraph group_g_hw["Hardware integration"]
  node_hardware["Hardware APIs<br/>vendor boundary"]
  node_display["Display Helpers<br/>display/rgb<br/>[DisplayManager.cs]"]
  node_pawn["PawnIO<br/>msr access<br/>[PawnIOWrapper.cs]"]
end

subgraph group_g_features["Control planes"]
  node_mode[("Profiles<br/>state model<br/>[ProfileManager.cs]")]
  node_fan["Fans<br/>thermal ui<br/>[Fans.cs]"]
  node_gpu["GPU<br/>nvidia control"]
  node_battery["Battery Control<br/>charge limit<br/>[BatteryControl.cs]"]
  node_rgb["RGB Form<br/>lighting ui<br/>[RgbForm.cs]"]
  node_input["Input<br/>hotkeys<br/>[KeyboardHook.cs]"]
end

subgraph group_g_ui["Presentation"]
  node_overlay["Overlay<br/>hud<br/>[HardwareOverlay.cs]"]
  node_ui_controls["UI Kit<br/>custom controls<br/>[UiKit.cs]"]
end

node_program -->|"launches"| node_mainform
node_mainform -->|"starts"| node_mainform_startup
node_mainform -->|"coordinates"| node_mainform_core
node_mainform -->|"polls"| node_mainform_refresh
node_mainform -->|"controls"| node_mainform_power
node_mainform -->|"controls"| node_mainform_battery
node_mainform -->|"controls"| node_mainform_rgb
node_mainform_core -->|"uses"| node_mode
node_mainform_core -->|"invokes"| node_hardware
node_mode -->|"feeds"| node_fan
node_mode -->|"feeds"| node_gpu
node_mode -->|"applies via"| node_pawn
node_fan -->|"writes"| node_hardware
node_gpu -->|"uses"| node_hardware
node_battery -->|"uses"| node_hardware
node_rgb -->|"uses"| node_hardware
node_input -->|"triggers"| node_mainform_core
node_overlay -->|"reads"| node_mode
node_overlay -->|"monitors"| node_hardware
node_overlay -->|"coordinates"| node_display
node_ui_controls -->|"composes"| node_mainform
node_mainform_power -->|"uses"| node_display
node_mainform_rgb -->|"uses"| node_display

click node_program "https://github.com/hammadzaigham/preysense/blob/main/app/Program.cs"
click node_mainform "https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.cs"
click node_mainform_core "https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Core.cs"
click node_mainform_startup "https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Startup.cs"
click node_mainform_refresh "https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Refresh.cs"
click node_mainform_power "https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Power.cs"
click node_mainform_battery "https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Battery.cs"
click node_mainform_rgb "https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Rgb.cs"
click node_mode "https://github.com/hammadzaigham/preysense/blob/main/app/Mode/ProfileManager.cs"
click node_fan "https://github.com/hammadzaigham/preysense/blob/main/app/Fan/Fans.cs"
click node_gpu "https://github.com/hammadzaigham/preysense/blob/main/app/Gpu/NvidiaGpuControl.cs"
click node_battery "https://github.com/hammadzaigham/preysense/blob/main/app/Battery/BatteryControl.cs"
click node_rgb "https://github.com/hammadzaigham/preysense/blob/main/app/Rgb/RgbForm.cs"
click node_input "https://github.com/hammadzaigham/preysense/blob/main/app/Input/KeyboardHook.cs"
click node_overlay "https://github.com/hammadzaigham/preysense/blob/main/app/Overlay/HardwareOverlay.cs"
click node_ui_controls "https://github.com/hammadzaigham/preysense/blob/main/app/UI/Controls/UiKit.cs"
click node_hardware "https://github.com/hammadzaigham/preysense/blob/main/app/Helpers/Hardware/AcerServiceClient.cs"
click node_display "https://github.com/hammadzaigham/preysense/blob/main/app/Helpers/Display/DisplayManager.cs"
click node_pawn "https://github.com/hammadzaigham/preysense/blob/main/app/Pawn/PawnIOWrapper.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_program,node_mainform,node_mainform_core,node_mainform_startup,node_mainform_refresh,node_mainform_power,node_mainform_battery,node_mainform_rgb toneBlue
class node_hardware,node_display,node_pawn toneAmber
class node_mode,node_fan,node_gpu,node_battery,node_rgb,node_input toneMint
class node_overlay,node_ui_controls toneRose
```

## Components

### App shell

WinForms entrypoint and main window orchestration

- [Program](https://github.com/hammadzaigham/preysense/blob/main/app/Program.cs): entrypoint · Starts the WinForms application · `app/Program.cs`
- [Main Form](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.cs): shell · Central app window coordinating startup, refresh, layout, power, battery, and RGB · `app/MainForm/MainForm.cs`
- [Core](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Core.cs): orchestration · MainForm core coordination logic · `app/MainForm/MainForm.Core.cs`
- [Startup](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Startup.cs): init · MainForm startup and initialization flow · `app/MainForm/MainForm.Startup.cs`
- [Refresh](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Refresh.cs): polling · MainForm UI and device refresh cycle · `app/MainForm/MainForm.Refresh.cs`
- [Power](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Power.cs): power-control · MainForm power and display behavior controls · `app/MainForm/MainForm.Power.cs`
- [Battery](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Battery.cs): battery-control · MainForm battery and charge-limit controls · `app/MainForm/MainForm.Battery.cs`
- [RGB](https://github.com/hammadzaigham/preysense/blob/main/app/MainForm/MainForm.Rgb.cs): rgb-control · MainForm RGB integration and mode coordination · `app/MainForm/MainForm.Rgb.cs`

### Hardware integration

Direct vendor and low-level system interfaces

- [Hardware APIs](https://github.com/hammadzaigham/preysense/blob/main/app/Helpers/Hardware/AcerServiceClient.cs): vendor boundary · Acer WMI/service, NVIDIA NVML, and PawnIO/MSR adapters · `app/Helpers/Hardware/AcerServiceClient.cs`
- [Display Helpers](https://github.com/hammadzaigham/preysense/blob/main/app/Helpers/Display/DisplayManager.cs): display/rgb · Display management and RGB profile support · `app/Helpers/Display/DisplayManager.cs`
- [PawnIO](https://github.com/hammadzaigham/preysense/blob/main/app/Pawn/PawnIOWrapper.cs): msr access · Low-level MSR and PawnIO wrapper layer · `app/Pawn/PawnIOWrapper.cs`

### Control planes

User-facing subsystems that manage modes, power, fans, GPU, battery, RGB, and input

- [Profiles](https://github.com/hammadzaigham/preysense/blob/main/app/Mode/ProfileManager.cs): state model · Performance profile state and per-mode settings · `app/Mode/ProfileManager.cs`
- [Fans](https://github.com/hammadzaigham/preysense/blob/main/app/Fan/Fans.cs): thermal ui · Fan curve UI and fan tuning logic · `app/Fan/Fans.cs`
- [GPU](https://github.com/hammadzaigham/preysense/blob/main/app/Gpu/NvidiaGpuControl.cs): nvidia control · NVIDIA control and GPU mode switching · `app/Gpu/NvidiaGpuControl.cs`
- [Battery Control](https://github.com/hammadzaigham/preysense/blob/main/app/Battery/BatteryControl.cs): charge limit · Battery charge-limit feature boundary · `app/Battery/BatteryControl.cs`
- [RGB Form](https://github.com/hammadzaigham/preysense/blob/main/app/Rgb/RgbForm.cs): lighting ui · Keyboard lighting control surface · `app/Rgb/RgbForm.cs`
- [Input](https://github.com/hammadzaigham/preysense/blob/main/app/Input/KeyboardHook.cs): hotkeys · Global hooks and laptop key watchers · `app/Input/KeyboardHook.cs`

### Presentation

Custom WinForms UI and overlay surfaces

- [Overlay](https://github.com/hammadzaigham/preysense/blob/main/app/Overlay/HardwareOverlay.cs): hud · Telemetry HUD and OSD presentation · `app/Overlay/HardwareOverlay.cs`
- [UI Kit](https://github.com/hammadzaigham/preysense/blob/main/app/UI/Controls/UiKit.cs): custom controls · Reusable themed WinForms controls · `app/UI/Controls/UiKit.cs`

## Connections

- Program → Main Form: launches · Application entry creates the main window
- Main Form → Startup: starts · Startup initializes hardware and UI state
- Main Form → Core: coordinates · Core shell owns feature wiring
- Main Form → Refresh: polls · Refresh loop updates UI and device state
- Main Form → Power: controls · Power-related actions flow through the main form
- Main Form → Battery: controls · Battery controls are surfaced from the main shell
- Main Form → RGB: controls · RGB actions are routed through the main shell
- Core → Profiles: uses · Main orchestration reads and applies performance profiles
- Core → Hardware APIs: invokes · Core actions call vendor and low-level hardware interfaces
- Profiles → Fans: feeds · Profiles include fan-curve settings
- Profiles → GPU: feeds · Profiles include GPU mode and offset settings
- Profiles → PawnIO: applies via · Power limits and tuning values are applied through MSR access
- Fans → Hardware APIs: writes · Fan settings are pushed through Acer-specific control paths
- GPU → Hardware APIs: uses · GPU operations rely on NVIDIA wrapper and NVML access
- Battery Control → Hardware APIs: uses · Charge-limit control uses vendor/system interfaces
- RGB Form → Hardware APIs: uses · Lighting control uses Acer service protocol
- Input → Core: triggers · Hotkeys and key watchers switch modes or update state
- Overlay → Profiles: reads · HUD reflects current performance profile state
- Overlay → Hardware APIs: monitors · Overlay displays real-time telemetry from hardware sources
- Overlay → Display Helpers: coordinates · Overlay presentation shares display and profile helpers
- UI Kit → Main Form: composes · Custom controls build the main WinForms shell
- Power → Display Helpers: uses · Power and refresh behavior coordinate with display management
- RGB → Display Helpers: uses · RGB workflow coordinates with display/profile helpers
