# thejoefin/text-grab architecture

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

- Interactive diagram: https://gitdiagram.com/thejoefin/text-grab
- Repository: https://github.com/thejoefin/text-grab

## Overview

##### Project type and purpose
- Text Grab is a Windows desktop OCR utility built with WPF and UWP packaging.
- Purpose: capture text from anywhere on screen (full-screen, framed region) or files/folders, process it via Windows.Media.Ocr, and expose it for copying, editing, quick lookup, or command-line use.

##### File structure
- Top-level solution:
- Text-Grab.sln
- Projects:
– Text-Grab (WPF application)
– Text-Grab-Package (UWP/MSIX packaging project)
– Tests (unit tests covering OCR, file IO, language, QR, screen layouts, string methods)
- Text-Grab project subfolders reveal layers:
- Views & Controls (UI windows, custom controls, pages)
- Services (HistoryService, SettingsService)
- Utilities (Clipboard, File, OCR, HotKey, Image, Registry, Notification, etc.)
- Models (domain objects like OcrOutput, HistoryInfo, WebSearchUrlModel)
- NativeMethods & OSInterop (P/Invoke wrappers)
- UndoRedoOperations (command pattern for undo/redo)
- Extensions (helper methods extending core types)
- Styles & Images (UI theming)
- Properties (app settings)
- Configuration & build: App.config, app.manifest, build-x64.ps1, .csproj files, .gitignore, GitHub workflows.

##### README for additional insights
- Four modes: Full-Screen, Grab Frame, Edit Text Window, Quick Simple Lookup
- Command-line interface (mode arguments and file/folder OCR)
- Uses Windows 10+ OCR API, ZXing.Net for QR/barcode, WPFUI for Fluent styling, CliWrap, CommunityToolkit
- Does not run in background by default; can use global hotkeys if background process enabled.

a. Main components:
- UI Layer (WPF): Views, Pages, Controls
- Application Core / Service Layer:
- OCRService (wraps Windows.Media.Ocr)
- HistoryService, SettingsService
- CommandLineProcessor
- UndoRedoManager
- Utility Layer: ClipboardUtilities, FileUtilities, ImageMethods, HotKeyManager, RegistryMonitor, NotificationUtilities, etc.
- Data Models & Domain Objects
- Native Interop Layer: NativeMethods, OSInterop
- Packaging Layer: Text-Grab-Package (UWP / MSIX)
- External Dependencies: Windows.Media.Ocr API, ZXing.Net, WPF UI library, CliWrap, CommunityToolkit
- Persistence: AppSettings (Properties/Settings), History store (local file or settings storage)

b. Relationships & interactions:
- UI ↔ ViewModels / Code-behind invoke Service Layer methods
- Service Layer calls Utility classes and NativeInterop for OS and third-party library operations
- OCRService → Windows.Media.Ocr API → returns OcrResult → mapped into domain Models → passed back to UI
- ClipboardUtilities reads/writes clipboard on behalf of UI and Services
- UndoRedoManager tracks operations initiated in UI (word border edits, image changes)
- CommandLineProcessor can launch specific UI modes or batch OCR via Services
- Text-Grab-Package wraps the WPF app for store deployment

c. Architectural patterns and principles:
- Layered architecture: UI, Application Services, Utilities, NativeInterop, Data Models
- Command pattern for undo/redo operations
- Separation of concerns: each folder corresponds to a distinct responsibility
- Dependency on OS services is abstracted behind utility and interop classes

