# mashirosaber03/saber-translator architecture

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

- Interactive diagram: https://gitdiagram.com/mashirosaber03/saber-translator
- Repository: https://github.com/mashirosaber03/saber-translator

## Overview

##### Main Components
- Frontend User Interface:
- Represented by the static and templates directories.
- HTML (index.html), JavaScript (script.js), and CSS (style.css) form the browser-based interface for uploading images/pdf files, previewing translation, toggling editing modes, and managing images.

- Backend Server:
- The central entry point is app.py.
- This Python module likely initializes the Flask (or similar) web server, handling HTTP requests (file uploads, rendering views, returning translations).

- Configuration and Model Data:
- config.py holds configuration settings such as API keys, model parameters, or paths.
- JSON files (model_info.json, prompt_info.json) store runtime or model-related metadata.

- Core Processing Modules:
- bubble_detection.py encapsulates the logic for identifying speech bubbles on manga images using the YOLOv5 weights stored under the weights directory (best.pt, last.pt).
- This module interacts with OCR or further pre-/post-processing steps as part of the image translation pipeline.

- External AI Translation Engines:
- The README mentions support for services like SiliconFlow, DeepSeek, and even local large models via ollama.

- Static Files and Assets:
- The “pic” directory holds logos and several screenshots that emphasize UI aspects (and may be used for branding or demo).
- It can be marked as an asset repository used by both the frontend and documentation.

##### Relationships and Data Flow
- Data/Input Flow:
- The client (browser) sends an image or PDF upload request via the UI.
- The backend (app.py) receives the file and, based on configuration (config.py), dispatches it to the bubble_detection module.

- Bubble Detection and OCR Pipeline:
- bubble_detection.py uses the weights from the weights folder to identify text bubbles in the image.
- Extracted regions are processed using the integrated OCR technology (linked in the README to Manga OCR).

- Translation Process:
- Once text is recognized, the backend consults available AI translation services (SiliconFlow, DeepSeek, etc.) based on API key configurations.
- There might be a logic module or decision engine (inside app.py) to select which translation service to use.

- Response and Rendering:
- Processed and translated text is re-integrated into the image if editing mode is enabled.
- The final output is served back to the client for a real-time preview on the web interface.

##### Architectural Patterns and Design Principles
- MVC-like Separation:
- Although the project is compact, notice how the file structure separates front-end (templates, static assets) from back-end logic (Python modules) and configuration.

- Pipeline Pattern:
- The processing flow (file upload ­→ bubble detection → OCR → translation → rendering) should be depicted as a sequence of processing stages.

- Extensibility:

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Side"
        Browser("Client Browser"):::client
    end

    subgraph "Frontend UI"
        HTML("HTML Template"):::frontend
        JS("JavaScript File"):::frontend
        CSS("CSS File"):::frontend
    end

    subgraph "Backend Services"
        App("Backend Server (app.py)"):::backend
        Config("Configuration (config.py)"):::backend
        MM("Model Metadata (model_info.json)"):::backend
        PM("Prompt Metadata (prompt_info.json)"):::backend
    end

    subgraph "Core Processing"
        BD("Bubble Detection (bubble_detection.py)"):::processing
        BW1("Model Weight (best.pt)"):::processing
        BW2("Model Weight (last.pt)"):::processing
        OCR("OCR Module (Manga OCR)"):::processing
    end

    subgraph "External Services"
        Trans("Translation Services (SiliconFlow,DeepSeek,ollama)"):::external
    end

    subgraph "Assets"
        Branding("Branding & Screenshots"):::asset
    end

    %% Data Flow Connections
    Browser --> HTML
    HTML --> App
    App --> Config
    App --> MM
    App --> PM
    App --> BD
    BD --> BW1
    BD --> BW2
    BD --> OCR
    OCR --> Trans
    Trans --> App
    App --> Browser
    Branding --> HTML

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef processing fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef asset fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef client fill:#e6e6fa,stroke:#483d8b,stroke-width:2px;

    %% Click Events
    click HTML "https://github.com/mashirosaber03/saber-translator/blob/main/templates/index.html"
    click JS "https://github.com/mashirosaber03/saber-translator/blob/main/static/script.js"
    click CSS "https://github.com/mashirosaber03/saber-translator/blob/main/static/style.css"
    click App "https://github.com/mashirosaber03/saber-translator/blob/main/app.py"
    click Config "https://github.com/mashirosaber03/saber-translator/blob/main/config.py"
    click MM "https://github.com/mashirosaber03/saber-translator/blob/main/model_info.json"
    click PM "https://github.com/mashirosaber03/saber-translator/blob/main/prompt_info.json"
    click BD "https://github.com/mashirosaber03/saber-translator/blob/main/bubble_detection.py"
    click BW1 "https://github.com/mashirosaber03/saber-translator/blob/main/weights/best.pt"
    click BW2 "https://github.com/mashirosaber03/saber-translator/blob/main/weights/last.pt"
    click Branding "https://github.com/mashirosaber03/saber-translator/tree/main/pic"
```
