# 13point5/gemini-cursor architecture

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

- Interactive diagram: https://gitdiagram.com/13point5/gemini-cursor
- Repository: https://github.com/13point5/gemini-cursor

## Overview

- Electron Main Process: Represented in files such as src/main.ts. This is the entry point, managing application lifecycles, window creation, and interprocess communication.
- Preload Scripts: Files like src/preload.ts are used for securely exposing limited APIs to the renderer processes.
- Renderer Processes/Frontend: There are separate renderer layers for the “controls” and “cursor” functionalities. Under src/apps/controls/ you see various React components (e.g., App.tsx, CursorControl.tsx, ControlTray.tsx, Logger.tsx, SidePanel.tsx) that build up the UI.
- Auxiliary Modules and Libraries: In the src/apps/controls/lib directory, you have modules handling media (audio-recorder, audio-streamer, worklets for audio-processing, vol-meter, etc.) and the multimodal live functionality (multimodal-live-client.ts).
- API Integration: The project leverages Google Gemini’s API as described in the README, so a clear node should indicate external API calls for the multimodal live features (see use-live-api hook and LiveAPIContext).
- Utility & Configuration: Configuration files (e.g., forge.config.ts, vite.*.config.ts, tsconfig.json) and environment declarations indicate build and runtime configurations.

##### Relationships and Interactions
- Renderer Processes to the Preload script, which safely channels between the two processes.
- That these components access shared contexts (e.g., LiveAPIContext) and hooks (e.g., use-live-api, use-media-stream-mux, etc.) that encapsulate business logic and media streaming functionalities.
- Relationship between UI components/hooks and the auxiliary libraries (found under src/apps/controls/lib), which perform tasks such as audio recording, live streaming, and worklet-based audio processing.
- An outward connection from the multimodal functionality (the Live API layer integrated via hooks and the LiveAPIContext) to the external Google Gemini API.

##### Architectural Patterns and Design Principles
- Electron Architecture: Clearly segment the Main process, Preload scripts, and Renderer processes to emphasize Electron’s security and separation responsibilities.
- Component-Based Design: For the frontend, underline the React-based, modular UI components.
- Modular Abstraction: Highlight the use of hooks, contexts, and library abstractions to manage media streams and API communications.

