# xhoantran/open-interview-coder architecture

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

- Interactive diagram: https://gitdiagram.com/xhoantran/open-interview-coder
- Repository: https://github.com/xhoantran/open-interview-coder

## Overview

##### Project Type and Purpose
- This is a desktop, full‑stack Electron application combining:
- An Electron “main” process (Node.js) for OS integration – global shortcuts, stealth window, screenshot capture, AI calls.
- An Electron “renderer” process (React + TypeScript + Tailwind CSS + Radix UI) for the UI.
- External services: OpenAI API and Google Gemini API for AI‑powered problem extraction and solution generation.

##### File Structure Analysis
- Top‑level config and scripts (`.erb/configs`, `.erb/scripts`): build, lint, package, and notarize flows.
- `src/main/`: Electron main process – window helper, screenshot helper, shortcuts helper, IPC handlers, state manager, AI processors (`GeminiHandler`, `OpenAIHandler`).
- `src/renderer/`: React app – entrypoint (`index.tsx`), components, feature modules (queue, settings, solution), UI primitives, global CSS, store and utils.
- `src/preload.ts` + `src/renderer/preload.d.ts`: secure IPC bridge exposing limited APIs to renderer.
- `package.json` / build configs: Electron Forge/Webpack configs for packaging per OS.

##### Key Architectural Insights from README
- Stealth mode: invisible window, OS‑level screen capture evasion.
- Global shortcuts trigger IPC events in main.
- AI model selection and API key stored locally (no backend server).
- Pure local processing except outbound HTTP to AI services.
- Extensible LLM integration via `src/main/processor/*`.

##### Detail Guidance
- Preload IPC surface explicitly, since it’s a critical security boundary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% OS and File System
    subgraph "OS & File System"
        OS["Screen Recording Permissions"]:::osfs
        FS["Local File System (temp/config)"]:::osfs
    end

    %% Electron Main Process
    subgraph "Electron Main Process"
        MM["main.ts"]:::main
        SM["ShortcutsHelper"]:::main
        MW["MainWindowHelper"]:::main
        SH["ScreenshotHelper"]:::main
        PH["ProcessingHelper"]:::main
        IPC["ipcHandlers"]:::main
        STM["StateManager"]:::main
        subgraph "AI Processors"
            OAI["OpenAIHandler"]:::main
            GEM["GeminiHandler"]:::main
            IDX["index.ts"]:::main
        end
        PreloadMain["preload.ts"]:::main
    end

    %% IPC Boundary
    subgraph "IPC Boundary"
        BND["Preload (Main) ↔ Preload (Renderer)"]:::ipc
    end

    %% Electron Renderer Process
    subgraph "Electron Renderer Process"
        PreloadRenderer["preload.d.ts"]:::renderer
        Entrypoint["index.tsx"]:::renderer
        App["App.tsx"]:::renderer
        subgraph "UI Components"
            UIP["UI Primitives"]:::renderer
            SU["Shared Components"]:::renderer
        end
        subgraph "Features"
            Q["Queue Module"]:::renderer
            S["Settings Module"]:::renderer
            Sol["Solution Module"]:::renderer
        end
        Store["store.ts"]:::renderer
        Utils["utils.ts"]:::renderer
        CSS["global.css"]:::renderer
    end

    %% External Services
    subgraph "External AI Services"
        OpenAI["OpenAI REST API"]:::external
        Gemini["Google Gemini REST API"]:::external
    end

    %% Data Flows
    OS -->|"Global Shortcut"| SM
    SM -->|"Open Stealth Window"| MW
    SM -->|"Trigger Capture"| SH
    SH -->|"Save Image"| FS
    SH -->|"Forward Image"| PH
    PH -->|"Call OpenAI"| OAI
    PH -->|"Call Gemini"| Gemini
    OAI -->|"Response"| PH
    Gemini -->|"Response"| PH
    PH -->|"Update State"| STM
    STM -->|"Persist"| FS
    PH -->|"Notify"| IPC
    IPC -->|"via Preload"| BND
    BND -->|"expose API"| PreloadRenderer
    PreloadRenderer -->|"invoke"| Entrypoint
    Entrypoint -->|"render"| App
    App -->|"uses"| UIP
    App -->|"uses"| SU
    App -->|"renders"| Q
    App -->|"renders"| S
    App -->|"renders"| Sol
    Q -->|"dispatch/actions"| Store
    S -->|"dispatch/actions"| Store
    Sol -->|"dispatch/actions"| Store
    App -->|"calls"| Utils
    Q -->|"save settings"| IPC
    S -->|"save settings"| IPC

    %% Click Events
    click MM "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/main.ts"
    click SM "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/helper/ShortcutsHelper.ts"
    click MW "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/helper/MainWindowHelper.ts"
    click SH "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/helper/ScreenshotHelper.ts"
    click PH "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/helper/ProcessingHelper.ts"
    click IPC "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/ipcHandlers.ts"
    click STM "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/stateManager.ts"
    click OAI "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/processor/OpenAIHandler.ts"
    click GEM "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/processor/GeminiHandler.ts"
    click IDX "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/processor/index.ts"
    click PreloadMain "https://github.com/xhoantran/open-interview-coder/blob/main/src/main/preload.ts"
    click PreloadRenderer "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/preload.d.ts"
    click Entrypoint "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/index.tsx"
    click App "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/App.tsx"
    click UIP "https://github.com/xhoantran/open-interview-coder/tree/main/src/renderer/components/ui"
    click SU "https://github.com/xhoantran/open-interview-coder/tree/main/src/renderer/components"
    click Q "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/features/queue/index.tsx"
    click S "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/features/settings/index.tsx"
    click Sol "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/features/solution/index.tsx"
    click Store "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/lib/store.ts"
    click Utils "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/lib/utils.ts"
    click CSS "https://github.com/xhoantran/open-interview-coder/blob/main/src/renderer/global.css"

    %% Styles
    classDef main fill:#D0E8FF,stroke:#5B9BD5,color:#0B3D91;
    classDef renderer fill:#DBFFD6,stroke:#3AA655,color:#1D5E20;
    classDef external fill:#FFE2B3,stroke:#FF8C00,color:#A64D00;
    classDef osfs fill:#E0E0E0,stroke:#A0A0A0,color:#505050;
    classDef ipc fill:#F0D6FF,stroke:#C080FF,color:#602070;
```
