# yang-haruka/linguaharu architecture

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

- Interactive diagram: https://gitdiagram.com/yang-haruka/linguaharu
- Repository: https://github.com/yang-haruka/linguaharu

## Overview

##### Project type and purpose
- This is a Python-based full-stack translation tool (LinguaHaru) that provides a web UI for uploading documents, runs format-specific translation pipelines, and calls LLM engines (local or online) to produce output.

##### File structure
- Top-level:
- app.py / app_temp.py – entry point for the web server/UI
- config/ – holds API credentials, prompts, system settings
- llmWrapper/ – abstraction layer over local (Ollama) and online model APIs
- pipeline/ – orchestrators for each file type’s end-to-end translation flow
- translator/ – per-format translation logic (Word, Excel, PDF, etc.)
- textProcessing/ – text splitting, token counting, translation checking
- utils/ – queue manager, process launcher, UI helpers, logging
- No persistent database; files flow through in-memory or temporary storage
- External dependencies: online LLM services (OpenAI, Deepseek, etc.), local Ollama runtime

##### Key README insights
- Single-page web UI served at http://127.0.0.1:9980
- “One-click” pipeline: upload → pipeline → LLM call → reassembly → download
- Configurable engines, prompts, multilingual support

##### Main components & interactions
a. Frontend (Web UI)
- Served by app.py (Flask/FastAPI/Starlette or equivalent)
- Upload endpoint, status/progress, download link

b. Backend API Server
- HTTP controller in app.py → delegates to utils/main_app and utils/translation_process
- Reads config/app_queue for task scheduling

c. Pipeline Orchestrator
- pipeline/*.py modules select the right flow based on file type
- Enqueue tasks, manage multithreading/multiprocessing

d. Translator Modules
- translator/*_translator.py handle I/O, format parsing, layout preservation
- PDFMathTranslate subpackage for PDF specifics

e. Text Processing
- base_translator, text_separator, calculation_tokens, translation_checker
- Splits large text, counts tokens, ensures chunk correctness

f. LLM Wrapper
- llm_wrapper.py picks between local Ollama or remote APIs (OpenAI, Deepseek, Gemini…)
- online_translation.py / offline_translation.py implement HTTP or local CLI calls

g. Configuration
- config/api_config/*.json, config/system_config.json, config/prompts/*.json
- languages_config.py and load_prompt.py dynamically supply parameters

h. External Services & Models
- Local model repository under models/ (Qwen, etc.)
- Remote API endpoints

##### Architectural patterns & design principles
- Modular “pipeline” pattern: each file format has its own pipeline class
- Separation of concerns: UI layer, orchestration layer, format translators, LLM calls, text utilities
- Config-driven behavior: engines, prompts, languages all abstracted via JSON
- Task queue + multiprocessing for concurrency

##### Detail
- Both local and online LLM branches
- Where prompts/config merge into the workflow
- Flow of a single “translate document” request end-to-end

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors and Frontend
    User([User]):::actor
    subgraph "Frontend Layer"
        UI["Web UI\n(app.py, app_temp.py)"]:::frontend
    end

    User -->|"interacts via browser"| UI
    UI -->|"POST /translate"| Req

    %% Backend Layer
    subgraph "Backend API Server" 
        direction TB
        Req["Request Handler\nutils/main_app.py\nutils/translation_process.py"]:::backend
        Queue["Task Queue / Scheduler\nutils/app_queue.py"]:::backend
        Config["Configuration Store\nconfig/"]:::config
        PipelineMgr["Pipeline Manager\npipeline/"]:::backend
        TranslatorMod["Translator Modules\ntranslator/"]:::backend
        TextProc["Text Processing\ntextProcessing/"]:::backend
        LLMWrap["LLM Wrapper\nllmWrapper/"]:::backend
    end

    UI --> Req
    Req -->|"enqueue task"| Queue
    Queue -->|"start pipeline"| PipelineMgr
    PipelineMgr -->|"select flow"| TranslatorMod
    TranslatorMod -->|"parse & preserve layout"| TextProc
    TextProc -->|"chunk text"| LLMWrap
    LLMWrap -->|"return translation"| PipelineMgr
    PipelineMgr -->|"assemble output"| Queue
    Queue --> Req
    Req -->|"send response"| UI

    %% Configuration usage
    Config --> Req
    Config --> PipelineMgr
    Config --> LLMWrap

    %% External Services
    subgraph "External Services"
        direction TB
        Ollama[(Local Model Server\nOllama)]:::external
        Online[(Online LLM APIs\nOpenAI, Deepseek, Gemini…)]:::external
    end

    LLMWrap -->|"use local"| Ollama
    LLMWrap -->|"use remote"| Online

    %% Data Stores
    ModelRepo["Model Repository\nmodels/.gitkeep"]:::data
    Glossary["Glossary\nglossary/Default.csv"]:::data

    Ollama --> ModelRepo
    Config --> Glossary

    %% Click Events
    click UI "https://github.com/yang-haruka/linguaharu/blob/main/app.py"
    click UI "https://github.com/yang-haruka/linguaharu/blob/main/app_temp.py"
    click Req "https://github.com/yang-haruka/linguaharu/blob/main/utils/main_app.py"
    click Req "https://github.com/yang-haruka/linguaharu/blob/main/utils/translation_process.py"
    click Queue "https://github.com/yang-haruka/linguaharu/blob/main/utils/app_queue.py"
    click Config "https://github.com/yang-haruka/linguaharu/tree/main/config/"
    click PipelineMgr "https://github.com/yang-haruka/linguaharu/tree/main/pipeline/"
    click TranslatorMod "https://github.com/yang-haruka/linguaharu/tree/main/translator/"
    click TextProc "https://github.com/yang-haruka/linguaharu/tree/main/textProcessing/"
    click LLMWrap "https://github.com/yang-haruka/linguaharu/tree/main/llmWrapper/"
    click ModelRepo "https://github.com/yang-haruka/linguaharu/blob/main/models/.gitkeep"
    click Glossary "https://github.com/yang-haruka/linguaharu/blob/main/glossary/Default.csv"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#1E70BF,color:#000;
    classDef backend fill:#DFF7D8,stroke:#2E8B57,color:#000;
    classDef external fill:#FFE6B3,stroke:#FF8C00,color:#000;
    classDef config fill:#E0E0E0,stroke:#A9A9A9,color:#000;
    classDef data fill:#F0F0F0,stroke:#696969,color:#000;
    classDef actor fill:#FFFFFF,stroke:#000000,stroke-width:2px;
    class User actor
    class UI frontend
    class Req,Queue,PipelineMgr,TranslatorMod,TextProc,LLMWrap backend
    class Config config
    class Ollama,Online external
    class ModelRepo,Glossary data
```