##### Relevant Technologies and Frameworks
- Electron (for the desktop application shell and system-level management).
- React with TypeScript (for the Frontend).
- Vite (for fast bundling and development).
- Google Gemini API (for multimodal AI features).
- Web Audio API elements and worklets integrated for audio processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Services Layer
    ext["Google Gemini API"]:::api

    %% Electron Layer
    subgraph "Electron Layer"
        main["Electron Main Process"]:::electron
        preload["Preload Scripts"]:::preload
        main -->|"creates"| preload
    end

    %% Renderer Layer
    subgraph "Renderer Layer"
        %% Controls Renderer Group
        subgraph "Controls Renderer"
            app["App Component"]:::ui
            cc["CursorControl Component"]:::ui
            ct["ControlTray Component"]:::ui
            logger["Logger Component"]:::ui
            side["SidePanel Component"]:::ui
            app -->|"includes"| cc
            app -->|"includes"| ct
            app -->|"includes"| logger
            app -->|"includes"| side

            %% Hooks & Context within Controls Renderer
            hook["use-live-api Hook"]:::api
            context["LiveAPIContext"]:::api
            app ---|"utilizes"| hook
            app ---|"utilizes"| context

            %% Auxiliary Modules & Libraries for Media Processing & Multimodal Features
            subgraph "Auxiliary Modules & Libraries"
                ar["audio-recorder Module"]:::aux
                as["audio-streamer Module"]:::aux
                awr["audioworklet-registry Module"]:::aux
                mlc["multimodal-live-client Module"]:::aux
                sl["store-logger Module"]:::aux
                utils["utils Module"]:::aux
                apw["audio-processing Worklet"]:::aux
                vm["vol-meter Worklet"]:::aux
            end
            %% Link hooks to Auxiliary Modules
            hook -->|"invokes"| mlc
            hook -->|"utilizes"| ar
            hook -->|"utilizes"| as
            hook -->|"utilizes"| awr
            hook -->|"utilizes"| sl
            hook -->|"utilizes"| utils
            hook -->|"invokes"| apw
            hook -->|"invokes"| vm

            %% Connection from Auxiliary Modules to External API (multimodal live)
            mlc -->|"connects"| ext
        end

        %% Cursor Renderer Group
        subgraph "Cursor Renderer"
            ctr["Cursor Controller"]:::ui
            ren["Cursor Renderer Entry"]:::ui
            ctr -->|"coordinates"| ren
        end

        %% Connections between Electron and Renderers via Preload
        preload -->|"channels data"| app
        preload -->|"channels data"| ctr
    end

    %% Configuration Files Layer
    subgraph "Configuration & Build"
        forge["forge.config.ts"]:::config
        tsconfig["tsconfig.json"]:::config
        viteMain["vite.main.config.ts"]:::config
        vitePreload["vite.preload.config.ts"]:::config
        viteRenderer["vite.renderer.config.ts"]:::config
    end

    %% Electron Main Process initiates Renderers
    main -->|"launches"| app
    main -->|"launches"| ctr

    %% UI Hooks interact with Configuration (indirectly) for runtime settings
    app ---|"reads"| tsconfig

    %% External API interaction from Controls through hooks
    hook -->|"calls"| ext

    %% Legend (as annotations)
    click main "https://github.com/13point5/gemini-cursor/blob/main/src/main.ts" "Main Process File"
    click preload "https://github.com/13point5/gemini-cursor/blob/main/src/preload.ts" "Preload Script File"
    
    click app "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/components/App.tsx" "App Component File"
    click cc "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/components/CursorControl.tsx" "CursorControl Component File"
    click ct "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/components/control-tray/ControlTray.tsx" "ControlTray Component File"
    click logger "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/components/logger/Logger.tsx" "Logger Component File"
    click side "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/components/side-panel/SidePanel.tsx" "SidePanel Component File"
    
    click ctr "https://github.com/13point5/gemini-cursor/blob/main/src/apps/cursor/controller.ts" "Cursor Controller File"
    click ren "https://github.com/13point5/gemini-cursor/blob/main/src/apps/cursor/renderer.ts" "Cursor Renderer Entry File"
    
    click ar "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/lib/audio-recorder.ts" "Audio Recorder Module"
    click as "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/lib/audio-streamer.ts" "Audio Streamer Module"
    click awr "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/lib/audioworklet-registry.ts" "Audio Worklet Registry Module"
    click mlc "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/lib/multimodal-live-client.ts" "Multimodal Live Client Module"
    click sl "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/lib/store-logger.ts" "Store Logger Module"
    click utils "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/lib/utils.ts" "Utils Module"
    click apw "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/lib/worklets/audio-processing.ts" "Audio Processing Worklet"
    click vm "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/lib/worklets/vol-meter.ts" "Vol-meter Worklet"

    click hook "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/hooks/use-live-api.ts" "use-live-api Hook File"
    click context "https://github.com/13point5/gemini-cursor/blob/main/src/apps/controls/contexts/LiveAPIContext.tsx" "LiveAPIContext File"
    
    click forge "https://github.com/13point5/gemini-cursor/blob/main/forge.config.ts" "Forge Configuration"
    click tsconfig "https://github.com/13point5/gemini-cursor/blob/main/tsconfig.json" "TypeScript Configuration"
    click viteMain "https://github.com/13point5/gemini-cursor/blob/main/vite.main.config.ts" "Vite Main Configuration"
    click vitePreload "https://github.com/13point5/gemini-cursor/blob/main/vite.preload.config.ts" "Vite Preload Configuration"
    click viteRenderer "https://github.com/13point5/gemini-cursor/blob/main/vite.renderer.config.ts" "Vite Renderer Configuration"

    %% Styles
    classDef electron fill:#F8B195,stroke:#333,stroke-width:2px;
    classDef preload fill:#F67280,stroke:#333,stroke-width:2px;
    classDef ui fill:#C06C84,stroke:#333,stroke-width:2px;
    classDef aux fill:#6C5B7B,stroke:#333,stroke-width:2px;
    classDef api fill:#355C7D,stroke:#333,stroke-width:2px,color:#fff;
    classDef config fill:#99B898,stroke:#333,stroke-width:2px;
    
    %% Legend (as a note)
    %% Legend:
    %% • Rectangles with pastel colors represent different layers:
    %%   - Electron Layer (orange): Main Process and Preload Scripts
    %%   - Renderer UI Components (purple): React Components & Cursor Renderer
    %%   - Auxiliary Modules (dark purple): Media Processing & Multimodal Libraries
    %%   - API & Hooks (blue): Google Gemini API integration and related hooks/contexts
    %%   - Configuration (green): Build and runtime configuration files
    %% • Arrows indicate data flow, component composition, or inter-process communication.
    %% • Dashed lines (if any) would normally indicate secure IPC channels.
```
