# kimrenny/i18nh architecture

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

- Interactive diagram: https://gitdiagram.com/kimrenny/i18nh
- Repository: https://github.com/kimrenny/i18nh

## Overview

#### Purpose and Runtime
Localization AI is an Electron desktop app for discovering, comparing, editing, translating, and safely writing JSON localization files. The renderer is React/TypeScript via Vite; privileged filesystem and translation-network work belongs in Electron’s main process. Main entry points are `electron/main/index.ts`, `electron/preload/index.ts`, and `src/main.tsx`.

#### Process Boundary and IPC
Electron main owns window lifecycle, folder/file access, atomic disk writes, and requests to translation providers in `electron/main/index.ts`, `electron/main/aiService.ts`, and `electron/main/freeTranslationService.ts`. The preload bridge in `electron/preload/index.ts` exposes a typed, constrained `window.electronAPI` contract defined by `src/types/electron.d.ts`; the React renderer does not directly use Node APIs or provider credentials.

#### Renderer Orchestration
`src/App.tsx` is the application-level coordinator for selected files, comparison state, settings, editing, translation actions, review, and refresh after writes. UI is organized around localization inspection and action surfaces: `src/components/localization/LocalizationTree.tsx`, `src/components/localization/LocalizationSummary.tsx`, and `src/components/settings/SettingsModal.tsx`. Review-oriented flows are separated into `src/components/localization/AiTranslationConfirmModal.tsx` and `src/components/localization/BatchTranslationModal.tsx`.

#### Localization Analysis Pipeline
JSON localization content is parsed into usable key representations by `src/services/localizationParser.ts`; `src/services/localizationComparator.ts` applies the union-of-keys comparison model across selected files, distinguishing missing paths from present-but-empty strings. Tree and navigation projections support hierarchical inspection and direct traversal of unresolved items through `src/services/localizationTree.ts` and `src/services/missingKeyNavigator.ts`. Core domain structures are centralized in `src/types/localization.ts`.

#### Editing and Persistence Safety
Manual edits, adding absent keys, and approved translation applications ultimately update the selected file through the Electron boundary. `src/services/localizationWriter.ts` owns JSON reconstruction/formatting and atomic-write semantics, while `src/components/localization/AddMissingKeysModal.tsx` provides the explicit missing-key insertion workflow. Writes are intentionally action-triggered; successful persistence should feed back into a fresh comparison state.

#### Translation Selection and Execution
Settings define the active engine, provider/model, credentials, endpoint, and review policy through `src/types/settings.ts` and `src/components/settings/SettingsModal.tsx`. Provider metadata/presets live in `src/services/aiProviderRegistry.ts` and `src/services/freeProviderRegistry.ts`. Main-process integrations target cloud AI providers, local Ollama, LibreTranslate endpoints, and MyMemory; no translation request is needed for normal file analysis.

#### Batch, Reliability, and Validation Controls
Single and batch AI flows are composed in `src/services/aiTranslation.ts` and `src/services/aiBatchTranslation.ts`. `src/services/aiBatchPlanner.ts` groups work by language pair/file, chunks requests, and supports splitting oversized batches; execution handles retry/backoff and partial failures. Every generated result crosses `src/services/aiResponseValidator.ts`, which enforces preservation of placeholders, formatting syntax, escape sequences, and HTML/XML markup before it can be reviewed or persisted. `src/services/aiEditPolicy.ts` determines whether validated proposals require user approval or may be applied directly.