d. Technologies, frameworks, and libraries:
- .NET 6.0 / .NET desktop and UWP workloads
- WPF for UI, XAML for layout and styling
- Windows.Media.Ocr UWP API
- ZXing.Net for barcode/QR code
- WPF UI (Fluent styling), CommunityToolkit, CliWrap

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        Views["Views"]:::frontend
        Controls["Controls"]:::frontend
    end

    subgraph "Application Core"
        HistoryService["HistoryService"]:::service
        SettingsService["SettingsService"]:::service
        CommandLineProcessor["App.xaml.cs (CommandLineProcessor)"]:::service
        UndoRedoManager["UndoRedoManager"]:::service
    end

    subgraph "Utility Layer"
        GeneralUtilities["General Utilities"]:::util
        ClipboardUtilities["ClipboardUtilities"]:::util
        FileUtilities["FileUtilities"]:::util
        IoUtilities["IoUtilities"]:::util
        HotKeyManager["HotKeyManager"]:::util
        OcrUtilities["OcrUtilities"]:::util
        BarcodeUtilities["BarcodeUtilities"]:::util
        NotificationUtilities["NotificationUtilities"]:::util
    end

    subgraph "Data Models"
        Models["Models"]:::data
    end

    subgraph "Native Interop"
        NativeMethods["NativeMethods"]:::util
        OSInterop["OSInterop"]:::util
    end

    subgraph "Packaging"
        Packaging["Text-Grab-Package"]:::external
    end

    subgraph "External Dependencies"
        OCRAPI["Windows.Media.Ocr API"]:::external
        ZXing["ZXing.Net"]:::external
        WPFUI["WPF UI Library"]:::external
        CliWrap["CliWrap"]:::external
        Toolkit["CommunityToolkit"]:::external
    end

    Views --> HistoryService
    Views --> SettingsService
    Views --> CommandLineProcessor
    Views --> UndoRedoManager

    Controls --> HistoryService
    Controls --> SettingsService
    Controls --> CommandLineProcessor
    Controls --> UndoRedoManager

    CommandLineProcessor --> Views
    CommandLineProcessor --> Controls
    CommandLineProcessor --> HistoryService
    CommandLineProcessor --> SettingsService

    HistoryService --> Models
    SettingsService --> Models
    UndoRedoManager --> Models

    HistoryService --> FileUtilities
    HistoryService --> IoUtilities
    SettingsService --> FileUtilities

    HistoryService --> ClipboardUtilities

    HotKeyManager --> CommandLineProcessor
    HotKeyManager --> HistoryService

    OcrUtilities --> OCRAPI
    BarcodeUtilities --> ZXing

    OcrUtilities --> Models
    UndoRedoManager --> NotificationUtilities

    NativeMethods --> OcrUtilities
    OSInterop --> OcrUtilities

    Packaging --> Views
    Packaging --> Controls
    Packaging --> CommandLineProcessor

    classDef frontend fill:#E3F2FD,stroke:#1976D2,stroke-width:1px;
    classDef service fill:#E8F5E9,stroke:#388E3C,stroke-width:1px;
    classDef util fill:#FFFDE7,stroke:#FBC02D,stroke-width:1px;
    classDef data fill:#FFF3E0,stroke:#FB8C00,stroke-width:1px;
    classDef external fill:#ECEFF1,stroke:#607D8B,stroke-width:1px;

    click Views "https://github.com/thejoefin/text-grab/tree/main/Text-Grab/Views"
    click Controls "https://github.com/thejoefin/text-grab/tree/main/Text-Grab/Controls"
    click HistoryService "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Services/HistoryService.cs"
    click SettingsService "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Services/SettingsService.cs"
    click CommandLineProcessor "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/App.xaml.cs"
    click UndoRedoManager "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/UndoRedoOperations/UndoRedo.cs"
    click GeneralUtilities "https://github.com/thejoefin/text-grab/tree/main/Text-Grab/Utilities"
    click ClipboardUtilities "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Utilities/ClipboardUtilities.cs"
    click FileUtilities "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Utilities/FileUtilities.cs"
    click IoUtilities "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Utilities/IoUtilities.cs"
    click HotKeyManager "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Utilities/HotKeyManager.cs"
    click OcrUtilities "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Utilities/OcrUtilities.cs"
    click BarcodeUtilities "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Utilities/BarcodeUtilities.cs"
    click NotificationUtilities "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/Utilities/NotificationUtilities.cs"
    click Models "https://github.com/thejoefin/text-grab/tree/main/Text-Grab/Models"
    click NativeMethods "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/NativeMethods.cs"
    click OSInterop "https://github.com/thejoefin/text-grab/blob/main/Text-Grab/OSInterop.cs"
    click Packaging "https://github.com/thejoefin/text-grab/tree/main/Text-Grab-Package"
```
