# qyzhg/prism architecture

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

- Interactive diagram: https://gitdiagram.com/qyzhg/prism
- Repository: https://github.com/qyzhg/prism

## Overview

1. **Overall shape**
   - This is a **desktop AI translation app** built with **Tauri**: a **Vue 3 + Vite frontend** for the UI and a **Rust backend** for OS integration, network calls, OCR, and persistence.
   - The app is cross-platform, with explicit backend modules for **Windows** and **macOS**, plus an **unsupported** fallback path.

2. **User interface layer**
   - The main UI lives under `src/` and is centered on `App.vue`, `main.js`, and a set of reusable components.
   - UI pieces are split into functional panels and modals: language selection, model selection, settings, history, hotkey recording, translation results, toolbar, and title bar.
   - This layer is responsible for collecting user input, showing translation/OCR results, and triggering backend actions through Tauri commands.

3. **Secondary overlay / capture UI**
   - `area-selector.html`, `src/AreaSelector.vue`, and `src/area-selector.js` indicate a separate **screen-region selection interface**.
   - That suggests a screenshot/OCR flow where the app can ask the user to choose an area of the screen before sending the image into the OCR pipeline.

4. **Tauri bridge and application boundary**
   - The backend is under `src-tauri/src/`, which is the main boundary between the desktop shell and Rust logic.
   - `commands.rs` is the likely command surface exposed to the frontend.
   - `app_state.rs` suggests shared runtime state that coordinates settings, API configuration, database access, and task execution across commands.

5. **Translation pipeline**
   - `translation.rs` and `http_client.rs` indicate the app sends text to an external AI model API, then returns translated text to the frontend.
   - The README says the app targets **OpenAI-compatible APIs** and mentions **Tencent Hunyuan-MT-7B** as the default translation model.
   - This is an online service boundary: translation depends on configured base URL and API key.

6. **OCR pipeline**
   - `ocr.rs` and `ocr_tasks.rs` represent the screenshot-to-text path.
   - The README identifies **Qwen3-VL-8B-Instruct** as the OCR/vision model, so OCR is not local image parsing but an API-backed vision-language call.
   - Typical flow is: capture or select screen region → process image → extract text → optionally translate → display result and store history.

7. **Local persistence**
   - `database.rs` plus the included SQLite artifacts show that the app keeps **local history/state in SQLite**.
   - The README explicitly says translation history is stored locally and not uploaded.
   - This persistence layer is the main local data boundary: user history, cached records, and possibly configuration metadata.

8. **Runtime coordination and limits**
   - `token_limits.rs` indicates the app tracks prompt/output size constraints for model calls.
   - `app_state.rs` and task modules imply the backend coordinates async work, API requests, and UI-triggered operations without blocking the desktop UI.
   - The project uses **Tokio** in the Rust runtime for concurrency.

9. **System integration**
   - `shortcuts.rs` and `system_tray.rs` show two key OS-facing subsystems: **global hotkeys** and a **tray menu / background presence**.
   - These are important entry points besides the main window: users can trigger actions from the tray or keyboard shortcuts without interacting with the full UI.
   - Platform-specific code under `src-tauri/src/platform/` handles OS differences and keeps those integrations isolated.

10. **Build, packaging, and release**
   - Frontend build is handled by **Vite**; backend build and desktop packaging are handled by **Cargo + Tauri**.
   - `tauri.conf.json` and `tauri.macos.conf.json` define desktop app packaging behavior, icons, and platform-specific settings.
   - `.github/workflows/release.yml` indicates automated release packaging/distribution.

11. **External service dependencies**
   - The app is designed around **remote model providers** rather than an embedded ML runtime.
   - The main external dependency is an **AI model API endpoint**; the README specifically references **SiliconFlow** as a provider and notes compatibility with other OpenAI-style services.
   - That means the architecture has a hard network boundary: UI and local state stay on-device, but translation/OCR requests go out to the configured API.

12. **Key architecture summary**
   - Frontend: Vue desktop UI + capture overlay.
   - Backend: Rust/Tauri command layer.
   - Services: translation and OCR over HTTP to external model APIs.
   - Local storage: SQLite for history.
   - OS integration: tray, shortcuts, and platform-specific support.
   - This makes the app a **local desktop orchestrator** around cloud AI services, with all sensitive history retained locally.

