# ffreemt/deeplx-tr architecture

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

- Interactive diagram: https://gitdiagram.com/ffreemt/deeplx-tr
- Repository: https://github.com/ffreemt/deeplx-tr

## Overview

##### Main System Components

a) Client Interface Layer:
- Command-line interface (Translate.py, __main__.py)
- Web interface (pages/1-🧰Toolbox.py, pages/2-ℹ️Info.py)
- Python API interface (for library usage)

b) Core Translation Services:
- DeepLX Translation Service (src/deeplx_tr/deeplx_tr.py)
- LLM Translation Service (src/deeplx_tr/llm_tr.py)
- New API Translation Service (src/deeplx_tr/newapi_tr.py)

c) External Services Integration:
- DeepLX Server Connection (deeplx_client.py, deeplx_client_async.py)
- LLM API Integration
- External API Services

##### Component Relationships

- User requests → Client Interface Layer
- Client Interface Layer → Translation Services
- Translation Services → External Services
- Response flow back to user

##### Architectural Patterns to Highlight

a) Service Layer Pattern:
- Clear separation between interface and translation services
- Async capabilities for DeepLX client

b) Client Abstraction:
- How different clients (sync/async) interact with DeepLX

##### Technical Implementation Details

- Blue rectangles: User-facing interfaces
- Green rectangles: Core translation services
- Yellow rectangles: External services
- Purple rectangles: Utility modules (color_diff.py, duration_human.py)

##### Additional Elements

A section showing:
- Configuration management (example.env, model-list.yml.sample)
- Testing framework (tests directory)
- Development tools (.flake8, .ruff.toml, etc.)

##### Specific Implementation Notes

- Concurrent processing capabilities (CONCURRENCY_LIMIT setting)
- Multiple translation backend support (DeepLX, LLM, NewAPI)
- Error handling and fallback mechanisms

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client_Layer
        CLI["Command Line Interface"]:::interface
        WEB["Web Interface"]:::interface
        API["Python API Interface"]:::interface
    end

    subgraph Translation_Services
        DX["DeepLX Translation"]:::service
        LLM["LLM Translation"]:::service
        NAPI["NewAPI Translation"]:::service
    end

    subgraph External_Services
        DXS["DeepLX Server"]:::external
        LLMS["LLM API"]:::external
        EXAPI["External APIs"]:::external
    end

    subgraph Batch_Processing
        BDX["DeepLX Batch"]:::batch
        BLLM["LLM Batch"]:::batch
        BNAPI["NewAPI Batch"]:::batch
    end

    subgraph Utility_Modules
        CD["Color Diff"]:::utility
        DH["Duration Calculator"]:::utility
        DC["Document Converter"]:::utility
    end

    subgraph Configuration
        ENV["Environment Config"]:::config
        MC["Model Configuration"]:::config
    end

    subgraph Testing
        TDX["DeepLX Tests"]:::test
        TLLM["LLM Tests"]:::test
        TNAPI["NewAPI Tests"]:::test
    end

    %% Client Layer Connections
    CLI --> DX & LLM & NAPI
    WEB --> DX & LLM & NAPI
    API --> DX & LLM & NAPI

    %% Translation Services to External Services
    DX -.-> DXS
    LLM -.-> LLMS
    NAPI -.-> EXAPI

    %% Batch Processing Connections
    DX --- BDX
    LLM --- BLLM
    NAPI --- BNAPI

    %% Testing Connections
    DX --- TDX
    LLM --- TLLM
    NAPI --- TNAPI

    %% Configuration Connections
    ENV --> DX & LLM & NAPI
    MC --> LLM & NAPI

    %% Utility Module Usage
    CD --- DX & LLM & NAPI
    DH --- DX & LLM & NAPI
    DC --- DX & LLM & NAPI

    %% Click Events
    click CLI "https://github.com/ffreemt/deeplx-tr/blob/main/Translate.py"
    click WEB "https://github.com/ffreemt/deeplx-tr/blob/main/pages/1-🧰Toolbox.py"
    click API "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/__main__.py"
    click DX "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/deeplx_tr.py"
    click LLM "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/llm_tr.py"
    click NAPI "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/newapi_tr.py"
    click BDX "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/batch_deeplx_tr.py"
    click BLLM "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/batch_llm_tr.py"
    click BNAPI "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/batch_newapi_tr.py"
    click CD "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/color_diff.py"
    click DH "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/duration_human.py"
    click DC "https://github.com/ffreemt/deeplx-tr/blob/main/src/deeplx_tr/trtext2docx.py"
    click TDX "https://github.com/ffreemt/deeplx-tr/blob/main/tests/test_deeplx_tr.py"
    click TLLM "https://github.com/ffreemt/deeplx-tr/blob/main/tests/test_llm_tr.py"
    click TNAPI "https://github.com/ffreemt/deeplx-tr/blob/main/tests/test_newapi_tr.py"
    click ENV "https://github.com/ffreemt/deeplx-tr/blob/main/example.env"
    click MC "https://github.com/ffreemt/deeplx-tr/blob/main/model-list.yml.sample"

    %% Styling
    classDef interface fill:#3498db,stroke:#2980b9,color:white
    classDef service fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef batch fill:#e74c3c,stroke:#c0392b,color:white
    classDef utility fill:#9b59b6,stroke:#8e44ad,color:white
    classDef config fill:#1abc9c,stroke:#16a085,color:white
    classDef test fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        L1["Interface"]:::interface
        L2["Service"]:::service
        L3["External"]:::external
        L4["Batch"]:::batch
        L5["Utility"]:::utility
        L6["Config"]:::config
        L7["Test"]:::test
    end
```
