# lemos1235/excel-translator architecture

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

- Interactive diagram: https://gitdiagram.com/lemos1235/excel-translator
- Repository: https://github.com/lemos1235/excel-translator

## Overview

##### Project Type and Purpose
- This is a desktop translation tool written in Go, offering both CLI and GUI front-end options to translate Japanese text in Excel (and Word) documents into Simplified Chinese.
- It reads files, preserves formatting, invokes an AI translation service (via API), and writes back the translated documents.

##### File Structure Analysis
- Top-level:
- cli/           – Command-line front end (cli/main.go)
- gui2/          – GUI front end (gui2/gui2.go)
- core/          – Core orchestration logic (core/core.go)
- word/          – Word document translator
- config/        – Configuration loader and model for TOML settings
- demo/          – Sample/demo inputs
- main.go        – Likely the default entry point (could route to CLI or GUI)
- Makefile       – Build and install targets
- go.mod, go.sum – Dependency management

##### Insights from README
- Two modes of operation: CLI and GUI (built with miqt).
- A TOML config file drives concurrency, CJK filtering, prompt templates, and LLM API parameters.
- Workflow: load file → parse relevant text nodes → call LLM API → inject translations → save file.

a. Main Components
1) Front Ends
- CLI component
- GUI component
2) Core Translator Service
3) Configuration Loader
4) File Parsers/Translators
– Word translator
5) External LLM API
6) File I/O (read/write)
b. Relationships & Data Flows
1) User invokes CLI or GUI → triggers Core
2) Core calls Configuration Loader → obtains settings
3) Core invokes File Parsers for each document type → yields text segments
4) Core batches segments (per max_concurrent_requests) → sends to External LLM API
5) Receives translated text → File Parsers recompose document preserving formatting
6) Core writes output file
c. Architectural Patterns & Principles
- Separation of Concerns: front ends vs. core engine vs. parsers
- Strategy Pattern: interchangeable parsers for Excel vs. Word
- Adapter Pattern: wrapper around LLM API to standardize calls
- Concurrency Control: managed by configuration (max_concurrent_requests)
d. Key Technologies
- Go modules (go.mod)
- miqt for GUI
- toml for config
- External HTTP API for LLM model

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User((User)):::user

    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI["CLI Front End"]:::frontend
        GUI["GUI Front End"]:::frontend
    end

    User --> CLI
    User --> GUI

    %% Build & Entry
    subgraph "Build & Entry"
        Entry["Application Entry Point\n(main.go)"]:::infra
        Make["Makefile"]:::infra
        Mod["go.mod"]:::infra
        Sum["go.sum"]:::infra
    end

    Entry --> CLI
    Entry --> GUI
    Make --> Entry
    Mod --> Entry
    Sum --> Entry

    %% Application Layer
    subgraph "Application Layer"
        Core["Core Translator Service"]:::core
        Config["Configuration Loader"]:::config
        Core --> Config

        subgraph "Document Parsers"
            ExcelCell["Cell Translator"]:::parser
            ExcelShape["Shape Translator"]:::parser
            ExcelSheet["Sheet Translator"]:::parser
            Word["Word Translator"]:::parser
        end

        Core --> ExcelCell
        Core --> ExcelShape
        Core --> ExcelSheet
        Core --> Word
    end

    %% External Service
    LLM["External LLM API"]:::external
    Core -->|"JSON payload"|LLM
    LLM -->|"Translated segments"|Core

    %% Infrastructure
    subgraph "Infrastructure"
        FS["File System"]:::datastore
    end

    CLI -->|"Document bytes"|FS
    GUI -->|"Document bytes"|FS
    ExcelCell -->|"Read/Write docs"|FS
    ExcelShape -->|"Read/Write docs"|FS
    ExcelSheet -->|"Read/Write docs"|FS
    Word -->|"Read/Write docs"|FS
    Core -->|"Final document bytes"|FS

    %% Click Events
    click CLI "https://github.com/lemos1235/excel-translator/blob/main/cli/main.go"
    click GUI "https://github.com/lemos1235/excel-translator/blob/main/gui2/gui2.go"
    click Core "https://github.com/lemos1235/excel-translator/blob/main/core/core.go"
    click Config "https://github.com/lemos1235/excel-translator/blob/main/config/config.go"
    click ExcelCell "https://github.com/lemos1235/excel-translator/blob/main/excel/cell_translator.go"
    click ExcelShape "https://github.com/lemos1235/excel-translator/blob/main/excel/shape_translator.go"
    click ExcelSheet "https://github.com/lemos1235/excel-translator/blob/main/excel/sheet_translator.go"
    click Word "https://github.com/lemos1235/excel-translator/blob/main/word/document_translator.go"
    click Entry "https://github.com/lemos1235/excel-translator/blob/main/main.go"
    click Make "https://github.com/lemos1235/excel-translator/tree/main/Makefile"
    click Mod "https://github.com/lemos1235/excel-translator/blob/main/go.mod"
    click Sum "https://github.com/lemos1235/excel-translator/blob/main/go.sum"

    %% Styles
    classDef frontend fill:#f0f8ff,stroke:#333,stroke-width:1px
    classDef infra fill:#e6e6fa,stroke:#333,stroke-width:1px
    classDef core fill:#ffe4b5,stroke:#333,stroke-width:1px
    classDef config fill:#fafad2,stroke:#333,stroke-width:1px
    classDef parser fill:#e0ffff,stroke:#333,stroke-width:1px
    classDef external fill:#fffafa,stroke:#333,stroke-dasharray: 5 5
    classDef datastore fill:#f5f5dc,stroke:#333,stroke-width:1px
    classDef user fill:#d3d3d3,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
