# nextai-translator/nextai-translator architecture

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

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

## Overview

NextAI Translator is a cross-platform translation and writing assistant delivered as a browser extension and a Tauri desktop app. Users submit selected or entered text, then use translation, polishing, or summarization, with results supporting streaming and speech; screenshot translation is a separate desktop path. Shared components provide provider-specific LLM requests, settings, language support, and persisted history and vocabulary. The README documents additional capabilities and providers beyond the sampled code; those branches are shown where useful, but unsampled implementation links are left unverified.

Main entry points: [`src/common/components/Translator.tsx`](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/components/Translator.tsx) (Translator interface), [`src/tauri/App.tsx`](https://github.com/nextai-translator/nextai-translator/blob/main/src/tauri/App.tsx) (Desktop window router), [`src/tauri/components/Window.tsx`](https://github.com/nextai-translator/nextai-translator/blob/main/src/tauri/components/Window.tsx) (Window shell), [`src-tauri/src/ocr.rs`](https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/ocr.rs) (Screenshot OCR)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User interfaces"]
  node_browser["Browser extension UI<br/>[index.tsx]"]
  node_browser_bg["Extension background<br/>[index.ts]"]
  node_translator["Translator interface<br/>[Translator.tsx]"]
  node_settings["Settings<br/>[Settings.tsx]"]
  node_actions["Custom actions<br/>[ActionManager.tsx]"]
end

subgraph group_desktop["Desktop runtime"]
  node_desktop_app["Desktop window router<br/>[App.tsx]"]
  node_desktop_window["Window shell<br/>[Window.tsx]"]
  node_ocr["Screenshot OCR<br/>[ocr.rs]"]
  node_window_ops["Native window control<br/>[windows.rs]"]
  node_native_insert["Text insertion<br/>[insertion.rs]"]
  node_writing["Writing assistance<br/>[writing.rs]"]
  node_native_config["Desktop configuration<br/>[config.rs]"]
  node_bindings["Tauri command bindings<br/>[bindings.ts]"]
end

subgraph group_language["Language services"]
  node_translate["Translation orchestration<br/>[translate.ts]"]
  node_llm["LLM request engine<br/>[abstract-openai.ts]"]
  node_provider_engines["Provider engines"]
  node_language_support["Language catalog<br/>[index.ts]"]
  node_speech["Text to speech<br/>[index.ts]"]
end

subgraph group_state["User data"]
  node_settings_hook["Settings access<br/>[useSettings.ts]"]
  node_theme_hook["Theme access<br/>[useTheme.ts]"]
  node_history[("Translation history<br/>[history.ts]")]
  node_vocabulary[("Vocabulary book<br/>[vocabulary.ts]")]
end

subgraph group_integrations["External services"]
  node_provider{{"LLM providers"}}
  node_tts_service{{"Speech service"}}
end

node_user(("User"))

node_user -->|"selects text"| node_browser
node_browser -->|"renders"| node_translator
node_browser_bg -->|"uses service"| node_history
node_browser_bg -->|"uses service"| node_vocabulary
node_user -->|"opens desktop"| node_desktop_app
node_desktop_app -->|"routes windows"| node_desktop_window
node_desktop_window -->|"reads theme"| node_theme_hook
node_desktop_window -->|"invokes commands"| node_bindings
node_translator -.->|"requests translation"| node_translate
node_translate -.->|"requests completion"| node_llm
node_llm -.->|"dispatches requests"| node_provider_engines
node_provider_engines -.->|"calls provider"| node_provider
node_settings -.->|"reads settings"| node_settings_hook
node_settings_hook -.->|"loads desktop config"| node_native_config
node_translator -.->|"selects language"| node_language_support
node_translator -.->|"speaks results"| node_speech
node_speech -.->|"synthesizes speech"| node_tts_service
node_user -.->|"requests screenshot translation"| node_ocr
node_ocr -->|"inserts recognized text"| node_native_insert
node_ocr -->|"uses windows"| node_window_ops
node_desktop_app -->|"creates windows"| node_window_ops
node_user -.->|"configures actions"| node_actions
node_actions -.->|"stores history"| node_history
node_user -.->|"requests polishing"| node_writing
node_user -.->|"reviews translations"| node_history
node_user -.->|"collects words"| node_vocabulary

click node_browser "https://github.com/nextai-translator/nextai-translator/blob/main/src/browser-extension/content_script/index.tsx"
click node_browser_bg "https://github.com/nextai-translator/nextai-translator/blob/main/src/browser-extension/background/index.ts"
click node_desktop_app "https://github.com/nextai-translator/nextai-translator/blob/main/src/tauri/App.tsx"
click node_desktop_window "https://github.com/nextai-translator/nextai-translator/blob/main/src/tauri/components/Window.tsx"
click node_translator "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/components/Translator.tsx"
click node_settings "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/components/Settings.tsx"
click node_actions "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/components/ActionManager.tsx"
click node_translate "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/translate.ts"
click node_llm "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/engines/abstract-openai.ts"
click node_provider_engines "https://github.com/nextai-translator/nextai-translator/tree/main/src/common/engines"
click node_language_support "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/lang/index.ts"
click node_speech "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/tts/index.ts"
click node_ocr "https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/ocr.rs"
click node_window_ops "https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/windows.rs"
click node_native_insert "https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/insertion.rs"
click node_writing "https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/writing.rs"
click node_native_config "https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/config.rs"
click node_bindings "https://github.com/nextai-translator/nextai-translator/blob/main/src/tauri/bindings.ts"
click node_settings_hook "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/hooks/useSettings.ts"
click node_theme_hook "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/hooks/useTheme.ts"
click node_history "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/internal-services/history.ts"
click node_vocabulary "https://github.com/nextai-translator/nextai-translator/blob/main/src/common/internal-services/vocabulary.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_browser,node_browser_bg,node_translator,node_settings,node_actions,node_user toneBlue
class node_desktop_app,node_desktop_window,node_ocr,node_window_ops,node_native_insert,node_writing,node_native_config,node_bindings toneAmber
class node_translate,node_llm,node_provider_engines,node_language_support,node_speech toneMint
class node_settings_hook,node_theme_hook,node_history,node_vocabulary toneRose
class node_provider,node_tts_service toneIndigo
```

## Components

### User interfaces

- [Browser extension UI](https://github.com/nextai-translator/nextai-translator/blob/main/src/browser-extension/content_script/index.tsx): `src/browser-extension/content_script/index.tsx`
- [Extension background](https://github.com/nextai-translator/nextai-translator/blob/main/src/browser-extension/background/index.ts): `src/browser-extension/background/index.ts`
- [Translator interface](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/components/Translator.tsx): `src/common/components/Translator.tsx`
- [Settings](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/components/Settings.tsx): `src/common/components/Settings.tsx`
- [Custom actions](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/components/ActionManager.tsx): `src/common/components/ActionManager.tsx`

### Desktop runtime

- [Desktop window router](https://github.com/nextai-translator/nextai-translator/blob/main/src/tauri/App.tsx): `src/tauri/App.tsx`
- [Window shell](https://github.com/nextai-translator/nextai-translator/blob/main/src/tauri/components/Window.tsx): `src/tauri/components/Window.tsx`
- [Screenshot OCR](https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/ocr.rs): `src-tauri/src/ocr.rs`
- [Native window control](https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/windows.rs): `src-tauri/src/windows.rs`
- [Text insertion](https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/insertion.rs): `src-tauri/src/insertion.rs`
- [Writing assistance](https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/writing.rs): `src-tauri/src/writing.rs`
- [Desktop configuration](https://github.com/nextai-translator/nextai-translator/blob/main/src-tauri/src/config.rs): `src-tauri/src/config.rs`
- [Tauri command bindings](https://github.com/nextai-translator/nextai-translator/blob/main/src/tauri/bindings.ts): `src/tauri/bindings.ts`

### Language services

- [Translation orchestration](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/translate.ts): `src/common/translate.ts`
- [LLM request engine](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/engines/abstract-openai.ts): `src/common/engines/abstract-openai.ts`
- [Provider engines](https://github.com/nextai-translator/nextai-translator/tree/main/src/common/engines): `src/common/engines`
- [Language catalog](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/lang/index.ts): `src/common/lang/index.ts`
- [Text to speech](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/tts/index.ts): `src/common/tts/index.ts`

### User data

- [Settings access](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/hooks/useSettings.ts): `src/common/hooks/useSettings.ts`
- [Theme access](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/hooks/useTheme.ts): `src/common/hooks/useTheme.ts`
- [Translation history](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/internal-services/history.ts): `src/common/internal-services/history.ts`
- [Vocabulary book](https://github.com/nextai-translator/nextai-translator/blob/main/src/common/internal-services/vocabulary.ts): `src/common/internal-services/vocabulary.ts`

### External services

- **LLM providers**
- **Speech service**

### Other components

- **User**

## Connections

- User → Browser extension UI: selects text (evidence: `README.md`)
- Browser extension UI → Translator interface: renders (evidence: `src/browser-extension/content_script/index.tsx`)
- Extension background → Translation history: uses service (evidence: `src/browser-extension/background/index.ts`)
- Extension background → Vocabulary book: uses service (evidence: `src/browser-extension/background/index.ts`)
- User → Desktop window router: opens desktop (evidence: `README.md`)
- Desktop window router → Window shell: routes windows (evidence: `src/tauri/App.tsx`)
- Window shell → Theme access: reads theme (evidence: `src/tauri/components/Window.tsx`)
- Window shell → Tauri command bindings: invokes commands (evidence: `src/tauri/components/Window.tsx`)
- Translator interface → Translation orchestration: requests translation
- Translation orchestration → LLM request engine: requests completion
- LLM request engine → Provider engines: dispatches requests (evidence: `src/common/engines/openrouter.ts`)
- Provider engines → LLM providers: calls provider
- Settings → Settings access: reads settings
- Settings access → Desktop configuration: loads desktop config
- Translator interface → Language catalog: selects language
- Translator interface → Text to speech: speaks results
- Text to speech → Speech service: synthesizes speech
- User → Screenshot OCR: requests screenshot translation
- Screenshot OCR → Text insertion: inserts recognized text (evidence: `src-tauri/src/ocr.rs`)
- Screenshot OCR → Native window control: uses windows (evidence: `src-tauri/src/ocr.rs`)
- Desktop window router → Native window control: creates windows
- User → Custom actions: configures actions
- Custom actions → Translation history: stores history
- User → Writing assistance: requests polishing
- User → Translation history: reviews translations (evidence: `README.md`)
- User → Vocabulary book: collects words (evidence: `README.md`)
