# nikola-ver/video-recording architecture

> Architecture diagram of the GitHub repository nikola-ver/video-recording, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nikola-ver/video-recording
- Repository: https://github.com/nikola-ver/video-recording

## Overview

##### Project Type and Purpose
- This is a native Windows desktop application written in C++/Win32 (Visual Studio solution) for recording screen regions to GIFs.
- It uses OS‑level hotkeys, a custom UI overlay for zone selection, and delegates GIF encoding to the external ImageMagick CLI tool. Installer and autorun scripts (VBScript) simplify deployment.

##### Main Components
a. UI Layer
- Hotkey Manager: registers “Shift+Win+C”, “F2”, “Win+Esc”, “Shift+Win+O/V” via Win32 RegisterHotKey.
- Selection Overlay: full‑screen transparent window for mouse‐drag to select recording area.
b. Recording Engine
- Frame Capturer: uses BitBlt/GDI to grab the selected rectangle on each timer tick.
- Buffer Manager: holds raw bitmaps or writes temporary BMP files.
- Session Controller: start/stop logic driven by hotkeys.
c. Configuration Module
- Reads/writes options.dat to persist user settings.
d. External GIF Encoder
- Invokes ImageMagick’s “convert” (via shell command) to compress captured frames into an animated GIF.
e. Persistence & File System
- Manages output directory (“GIF” folder), temporary files, and final storage.
f. Deployment Scripts
- Setup.vbs: launches installer and ensures ImageMagick is installed.
- Autorun.vbs: places shortcut in user’s Startup folder for automatic launch.

##### Relationships & Data Flows
- UI Layer → Session Controller: “startRecording()” / “stopRecording()” signals
- Session Controller → Frame Capturer: on each timer tick, capture screen region → Buffer Manager
- After stop: Buffer Manager → External GIF Encoder (shell out) → writes GIF to disk
- Configuration Module ↔ Options Dialog: read/write user settings
- Deployment Scripts → OS Startup Folder & ImageMagick installation

##### Architectural Patterns & Principles
- Layered Design: clear separation between UI, core recording engine, and external service wrapper.
- Single Responsibility: each module (capture, config, encoding) handles a distinct concern.
- OS‑Integration Adapter: thin layer encapsulating Win32 APIs (hotkeys, GDI, file I/O).
- External Dependency Isolation: all calls to ImageMagick go through a single “ConvertLauncher” component.

##### Detailed Steps
– UI Layer (Hotkey Manager, Selection Overlay, Options Dialog)
– Recording Engine (Frame Capturer, Buffer Manager, Session Controller)
– Config Module (options.dat)
– GIF Encoder Adapter
– ImageMagick CLI (as external service)
– OS/Win32 APIs (hotkey registry, GDI, file I/O)
– File System (GIF output folder)
– Deployment Scripts (Setup.vbs, Autorun.vbs)
d. Connect:
– UI → Engine (control commands)
– Engine → OS/GDI (capture calls)
– Engine → Buffer Manager → GIF Encoder
– GIF Encoder → ImageMagick → File System
– UI ↔ Config Module (read/write settings)
– Deployment Scripts → OS Startup & Installer UI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main Application Container
    subgraph "Video-Recording App"
        direction TB
        %% UI Layer
        subgraph "UI Layer"
            direction TB
            HK["Hotkey Manager"]:::internal
            SO["Selection Overlay"]:::internal
            OD["Options Dialog"]:::internal
        end
        %% Recording Engine
        subgraph "Recording Engine"
            direction TB
            SCtrl["Session Controller"]:::internal
            FC["Frame Capturer"]:::internal
            BM["Buffer Manager"]:::internal
        end
        CM["Config Module\n(options.dat)"]:::internal
        GEA["GIF Encoder Adapter"]:::internal
        VS["VS Solution & Projects"]:::internal
        subgraph "Resources"
            direction TB
            Cursors["Cursors Directory"]:::internal
            Img["background.bmp"]:::internal
        end
    end

    %% External Services and OS
    IMG["ImageMagick CLI"]:::external
    OS["Win32 APIs\n(Hotkeys, GDI, File I/O)"]:::os
    FS["File System\n(GIF Folder & temp files)"]:::os

    %% Deployment Scripts
    Setup["Setup.vbs"]:::deploy
    Autorun["Autorun.vbs"]:::deploy

    %% Flows and Relationships
    HK -->|"startRecording()/stopRecording()"| SCtrl
    SO -->|"selectRegion()"| SCtrl
    OD -->|"load/save settings"| CM
    CM -->|"persist options.dat"| OD

    SCtrl -->|"onTimerTick()"| FC
    FC -->|"captureRectangle → bitmap"| BM
    BM -->|"frames buffer"| GEA
    GEA -->|"exec convert.exe"| IMG
    IMG -->|"writes .gif"| FS

    SCtrl -->|"RegisterHotKey, timers"| OS
    FC -->|"BitBlt/GDI calls"| OS
    GEA -->|"shell & FS I/O"| OS

    Setup -->|"install & ensure ImageMagick"| OS
    Autorun -->|"create startup shortcut"| OS

    %% Solution link (optional reference)
    VS -->|opens project| HK

    %% Click Events
    click HK "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording/windowFunctions.cpp"
    click SO "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording/windowFunctions.cpp"
    click OD "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording/options.cpp"
    click CM "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording/options.dat"
    click SCtrl "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording/Video-recording.cpp"
    click FC "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording/framework.h"
    click GEA "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording/Video-recording.cpp"
    click Cursors "https://github.com/nikola-ver/video-recording/tree/main/src/Video-recording/cursors/"
    click Img "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording/img/background.bmp"
    click Setup "https://github.com/nikola-ver/video-recording/blob/main/installation/Setup.vbs"
    click Autorun "https://github.com/nikola-ver/video-recording/blob/main/installation/Video-recording.vbs"
    click IMG "https://github.com/nikola-ver/video-recording/blob/main/installation/ImageMagick.exe"
    click VS "https://github.com/nikola-ver/video-recording/blob/main/src/Video-recording.sln"

    %% Legend
    subgraph Legend
        direction TB
        I["Internal Modules"]:::internal
        E["External Service"]:::external
        O["OS Integration"]:::os
        D["Deployment Scripts"]:::deploy
    end

    classDef internal fill:#cdfac4,stroke:#2d8f3c,color:#000
    classDef external fill:#a0c4ff,stroke:#0057c2,color:#000
    classDef os fill:#e0e0e0,stroke:#888,color:#000
    classDef deploy fill:#ffd6a5,stroke:#ff8c00,color:#000
```
