# xushengfeng/esearch architecture

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

- Interactive diagram: https://gitdiagram.com/xushengfeng/esearch
- Repository: https://github.com/xushengfeng/esearch

## Overview

##### Main Components
- Electron Main Process – This resides within the src/main/ directory (main.ts). It initializes the application, manages app lifecycle events, window creation, and coordinates inter-process communication (IPC) between the main process and the renderer processes.
- Renderer Processes – Found in the src/renderer/ folder, these include a variety of HTML and TypeScript modules. They represent different functional “windows” or “views” (e.g., clip, editor, recorder, photoEditor, screenShot, translate, and more). Each component is largely responsible for its own user interface and behavior.
- Shared Libraries and Services – The lib/ directory provides cross-cutting functionalities such as:
- IPC utilities (lib/ipc.ts) to streamline communication.
- Platform-specific integrations like “gtk-open-with” and “kde-open-with.”
- State management via lib/store (store.ts, renderStore.ts).
- Time formatting and translation modules (lib/translate/).
- Assets and Theming – The assets/ directory contains images, desktop files, logos, and other resource files needed for branding and some runtime configurations.

##### Relationships and Interactions
- Shared libraries underpin multiple modules—the state management service (lib/store) and translation utilities (lib/translate) are “support” components that feed data into respective UI panels.
- External services/libraries such as onnx runtime for AI functionalities, offline OCR models, FFmpeg for video processing, and third-party API integrations (for translation engines) should be indicated as external dependencies or “service nodes.”

##### Architectural Patterns and Design Principles
- The classic Electron dual-process model (Main vs. Renderer) is central. Mark the separation clearly.
- The project follows modular design principles by splitting functionalities into separate subdirectories in the renderer (e.g., different UIs for capture, clip editing, translation, etc.).
- Emphasis on IPC and shared libraries indicates a “service-oriented” approach inside the desktop app, where different JS/TS modules provide specialized functionalities.

##### Technologies, Frameworks, and Libraries
- Electron (as the underlying desktop framework).
- TypeScript – evidenced by the tsconfig files and .ts source files.
- Vite for bundling Electron’s renderer (electron.vite.config.ts).
- Onnx and FFmpeg – implied via the README (for AI models and recording conversion).
- Libraries for OCR and translation.
- Cross-platform UI elements and styling (the CSS files under src/renderer/css).

##### Final Steps
- A side layer for shared libraries and external dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Processes
    EP("Electron Main Process"):::core
    click EP "https://github.com/xushengfeng/esearch/blob/master/src/main/main.ts"

    %% Renderer Processes Subgraph
    subgraph "Renderer Processes"
        direction TB
        Clip("Clip Module"):::ui
        click Clip "https://github.com/xushengfeng/esearch/blob/master/src/renderer/clip/clip_window.ts"
        Editor("Editor Module"):::ui
        click Editor "https://github.com/xushengfeng/esearch/blob/master/src/renderer/editor/editor.ts"
        Recorder("Recorder Module"):::ui
        click Recorder "https://github.com/xushengfeng/esearch/blob/master/src/renderer/recorder/recorder.ts"
        PhotoEd("Photo Editor Module"):::ui
        click PhotoEd "https://github.com/xushengfeng/esearch/blob/master/src/renderer/photoEditor/photoEditor.ts"
        Screenshot("Screenshot Module"):::ui
        click Screenshot "https://github.com/xushengfeng/esearch/blob/master/src/renderer/screenShot/screenShot.ts"
        Translate("Translate Module"):::ui
        click Translate "https://github.com/xushengfeng/esearch/blob/master/src/renderer/translate/translate.ts"
        AIVision("AI Vision Module"):::ui
        click AIVision "https://github.com/xushengfeng/esearch/blob/master/src/renderer/aiVision/aiVision.ts"
    end

    %% Shared Libraries and Services
    subgraph "Shared Libraries"
        direction TB
        IPC("Shared IPC Utilities"):::shared
        click IPC "https://github.com/xushengfeng/esearch/blob/master/lib/ipc.ts"
        StateStore("State Management (Store)"):::shared
        click StateStore "https://github.com/xushengfeng/esearch/blob/master/lib/store/store.ts"
        RenderStore("State Management (RenderStore)"):::shared
        click RenderStore "https://github.com/xushengfeng/esearch/blob/master/lib/store/renderStore.ts"
        TransUtil("Shared Translation Utilities"):::shared
        click TransUtil "https://github.com/xushengfeng/esearch/blob/master/lib/translate/translate.ts"
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        OCR("OCR Service"):::external
        FFmpeg("FFmpeg"):::external
        TransAPI("Online Translation API"):::external
        Onnx("Onnx Runtime"):::external
    end

    %% Build and Configuration Tools
    subgraph "Build & Configuration"
        direction TB
        Builder("Electron Builder Config"):::config
        click Builder "https://github.com/xushengfeng/esearch/blob/master/electron-builder.config.js"
        Vite("Electron Vite Config"):::config
        click Vite "https://github.com/xushengfeng/esearch/blob/master/electron.vite.config.ts"
    end

    %% Assets and Theming
    Assets("Assets & Theming"):::asset
    click Assets "https://github.com/xushengfeng/esearch/tree/master/assets/"

    %% Relationships between Core and Renderer Processes (IPC)
    EP -->|"IPC"| Clip
    EP -->|"IPC"| Editor
    EP -->|"IPC"| Recorder
    EP -->|"IPC"| PhotoEd
    EP -->|"IPC"| Screenshot
    EP -->|"IPC"| Translate
    EP -->|"IPC"| AIVision

    %% Interaction between Renderer Modules and Shared IPC Utilities
    Clip -->|"IPC message"| IPC
    Editor -->|"IPC message"| IPC
    Recorder -->|"IPC message"| IPC
    PhotoEd -->|"IPC message"| IPC
    Screenshot -->|"IPC message"| IPC
    Translate -->|"IPC message"| IPC
    AIVision -->|"IPC message"| IPC

    %% Rendering modules using State Management
    Editor -->|"update state"| StateStore
    Recorder -->|"update state"| RenderStore

    %% Translation module using Shared Translation Utilities
    Translate -->|"translate"| TransUtil

    %% Renderer modules utilizing Assets for UI resources
    Editor -->|"load assets"| Assets

    %% External Dependencies interactions
    Screenshot -->|"OCR"| OCR
    Recorder -->|"recording"| FFmpeg
    Translate -->|"translate"| TransAPI
    AIVision -->|"AI inference"| Onnx

    %% Build & Configuration supporting core and renderer processes
    Builder -->|"build config"| EP
    Vite -->|"bundling"| Editor

    
    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef ui fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef shared fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#7D3C98,stroke-width:2px;
    classDef config fill:#F5B7B1,stroke:#CB4335,stroke-width:2px;
    classDef asset fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