Main entry points: [`electron/main/index.ts`](https://github.com/kimrenny/i18nh/blob/main/electron/main/index.ts) (Main process services), [`src/App.tsx`](https://github.com/kimrenny/i18nh/blob/main/src/App.tsx) (App coordinator), [`src/services/localizationComparator.ts`](https://github.com/kimrenny/i18nh/blob/main/src/services/localizationComparator.ts) (Union-key comparator), [`src/services/aiBatchTranslation.ts`](https://github.com/kimrenny/i18nh/blob/main/src/services/aiBatchTranslation.ts) (AI translation and batch execution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_renderer["React renderer"]
  node_app["App coordinator<br/>React orchestration<br/>[App.tsx]"]
  node_tree_ui["Localization tree<br/>inspection UI"]
  node_summary_ui["Localization summary<br/>inspection UI"]
  node_review_ui["Translation review modals<br/>review UI"]
  node_add_keys_ui["Add missing keys<br/>edit UI"]
  node_settings_ui["Settings modal<br/>settings UI<br/>[SettingsModal.tsx]"]
end

subgraph group_analysis["Localization analysis"]
  node_domain["Localization domain types<br/>TypeScript types<br/>[localization.ts]"]
  node_parser["JSON parser<br/>analysis service"]
  node_comparator["Union-key comparator<br/>analysis service"]
  node_projections["Tree and missing navigation<br/>analysis projections"]
  node_writer["Localization writer<br/>persistence service"]
end

subgraph group_translation["Translation workflow"]
  node_translation_flow["AI translation and batch execution<br/>translation service"]
  node_batch_planner["Batch planner<br/>translation planner<br/>[aiBatchPlanner.ts]"]
  node_validator["Response validator<br/>translation guard"]
  node_edit_policy["AI edit policy<br/>review policy<br/>[aiEditPolicy.ts]"]
  node_provider_registry["Provider registries<br/>provider metadata"]
end

subgraph group_electron["Electron main process"]
  node_preload{{"Typed preload bridge<br/>IPC bridge<br/>[index.ts]"}}
  node_main["Main process services<br/>Electron privileged runtime<br/>[index.ts]"]
  node_providers(("Translation providers<br/>external services"))
  node_files[("Localization JSON files<br/>filesystem data")]
end

node_app -->|"parses selected files"| node_parser
node_parser -->|"key representations"| node_comparator
node_domain -.->|"defines structures"| node_parser
node_domain -.->|"defines comparison state"| node_comparator
node_comparator -->|"comparison state"| node_projections
node_projections -->|"hierarchy and navigation"| node_tree_ui
node_comparator -->|"missing and empty status"| node_summary_ui
node_settings_ui -->|"selects engine and preset"| node_provider_registry
node_app -->|"translation work"| node_batch_planner
node_batch_planner -->|"grouped chunks"| node_translation_flow
node_provider_registry -->|"provider configuration"| node_translation_flow
node_translation_flow -->|"generated proposals"| node_validator
node_validator -->|"validated results"| node_edit_policy
node_edit_policy -->|"approval required"| node_review_ui
node_review_ui -->|"approved translations"| node_writer
node_add_keys_ui -->|"insert absent keys"| node_writer
node_app -->|"typed IPC calls"| node_preload
node_writer -->|"write request"| node_preload
node_translation_flow -->|"translation request"| node_preload
node_preload -->|"constrained IPC"| node_main
node_main -->|"read and atomic write"| node_files
node_main -->|"provider network requests"| node_providers
node_files -->|"selected JSON content"| node_parser
node_main -.->|"write completion triggers refresh"| node_app

click node_app "https://github.com/kimrenny/i18nh/blob/main/src/App.tsx"
click node_tree_ui "https://github.com/kimrenny/i18nh/blob/main/src/components/localization/LocalizationTree.tsx"
click node_summary_ui "https://github.com/kimrenny/i18nh/blob/main/src/components/localization/LocalizationSummary.tsx"
click node_review_ui "https://github.com/kimrenny/i18nh/blob/main/src/components/localization/AiTranslationConfirmModal.tsx"
click node_add_keys_ui "https://github.com/kimrenny/i18nh/blob/main/src/components/localization/AddMissingKeysModal.tsx"
click node_settings_ui "https://github.com/kimrenny/i18nh/blob/main/src/components/settings/SettingsModal.tsx"
click node_domain "https://github.com/kimrenny/i18nh/blob/main/src/types/localization.ts"
click node_parser "https://github.com/kimrenny/i18nh/blob/main/src/services/localizationParser.ts"
click node_comparator "https://github.com/kimrenny/i18nh/blob/main/src/services/localizationComparator.ts"
click node_projections "https://github.com/kimrenny/i18nh/blob/main/src/services/localizationTree.ts"
click node_writer "https://github.com/kimrenny/i18nh/blob/main/src/services/localizationWriter.ts"
click node_translation_flow "https://github.com/kimrenny/i18nh/blob/main/src/services/aiBatchTranslation.ts"
click node_batch_planner "https://github.com/kimrenny/i18nh/blob/main/src/services/aiBatchPlanner.ts"
click node_validator "https://github.com/kimrenny/i18nh/blob/main/src/services/aiResponseValidator.ts"
click node_edit_policy "https://github.com/kimrenny/i18nh/blob/main/src/services/aiEditPolicy.ts"
click node_provider_registry "https://github.com/kimrenny/i18nh/blob/main/src/services/aiProviderRegistry.ts"
click node_preload "https://github.com/kimrenny/i18nh/blob/main/electron/preload/index.ts"
click node_main "https://github.com/kimrenny/i18nh/blob/main/electron/main/index.ts"

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_app,node_tree_ui,node_summary_ui,node_review_ui,node_add_keys_ui,node_settings_ui toneBlue
class node_domain,node_parser,node_comparator,node_projections,node_writer toneAmber
class node_translation_flow,node_batch_planner,node_validator,node_edit_policy,node_provider_registry toneMint
class node_preload,node_main,node_providers,node_files toneRose
```

## Components

### React renderer

Unprivileged UI and client-side orchestration.

- [App coordinator](https://github.com/kimrenny/i18nh/blob/main/src/App.tsx): React orchestration · Coordinates selection, edits, translations, review, and refresh. · `src/App.tsx`
- [Localization tree](https://github.com/kimrenny/i18nh/blob/main/src/components/localization/LocalizationTree.tsx): inspection UI · `src/components/localization/LocalizationTree.tsx`
- [Localization summary](https://github.com/kimrenny/i18nh/blob/main/src/components/localization/LocalizationSummary.tsx): inspection UI · `src/components/localization/LocalizationSummary.tsx`
- [Translation review modals](https://github.com/kimrenny/i18nh/blob/main/src/components/localization/AiTranslationConfirmModal.tsx): review UI · Confirms single and batch translation proposals. · `src/components/localization/AiTranslationConfirmModal.tsx`
- [Add missing keys](https://github.com/kimrenny/i18nh/blob/main/src/components/localization/AddMissingKeysModal.tsx): edit UI · `src/components/localization/AddMissingKeysModal.tsx`
- [Settings modal](https://github.com/kimrenny/i18nh/blob/main/src/components/settings/SettingsModal.tsx): settings UI · Configures engine, provider, credentials, endpoint, and review policy. · `src/components/settings/SettingsModal.tsx`

### Localization analysis

Comparison and inspection pipeline.

- [Localization domain types](https://github.com/kimrenny/i18nh/blob/main/src/types/localization.ts): TypeScript types · `src/types/localization.ts`
- [JSON parser](https://github.com/kimrenny/i18nh/blob/main/src/services/localizationParser.ts): analysis service · Builds usable localization key representations. · `src/services/localizationParser.ts`
- [Union-key comparator](https://github.com/kimrenny/i18nh/blob/main/src/services/localizationComparator.ts): analysis service · Separates missing paths from present empty strings. · `src/services/localizationComparator.ts`
- [Tree and missing navigation](https://github.com/kimrenny/i18nh/blob/main/src/services/localizationTree.ts): analysis projections · Supports hierarchy inspection and unresolved-item traversal. · `src/services/localizationTree.ts`
- [Localization writer](https://github.com/kimrenny/i18nh/blob/main/src/services/localizationWriter.ts): persistence service · Reconstructs and formats JSON for atomic persistence. · `src/services/localizationWriter.ts`

### Translation workflow

Planning, validation, policy, and provider selection.

- [AI translation and batch execution](https://github.com/kimrenny/i18nh/blob/main/src/services/aiBatchTranslation.ts): translation service · Runs single and batch requests with retry, backoff, and partial-failure handling. · `src/services/aiBatchTranslation.ts`
- [Batch planner](https://github.com/kimrenny/i18nh/blob/main/src/services/aiBatchPlanner.ts): translation planner · Groups by language pair/file and chunks or splits oversized work. · `src/services/aiBatchPlanner.ts`
- [Response validator](https://github.com/kimrenny/i18nh/blob/main/src/services/aiResponseValidator.ts): translation guard · Preserves placeholders, syntax, escapes, and markup. · `src/services/aiResponseValidator.ts`
- [AI edit policy](https://github.com/kimrenny/i18nh/blob/main/src/services/aiEditPolicy.ts): review policy · Decides whether validated proposals need approval. · `src/services/aiEditPolicy.ts`
- [Provider registries](https://github.com/kimrenny/i18nh/blob/main/src/services/aiProviderRegistry.ts): provider metadata · Contains AI and free-provider presets. · `src/services/aiProviderRegistry.ts`

### Electron main process

Privileged filesystem and network boundary.

- [Typed preload bridge](https://github.com/kimrenny/i18nh/blob/main/electron/preload/index.ts): IPC bridge · Exposes constrained window.electronAPI to the renderer. · `electron/preload/index.ts`
- [Main process services](https://github.com/kimrenny/i18nh/blob/main/electron/main/index.ts): Electron privileged runtime · Owns windows, filesystem access, atomic writes, and provider requests. · `electron/main/index.ts`
- **Translation providers**: external services · Cloud AI, Ollama, LibreTranslate, and MyMemory.
- **Localization JSON files**: filesystem data

## Connections

- App coordinator → JSON parser: parses selected files
- JSON parser → Union-key comparator: key representations
- Localization domain types → JSON parser: defines structures
- Localization domain types → Union-key comparator: defines comparison state
- Union-key comparator → Tree and missing navigation: comparison state
- Tree and missing navigation → Localization tree: hierarchy and navigation
- Union-key comparator → Localization summary: missing and empty status
- Settings modal → Provider registries: selects engine and preset
- App coordinator → Batch planner: translation work
- Batch planner → AI translation and batch execution: grouped chunks
- Provider registries → AI translation and batch execution: provider configuration
- AI translation and batch execution → Response validator: generated proposals
- Response validator → AI edit policy: validated results
- AI edit policy → Translation review modals: approval required
- Translation review modals → Localization writer: approved translations
- Add missing keys → Localization writer: insert absent keys
- App coordinator → Typed preload bridge: typed IPC calls
- Localization writer → Typed preload bridge: write request
- AI translation and batch execution → Typed preload bridge: translation request
- Typed preload bridge → Main process services: constrained IPC
- Main process services → Localization JSON files: read and atomic write
- Main process services → Translation providers: provider network requests
- Localization JSON files → JSON parser: selected JSON content
- Main process services → App coordinator: write completion triggers refresh