Main entry points: [`src-tauri/src/commands.rs`](https://github.com/qyzhg/prism/blob/main/src-tauri/src/commands.rs) (Commands), [`src-tauri/src/app_state.rs`](https://github.com/qyzhg/prism/blob/main/src-tauri/src/app_state.rs) (App state), [`src-tauri/src/ocr.rs`](https://github.com/qyzhg/prism/blob/main/src-tauri/src/ocr.rs) (OCR), [`src/App.vue`](https://github.com/qyzhg/prism/blob/main/src/App.vue) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app["App shell<br/>Vue/Tauri UI<br/>[App.vue]"]
  node_main_ui["Main UI<br/>Vue entry<br/>[main.js]"]
  node_panels["Panels<br/>UI components"]
  node_selector_overlay["Area selector<br/>capture overlay<br/>[area-selector.html]"]
  node_selector_logic["Selector logic<br/>overlay script<br/>[area-selector.js]"]
end

subgraph group_backend["Backend"]
  node_commands["Commands<br/>Tauri bridge<br/>[commands.rs]"]
  node_state["App state<br/>runtime state<br/>[app_state.rs]"]
  node_translation["Translation<br/>service flow<br/>[translation.rs]"]
  node_ocr["OCR<br/>vision flow<br/>[ocr.rs]"]
  node_ocr_tasks["OCR tasks<br/>async tasks<br/>[ocr_tasks.rs]"]
  node_http_client["HTTP client<br/>API client<br/>[http_client.rs]"]
  node_tray_shortcuts["Tray & hotkeys<br/>OS integration<br/>[system_tray.rs]"]
  node_platform["Platform layer<br/>OS adapters<br/>[mod.rs]"]
  node_token_limits["Token limits<br/>constraints<br/>[token_limits.rs]"]
end

subgraph group_external["External services"]
  node_database[("SQLite store<br/>local persistence<br/>[database.rs]")]
  node_models_api(("Model API<br/>remote AI service"))
end

subgraph group_build["Build & release"]
  node_release["Build & release<br/>packaging"]
end

node_main_ui -->|"mounts"| node_app
node_app -->|"uses"| node_panels
node_app -->|"opens"| node_selector_overlay
node_selector_overlay -->|"drives"| node_selector_logic
node_panels -->|"invokes"| node_commands
node_selector_logic -->|"invokes"| node_commands
node_commands -->|"reads/writes"| node_state
node_state -->|"orchestrates"| node_translation
node_state -->|"orchestrates"| node_ocr
node_ocr -->|"queues"| node_ocr_tasks
node_translation -->|"uses"| node_http_client
node_ocr -->|"uses"| node_http_client
node_http_client -->|"calls"| node_models_api
node_translation -->|"stores"| node_database
node_ocr -->|"stores"| node_database
node_commands -->|"exposes"| node_tray_shortcuts
node_tray_shortcuts -->|"adapts"| node_platform
node_state -->|"checks"| node_token_limits
node_release -.->|"builds"| node_main_ui
node_release -.->|"packages"| node_commands

click node_app "https://github.com/qyzhg/prism/blob/main/src/App.vue"
click node_main_ui "https://github.com/qyzhg/prism/blob/main/src/main.js"
click node_panels "https://github.com/qyzhg/prism/tree/main/src/components"
click node_selector_overlay "https://github.com/qyzhg/prism/blob/main/area-selector.html"
click node_selector_logic "https://github.com/qyzhg/prism/blob/main/src/area-selector.js"
click node_commands "https://github.com/qyzhg/prism/blob/main/src-tauri/src/commands.rs"
click node_state "https://github.com/qyzhg/prism/blob/main/src-tauri/src/app_state.rs"
click node_translation "https://github.com/qyzhg/prism/blob/main/src-tauri/src/translation.rs"
click node_ocr "https://github.com/qyzhg/prism/blob/main/src-tauri/src/ocr.rs"
click node_ocr_tasks "https://github.com/qyzhg/prism/blob/main/src-tauri/src/ocr_tasks.rs"
click node_http_client "https://github.com/qyzhg/prism/blob/main/src-tauri/src/http_client.rs"
click node_database "https://github.com/qyzhg/prism/blob/main/src-tauri/src/database.rs"
click node_tray_shortcuts "https://github.com/qyzhg/prism/blob/main/src-tauri/src/system_tray.rs"
click node_platform "https://github.com/qyzhg/prism/blob/main/src-tauri/src/platform/mod.rs"
click node_token_limits "https://github.com/qyzhg/prism/blob/main/src-tauri/src/token_limits.rs"

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_main_ui,node_panels,node_selector_overlay,node_selector_logic toneBlue
class node_commands,node_state,node_translation,node_ocr,node_ocr_tasks,node_http_client,node_tray_shortcuts,node_platform,node_token_limits toneAmber
class node_database,node_models_api toneMint
class node_release toneRose
```

## Components

### Frontend

Vue desktop UI and capture overlay

- [App shell](https://github.com/qyzhg/prism/blob/main/src/App.vue): Vue/Tauri UI · Main desktop application shell and composition root · `src/App.vue`
- [Main UI](https://github.com/qyzhg/prism/blob/main/src/main.js): Vue entry · Bootstraps the Vue app and mounts the desktop interface · `src/main.js`
- [Panels](https://github.com/qyzhg/prism/tree/main/src/components): UI components · Core interaction surfaces for input, settings, history, and results · `src/components`
- [Area selector](https://github.com/qyzhg/prism/blob/main/area-selector.html): capture overlay · Separate screen-region selection interface for OCR capture · `area-selector.html`
- [Selector logic](https://github.com/qyzhg/prism/blob/main/src/area-selector.js): overlay script · Overlay-specific frontend logic for region picking · `src/area-selector.js`

### Backend

Tauri command surface, services, and OS integration

- [Commands](https://github.com/qyzhg/prism/blob/main/src-tauri/src/commands.rs): Tauri bridge · Backend command surface invoked by the frontend · `src-tauri/src/commands.rs`
- [App state](https://github.com/qyzhg/prism/blob/main/src-tauri/src/app_state.rs): runtime state · Shared backend state for settings, API config, and coordination · `src-tauri/src/app_state.rs`
- [Translation](https://github.com/qyzhg/prism/blob/main/src-tauri/src/translation.rs): service flow · Text translation pipeline and request orchestration · `src-tauri/src/translation.rs`
- [OCR](https://github.com/qyzhg/prism/blob/main/src-tauri/src/ocr.rs): vision flow · Screenshot-to-text pipeline backed by model API calls · `src-tauri/src/ocr.rs`
- [OCR tasks](https://github.com/qyzhg/prism/blob/main/src-tauri/src/ocr_tasks.rs): async tasks · Background OCR job execution and coordination · `src-tauri/src/ocr_tasks.rs`
- [HTTP client](https://github.com/qyzhg/prism/blob/main/src-tauri/src/http_client.rs): API client · Shared outbound client for OpenAI-compatible model endpoints · `src-tauri/src/http_client.rs`
- [Tray & hotkeys](https://github.com/qyzhg/prism/blob/main/src-tauri/src/system_tray.rs): OS integration · Background presence and global keyboard entry points · `src-tauri/src/system_tray.rs`
- [Platform layer](https://github.com/qyzhg/prism/blob/main/src-tauri/src/platform/mod.rs): OS adapters · Windows, macOS, and unsupported platform-specific behavior · `src-tauri/src/platform/mod.rs`
- [Token limits](https://github.com/qyzhg/prism/blob/main/src-tauri/src/token_limits.rs): constraints · Prompt and output size management for model calls · `src-tauri/src/token_limits.rs`

### External services

Remote model APIs and local persistence boundary

- [SQLite store](https://github.com/qyzhg/prism/blob/main/src-tauri/src/database.rs): local persistence · Local history and app data storage · `src-tauri/src/database.rs`
- **Model API**: remote AI service · External translation and vision-model endpoint

### Build & release

Frontend, desktop packaging, and release automation

- **Build & release**: packaging · Vite frontend build, Tauri packaging, and release automation

## Connections

- Main UI → App shell: mounts · Vue entry renders the application shell
- App shell → Panels: uses · Shell composes the main UI panels and modals
- App shell → Area selector: opens · Shell can launch the region-selection overlay
- Area selector → Selector logic: drives · Overlay HTML is powered by dedicated frontend logic
- Panels → Commands: invokes · UI actions call backend commands through Tauri
- Selector logic → Commands: invokes · Overlay sends capture actions to backend commands
- Commands → App state: reads/writes · Commands coordinate through shared runtime state
- App state → Translation: orchestrates · State drives translation requests and configuration
- App state → OCR: orchestrates · State drives OCR capture and processing
- OCR → OCR tasks: queues · OCR work is executed asynchronously in background tasks
- Translation → HTTP client: uses · Translation sends outbound API requests through the shared client
- OCR → HTTP client: uses · OCR vision calls use the shared HTTP client
- HTTP client → Model API: calls · Outbound requests go to the configured model provider
- Translation → SQLite store: stores · Translated history is persisted locally
- OCR → SQLite store: stores · OCR/translation results can be persisted locally
- Commands → Tray & hotkeys: exposes · Backend command surface is reachable from tray and hotkeys
- Tray & hotkeys → Platform layer: adapts · OS integrations are specialized per platform
- App state → Token limits: checks · Request sizing is constrained before model calls
- Build & release → Main UI: builds · Frontend is built with Vite before packaging
- Build & release → Commands: packages · Rust/Tauri backend is packaged into the desktop app
