# pot-app/pot-desktop architecture

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

- Interactive diagram: https://gitdiagram.com/pot-app/pot-desktop
- Repository: https://github.com/pot-app/pot-desktop

## Overview

##### Project Type & Purpose
- The project is a Tauri desktop application that leverages a modern JavaScript/React-based frontend (found in the “src” directory) paired with a Rust backend (in the “src-tauri” directory).
- Its main purpose is to offer multi-functional translation services (selection, input, screenshot OCR/translation, external HTTP calls, etc.) as well as a plugin system to extend functionalities.

##### Main Components
- Frontend UI (React): This is implemented in the “src” directory. It includes components, hooks, internationalization (i18n), and window configuration (for display panels like Recognize, Translate, etc.).
- Tauri Backend (Rust): Located in “src-tauri”, this section includes various modules such as clipboard handling, screenshot capture, OCR services, and hotkey management. It acts as the system layer that interfaces with native components.
- External API Integration: As described in the README, the application supports many external translation/OCR services via HTTP endpoints and its built-in plugin system.
- Build & Deployment: Configuration files (e.g., package.json, tauri.conf.json, Dockerfiles in .github/actions) and scripts (in .scripts) highlight deployment pipelines and continuous integration.

##### Relationships & Interactions
- The user interacts with the UI, which is rendered by React components. User actions (e.g., text selection or triggering OCR) are passed to the Tauri backend via the Tauri API.
- The Tauri backend (Rust) then handles system-level actions like screenshot capture, interfacing with native OCR modules, and invoking external APIs.
- The “services” directories indicate a modular design where different translation/recognition services are abstracted as configurable modules. The plugin system is also built on top of these modules so that external extensions can be integrated seamlessly.
- There are clear communication paths between the frontend, the Tauri backend, and external endpoints when interacting via HTTP interfaces (for external application calls).

##### Architectural Patterns & Design Principles
- Separation of Concerns: The project distinguishes clearly between the frontend (UI built in React) and system/backend functionality (managed by Rust/Tauri).
- Modular & Extensible: With separated directories for different service integrations (translate, recognize, etc.), the design is modular. The plugin system further extends this by allowing external modules to plug into the core service logic.
- Cross-Platform & Native Integration: Leveraging Tauri’s capabilities ensures that the application is truly cross-platform while taking advantage of platform-specific features (e.g., WebView2 on Windows, Apple Vision on Mac, Tesseract on Linux).

##### Final Recommendation
- The separation between the UI (built using React) and the Tauri backend (Rust code).
- The modular approach to handling translation and OCR functionalities.
- The integration points for external services and plugin extensions.
- The directions of communication and dependencies between these components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User (Actions)"]:::external
    B["Frontend UI (React)"]:::frontend
    C["Tauri Backend (Rust)"]:::backend

    subgraph "Service Modules"
        D1["Translation Service Modules"]:::service
        D2["Recognition (OCR) Service Modules"]:::service
        D3["TTS Service Module"]:::service
        D4["Collection Service Module"]:::service
        D5["Plugin System Interface"]:::service
    end

    E["External APIs/Endpoints"]:::external
    F["Build & Deployment Configuration"]:::deployment

    A -->|"interacts"| B
    B -->|"calls"| C
    C -->|"invokes"| D1
    C -->|"invokes"| D2
    C -->|"invokes"| D3
    C -->|"invokes"| D4
    C -->|"invokes"| D5

    D1 -->|"HTTP_call"| E
    D2 -->|"HTTP_call"| E
    D3 -->|"HTTP_call"| E
    D4 -->|"HTTP_call"| E
    D5 -->|"plugin_integ"| E

    F -->|"builds_deploys"| B
    F -->|"builds_deploys"| C
    F -->|"builds_deploys"| D1
    F -->|"builds_deploys"| D2
    F -->|"builds_deploys"| D3
    F -->|"builds_deploys"| D4
    F -->|"builds_deploys"| D5

    %% Click Events
    click B "https://github.com/pot-app/pot-desktop/tree/master/src/"
    click C "https://github.com/pot-app/pot-desktop/tree/master/src-tauri/"
    click D1 "https://github.com/pot-app/pot-desktop/tree/master/src/services/translate/"
    click D2 "https://github.com/pot-app/pot-desktop/tree/master/src/services/recognize/"
    click D3 "https://github.com/pot-app/pot-desktop/tree/master/src/services/tts/"
    click D4 "https://github.com/pot-app/pot-desktop/tree/master/src/services/collection/"
    click D5 "https://github.com/pot-app/pot-desktop/tree/master/src/window/Config/pages/Service/PluginConfig"
    click D5 "https://github.com/pot-app/pot-desktop/blob/master/src/utils/invoke_plugin.js"
    click F "https://github.com/pot-app/pot-desktop/tree/master/.github/actions/"
    click F "https://github.com/pot-app/pot-desktop/tree/master/.github/workflows/"
    click F "https://github.com/pot-app/pot-desktop/blob/master/package.json"
    click F "https://github.com/pot-app/pot-desktop/tree/master/.scripts/"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#00796B,stroke-width:2px;
    classDef backend fill:#E1F5FE,stroke:#0277BD,stroke-width:2px;
    classDef service fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef deployment fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
```
