# stevenzhao07/doc-translate-keep-layout architecture

> Architecture diagram of the GitHub repository stevenzhao07/doc-translate-keep-layout, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stevenzhao07/doc-translate-keep-layout
- Repository: https://github.com/stevenzhao07/doc-translate-keep-layout

## Overview

This is a local, standard-library Python toolkit for translating DOCX/PPTX while preserving document structure. Its main workflow extracts a map, validates a translation plan through a fail-closed gate, applies translations, then checks the result. A separate glossary builder finds candidate terms across document collections. The README documents the command workflow and audit trail; the source excerpts are partial, so internal calls between CLI stages are not asserted beyond those documented relationships.

Main entry points: [`scripts/translate_kit.py`](https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py) (Translation apply), [`scripts/glossary_build.py`](https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/glossary_build.py) (Candidate glossary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_translation["Translation workflow"]
  node_map["Paragraph map<br/>[translate_kit.py]"]
  node_apply["Translation apply<br/>[translate_kit.py]"]
end

subgraph group_review["Validation and audit"]
  node_gate["Preflight gate<br/>[translate_kit.py]"]
  node_check["Layout review<br/>[translate_kit.py]"]
  node_audit["Audit log<br/>[translate_kit.py]"]
end

subgraph group_terms["Terminology"]
  node_glossary["Candidate glossary<br/>[glossary_build.py]"]
end

node_user(("Document operator"))
node_source["Source DOCX/PPTX"]
node_plan["Translation plan"]
node_termsfile["Terminology TSV"]
node_output["Translated document"]
node_report["Review report"]
node_corpus["Document corpus"]
node_candidatefile["Candidate terms TSV"]

node_user -->|"requests map"| node_map
node_source -->|"extracts paragraphs"| node_map
node_map -->|"map JSON"| node_gate
node_plan -->|"validates plan"| node_gate
node_termsfile -->|"checks terms"| node_gate
node_source -->|"checks source match"| node_gate
node_user -->|"requests gate"| node_gate
node_user -->|"requests apply"| node_apply
node_source -->|"writes translations"| node_apply
node_plan -->|"supplies translations"| node_apply
node_map -->|"checks paragraph mapping"| node_apply
node_termsfile -->|"checks terminology"| node_apply
node_gate -->|"authorizes apply"| node_apply
node_apply -->|"writes document"| node_output
node_apply -->|"records hashes"| node_audit
node_user -->|"requests check"| node_check
node_source -->|"compares structure"| node_check
node_output -->|"compares structure"| node_check
node_check -->|"produces report"| node_report
node_corpus -->|"scans documents"| node_glossary
node_glossary -->|"writes candidates"| node_candidatefile
node_glossary -->|"uses document parsing"| node_map

click node_map "https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py"
click node_gate "https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py"
click node_apply "https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py"
click node_check "https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py"
click node_audit "https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py"
click node_glossary "https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/glossary_build.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_map,node_apply,node_report toneBlue
class node_gate,node_check,node_audit toneAmber
class node_glossary toneMint
class node_user,node_source,node_plan,node_termsfile,node_output,node_corpus,node_candidatefile toneIndigo
```

## Components

### Translation workflow

- [Paragraph map](https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py): `scripts/translate_kit.py`
- [Translation apply](https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py): `scripts/translate_kit.py`

### Validation and audit

- [Preflight gate](https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py): `scripts/translate_kit.py`
- [Layout review](https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py): `scripts/translate_kit.py`
- [Audit log](https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/translate_kit.py): `scripts/translate_kit.py`

### Terminology

- [Candidate glossary](https://github.com/stevenzhao07/doc-translate-keep-layout/blob/main/scripts/glossary_build.py): `scripts/glossary_build.py`

### Other components

- **Document operator**
- **Source DOCX/PPTX**
- **Translation plan**
- **Terminology TSV**
- **Translated document**
- **Review report**
- **Document corpus**
- **Candidate terms TSV**

## Connections

- Document operator → Paragraph map: requests map (evidence: `README.md`)
- Source DOCX/PPTX → Paragraph map: extracts paragraphs (evidence: `README.md`)
- Paragraph map → Preflight gate: map JSON (evidence: `README.md`)
- Translation plan → Preflight gate: validates plan (evidence: `README.md`)
- Terminology TSV → Preflight gate: checks terms (evidence: `README.md`)
- Source DOCX/PPTX → Preflight gate: checks source match (evidence: `README.md`)
- Document operator → Preflight gate: requests gate (evidence: `README.md`)
- Document operator → Translation apply: requests apply (evidence: `README.md`)
- Source DOCX/PPTX → Translation apply: writes translations (evidence: `README.md`)
- Translation plan → Translation apply: supplies translations (evidence: `README.md`)
- Paragraph map → Translation apply: checks paragraph mapping (evidence: `README.md`)
- Terminology TSV → Translation apply: checks terminology (evidence: `README.md`)
- Preflight gate → Translation apply: authorizes apply (evidence: `README.md`)
- Translation apply → Translated document: writes document (evidence: `README.md`)
- Translation apply → Audit log: records hashes (evidence: `README.md`)
- Document operator → Layout review: requests check (evidence: `README.md`)
- Source DOCX/PPTX → Layout review: compares structure (evidence: `README.md`)
- Translated document → Layout review: compares structure (evidence: `README.md`)
- Layout review → Review report: produces report (evidence: `README.md`)
- Document corpus → Candidate glossary: scans documents (evidence: `scripts/glossary_build.py`)
- Candidate glossary → Candidate terms TSV: writes candidates (evidence: `scripts/glossary_build.py`)
- Candidate glossary → Paragraph map: uses document parsing (evidence: `scripts/glossary_build.py`)
