# oslong/manga-image-translator architecture

> Architecture diagram of the GitHub repository oslong/manga-image-translator, 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/oslong/manga-image-translator
- Repository: https://github.com/oslong/manga-image-translator

## Overview

##### High-level components
- Client Interface Layer:
- CLI Mode (for batch processing)
- Web/API Mode (see the “server” directory with main.py, manual.html, and queue management in myqueue.py)
- Demo / Local mode (e.g. run.sh and run_as_colab.ipynb)
- Core Processing Pipeline (“manga_translator” package):
- Input/Preprocessing: Accepting an image file; could include generic utils, logging, and configuration parsing (via config.py and pyproject.toml).
- Detection Module: Located in manga_translator/detection; supports different detection methods (CTD, CRAFT, DBNet, and even “none”).
- OCR Module: In manga_translator/ocr; supporting multiple resolution models (32px, 48px, etc).
- Translation Module: In manga_translator/translators; integrates various translators (youdao, baidu, deepl, GPT versions, etc) and supports both offline and API-based translations.
- Inpainting Module: In manga_translator/inpainting; performs text removal and image repair using several methods (sd, lama variants, and original/diffusion-based).
- Rendering & Post-processing Module: In manga_translator/rendering; for overlaying translated text using methods like “manga2eng” and interfacing with external tools like Gimp.
- Colorization/Upscaling Modules: Found in manga_translator/colorization and manga_translator/upscaling for improving visualization quality.
- Utility Modules: (manga_translator/utils, textline_merge, mask_refinement) for common tasks and post-processing.
- Training / Model Improvement Components:
- Under the “training” directory, training for OCR and inpainting components.
- Deployment Infrastructure:
- Docker support (Dockerfile, docker_prepare.py, and docker-compose files in demo/doc) which shows both CPU and GPU deployment.
- CI/CD configuration (inside .github/workflows)

- The Input/Preprocessing then “branches” into the core image processing pipeline:
– Detection Module → extracts text region coordinates from the image.
– OCR Module → reads text from those regions.
– Translation Module → sends the deciphered text to one or more translation services (external API calls or offline translator logic) to map source text to target language.
– Inpainting Module → removes or masks out the original text.
– Rendering Module → overlays or renders the translated text onto the image. Optionally, the pipeline might send the image through the Colorization and Upscaling modules to improve final output quality.
- For the Translation module, indicate external dependencies with a side note: “API Keys and External Service” (e.g., DeepL, Youdao, GPT-3/4) which are set via env vars and configuration.

##### Elements
- Clear labelling for each component (e.g., “Detection Module (CTD/CRAFT/Default)”, “OCR Engine (48px, 32px Models)”, “Translation Service Adapter (DeepL, GPT3, etc)”, “Inpainting & Render Engine”, and “Client Interface: CLI / Web API”).
- Annotations indicating configuration injection and dependency on external APIs and GPU acceleration.

- Then subdivide the pipeline into granular modules (detection, OCR, translation, inpainting, rendering, etc.) so that the dependencies and data transformations are clearly visible.
- Remember that while the project has many components, focusing on end-to-end flow—from image input to translated image output—is key.
- Lastly, include optional flows (like error handling and configuration injection) to capture the essential architectural elements as represented by the extensive configuration files and multiple implementation strategies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Interface Layer
    subgraph "Client Interface Layer"
        CLI["CLI Mode (Batch Processing)"]:::client
        WEB["Web/API Mode"]:::client
        DEMO["Demo/Local Mode"]:::client
    end

    %% Core Processing Pipeline
    subgraph "Core Processing Pipeline"
        PRE["Input/Preprocessing\n(Configuration & Initialization)"]:::core
        DET["Detection Module\n(CTD/CRAFT/None)"]:::core
        OCR["OCR Module\n(32px,48px Models)"]:::core
        TRL["Translation Module\n(Baidu,DeepL,GPT,etc)"]:::core
        INP["Inpainting Module\n(SD,Lama,Diffusion)"]:::core
        REN["Rendering Module\n(Text Overlay & Gimp)"]:::core
        COL["Colorization Module"]:::core
        UPS["Upscaling Module"]:::core
        UTL["Utility Modules\n(Logging,Mask Refinement)"]:::core
        FINAL["Output:\nTranslated Image"]:::output
    end

    %% Training / Model Improvement
    subgraph "Training / Model Improvement"
        TRAIN["Training Resources"]:::infrastructure
    end

    %% Deployment Infrastructure
    subgraph "Deployment Infrastructure"
        DOCK["Docker & Deployment Scripts"]:::infrastructure
        CICD["CI/CD Pipeline"]:::infrastructure
    end

    %% Data Flow Connections
    CLI ---|"input"| PRE
    WEB ---|"input"| PRE
    DEMO ---|"input"| PRE

    PRE -->|"preprocess"| DET
    DET -->|"detect text regions"| OCR
    OCR -->|"extracted text"| TRL
    TRL -->|"translated text"| INP
    INP -->|"inpainted image"| REN
    REN -->|"final render"| FINAL
    REN --> COL
    REN --> UPS
    COL ---|"enhanced colors"| FINAL
    UPS ---|"upscaled image"| FINAL

    %% Utility connection (logging/error handling available across modules)
    PRE --- UTL
    DET --- UTL
    OCR --- UTL
    TRL --- UTL
    INP --- UTL
    REN --- UTL

    %% Click Events for Client Interface Layer
    click CLI "https://github.com/oslong/manga-image-translator/blob/main/run.sh"
    click WEB "https://github.com/oslong/manga-image-translator/blob/main/server/main.py"
    click DEMO "https://github.com/oslong/manga-image-translator/tree/main/demo/"

    %% Click Events for Core Processing Pipeline
    click PRE "https://github.com/oslong/manga-image-translator/blob/main/manga_translator/config.py"
    click DET "https://github.com/oslong/manga-image-translator/tree/main/manga_translator/detection/"
    click OCR "https://github.com/oslong/manga-image-translator/tree/main/manga_translator/ocr/"
    click TRL "https://github.com/oslong/manga-image-translator/tree/main/manga_translator/translators/"
    click INP "https://github.com/oslong/manga-image-translator/tree/main/manga_translator/inpainting/"
    click REN "https://github.com/oslong/manga-image-translator/tree/main/manga_translator/rendering/"
    click COL "https://github.com/oslong/manga-image-translator/tree/main/manga_translator/colorization/"
    click UPS "https://github.com/oslong/manga-image-translator/tree/main/manga_translator/upscaling/"
    click UTL "https://github.com/oslong/manga-image-translator/tree/main/manga_translator/utils/"

    %% Click Events for Training / Model Improvement
    click TRAIN "https://github.com/oslong/manga-image-translator/tree/main/training/"

    %% Click Events for Deployment Infrastructure
    click DOCK "https://github.com/oslong/manga-image-translator/tree/main/demo/doc/"
    click CICD "https://github.com/oslong/manga-image-translator/tree/main/.github/workflows/"

%% Classes and Styles
classDef client fill:#f9f,stroke:#333,stroke-width:2px;
classDef core fill:#bbf,stroke:#333,stroke-width:2px;
classDef output fill:#bfb,stroke:#333,stroke-width:2px;
classDef infrastructure fill:#fed,stroke:#333,stroke-width:2px;
```
