# onemoregres/screentranslator architecture

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

- Interactive diagram: https://gitdiagram.com/onemoregres/screentranslator
- Repository: https://github.com/onemoregres/screentranslator

## Overview

##### Main components
- Module (src/capture): This module handles screen capture including selecting and editing the capture area.
- OCR Module (src/ocr): Responsible for converting captured images to text using Tesseract. It also manages worker processes (recognizerworker) for background OCR processing.
- Correction Module (src/correct): Contains components for text correction, such as the Hunspell-based corrector.
- Translation Module (src/translate): Manages the process of translating recognized text using various online translation services. The translators folder holds scripts that implement support for services like Google, Bing, DeepL, etc.
- Representation Module (src/represent): Deals with displaying the results (translated text) in the UI, managing result widgets and editors.
- Services & Utilities (src/service): Includes helper classes for common functionalities (e.g., application translation, global actions, updates, widget state, etc.), as well as system-specific integrations like auto-launch (runatsystemstart) and single application enforcement.

##### Relationships and interactions
- The Capture Module (in src/capture) collects the screen region and passes the image to the OCR Module.
- The OCR Module processes the image, extracts text, and sends it to the Correction Module if necessary.
- Corrected text is then fed into the Translation Module, which uses one or more configured online services to get the translated text.
- The translated text is then handled by the Representation Module and displayed to the user (either as a pop-up, integrated text field, or another UI component).
- Module has clear input and output dataflows (for example, data flows from capture → OCR → correction → translation → representation).

##### Architectural patterns and design principles
- Modular design: The directory structure clearly segments functionalities (capture, ocr, correct, translate, represent, service).
- Layered architecture: Data flows are processed sequentially through modules. This segmentation makes it easier to pinpoint where errors occur or where extensions should be added (e.g., adding another translator or a new correction strategy).
- Worker-based processing: Several modules, such as OCR and correction, use worker classes (evident from files like recognizerworker.cpp and correctorworker.cpp), indicating asynchronous or multi-threaded processing.
- Dependency on external libraries: Mark external libraries like Qt (for UI and application framework), Tesseract and Leptonica (for OCR), and Hunspell (for text correction).

##### Relevant technologies and frameworks
- Qt 5: Used for UI, system tray integration, and overall application management.
- Tesseract & Leptonica: Core dependencies for the OCR functionality.
- Hunspell: Used in the correction module.
- Various online translation services implemented as separate JavaScript translators.
- CI/CD scripts and external dependency management present in the “share/ci” and “external” directories.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        user("User"):::ui
        trayIcon("Tray Icon"):::ui
        settingsWindow("Settings Window"):::ui
    end

    %% Processing Pipeline
    subgraph "Processing Pipeline"
        captureModule("Capture Module"):::core
        ocrModule("OCR Module"):::core
        correctModule("Correction Module"):::core
        translateModule("Translation Module"):::core
        representModule("Representation Module"):::core
    end

    %% Supporting Components
    settingsConfig("Settings & Configuration"):::support
    services("Services & Utilities"):::support
    translatorScripts("Translator Scripts"):::core

    %% Flows for user interaction and processing
    user -->|"initiates"| trayIcon
    trayIcon -->|"triggers_capture"| captureModule
    trayIcon -->|"opens_settings"| settingsWindow
    settingsWindow -->|"edits_config"| settingsConfig

    captureModule -->|"captures_screen"| ocrModule
    ocrModule -->|"performs_OCR"| correctModule
    correctModule -->|"corrects_text"| translateModule
    translateModule -->|"translates_text"| representModule
    translateModule -->|"uses"| translatorScripts

    %% Dotted dependencies to supporting services
    captureModule -.-> services
    ocrModule -.-> services
    correctModule -.-> services
    translateModule -.-> services
    representModule -.-> services
    settingsConfig -.-> services

    %% Styling
    classDef ui fill:#ffdddd,stroke:#aa2222,stroke-width:2px
    classDef core fill:#ddeeff,stroke:#224488,stroke-width:2px
    classDef support fill:#ddffdd,stroke:#228822,stroke-width:2px

    %% Click Events
    click trayIcon "https://github.com/onemoregres/screentranslator/blob/master/src/trayicon.cpp"
    click trayIcon "https://github.com/onemoregres/screentranslator/blob/master/src/trayicon.h"
    click settingsWindow "https://github.com/onemoregres/screentranslator/blob/master/src/settingseditor.cpp"
    click settingsWindow "https://github.com/onemoregres/screentranslator/blob/master/src/settingseditor.h"
    click settingsWindow "https://github.com/onemoregres/screentranslator/blob/master/src/settingseditor.ui"
    click settingsConfig "https://github.com/onemoregres/screentranslator/blob/master/recources.qrc"
    click captureModule "https://github.com/onemoregres/screentranslator/tree/master/src/capture/"
    click ocrModule "https://github.com/onemoregres/screentranslator/tree/master/src/ocr/"
    click correctModule "https://github.com/onemoregres/screentranslator/tree/master/src/correct/"
    click translateModule "https://github.com/onemoregres/screentranslator/tree/master/src/translate/"
    click translatorScripts "https://github.com/onemoregres/screentranslator/tree/master/translators/"
    click representModule "https://github.com/onemoregres/screentranslator/tree/master/src/represent/"
    click services "https://github.com/onemoregres/screentranslator/tree/master/src/service/"
    click settingsConfig "https://github.com/onemoregres/screentranslator/blob/master/src/settings.cpp"
    click settingsConfig "https://github.com/onemoregres/screentranslator/blob/master/src/settings.h"
```
