# jhuow/openmathpix architecture

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

- Interactive diagram: https://gitdiagram.com/jhuow/openmathpix
- Repository: https://github.com/jhuow/openmathpix

## Overview

OpenMathpix is an Electron desktop snipping and OCR application. Users capture or paste an image, send it to a configured PaddleOCR pipeline, view LaTeX/Markdown/text or the original image, and can revisit saved results in History. Settings configure the endpoint, pipeline, output format, theme, and hotkey. The graph separates renderer UI, capture, main-process coordination, OCR integration, and persistence. Edges follow shown calls and documented workflow; some renderer-to-main links are evidenced by IPC usage rather than a directly shown end-to-end call.

Main entry points: [`src/renderer/App.tsx`](https://github.com/jhuow/openmathpix/blob/master/src/renderer/App.tsx) (App shell), [`src/renderer/hooks/useOCR.ts`](https://github.com/jhuow/openmathpix/blob/master/src/renderer/hooks/useOCR.ts) (Recognition flow), [`src/main/capture.ts`](https://github.com/jhuow/openmathpix/blob/master/src/main/capture.ts) (Screen capture), [`src/main/ipc.ts`](https://github.com/jhuow/openmathpix/blob/master/src/main/ipc.ts) (IPC handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_renderer["Renderer UI"]
  node_app["App shell<br/>[App.tsx]"]
  node_toolbar["Toolbar<br/>[Toolbar.tsx]"]
  node_status["Status bar<br/>[StatusBar.tsx]"]
  node_ocrflow["Recognition flow<br/>[useOCR.ts]"]
  node_result["Result tabs<br/>[SnipResult.tsx]"]
  node_preview["Format preview<br/>[Preview.tsx]"]
  node_settingsui["Settings page<br/>[Settings.tsx]"]
  node_historyui["History page<br/>[History.tsx]"]
  node_uistate["UI state<br/>[store.ts]"]
end

subgraph group_capture["Screen Capture"]
  node_overlay["Selection overlay<br/>[overlay.ts]"]
  node_capture["Screen capture<br/>[capture.ts]"]
end

subgraph group_main["Main Process"]
  node_mainapp["Electron coordinator<br/>[index.ts]"]
  node_bridge["Preload API<br/>[index.ts]"]
  node_handlers["IPC handlers<br/>[ipc.ts]"]
  node_types["Shared IPC types<br/>[types.ts]"]
end

subgraph group_recognition["OCR Recognition"]
  node_ocrservice["PaddleOCR client<br/>[paddleocr.ts]"]
  node_provider{{"PaddleOCR endpoint"}}
end

subgraph group_persistence["Settings and History"]
  node_settings[("Encrypted settings<br/>[store.ts]")]
  node_history[("Recognition history<br/>[db.ts]")]
end

node_user(("Desktop user"))

node_user -.->|"starts snip"| node_toolbar
node_user -.->|"pastes image"| node_ocrflow
node_toolbar -.->|"requests snip"| node_capture
node_mainapp -->|"starts snip"| node_capture
node_capture -->|"sends screen data"| node_overlay
node_overlay -->|"sends selection"| node_capture
node_capture -->|"sends captured image"| node_ocrflow
node_app -->|"uses recognition"| node_ocrflow
node_app -->|"renders"| node_toolbar
node_app -->|"renders"| node_status
node_app -->|"renders"| node_result
node_app -->|"renders"| node_settingsui
node_app -->|"renders"| node_historyui
node_result -->|"renders"| node_preview
node_ocrflow -->|"updates results"| node_uistate
node_ocrflow -->|"invokes recognition"| node_bridge
node_bridge -.->|"dispatches IPC"| node_handlers
node_handlers -->|"calls recognition"| node_ocrservice
node_ocrservice -->|"posts image"| node_provider
node_handlers -->|"reads settings"| node_settings
node_handlers -->|"saves and queries"| node_history
node_settingsui -.->|"uses settings API"| node_bridge
node_historyui -.->|"uses history API"| node_bridge
node_mainapp -->|"loads settings"| node_settings
node_mainapp -->|"initializes history"| node_history

click node_app "https://github.com/jhuow/openmathpix/blob/master/src/renderer/App.tsx"
click node_toolbar "https://github.com/jhuow/openmathpix/blob/master/src/renderer/components/Toolbar.tsx"
click node_status "https://github.com/jhuow/openmathpix/blob/master/src/renderer/components/StatusBar.tsx"
click node_ocrflow "https://github.com/jhuow/openmathpix/blob/master/src/renderer/hooks/useOCR.ts"
click node_result "https://github.com/jhuow/openmathpix/blob/master/src/renderer/pages/SnipResult.tsx"
click node_preview "https://github.com/jhuow/openmathpix/blob/master/src/renderer/components/Preview.tsx"
click node_settingsui "https://github.com/jhuow/openmathpix/blob/master/src/renderer/pages/Settings.tsx"
click node_historyui "https://github.com/jhuow/openmathpix/blob/master/src/renderer/pages/History.tsx"
click node_uistate "https://github.com/jhuow/openmathpix/blob/master/src/renderer/store.ts"
click node_overlay "https://github.com/jhuow/openmathpix/blob/master/src/renderer/overlay.ts"
click node_capture "https://github.com/jhuow/openmathpix/blob/master/src/main/capture.ts"
click node_mainapp "https://github.com/jhuow/openmathpix/blob/master/src/main/index.ts"
click node_bridge "https://github.com/jhuow/openmathpix/blob/master/src/preload/index.ts"
click node_handlers "https://github.com/jhuow/openmathpix/blob/master/src/main/ipc.ts"
click node_types "https://github.com/jhuow/openmathpix/blob/master/src/shared/types.ts"
click node_ocrservice "https://github.com/jhuow/openmathpix/blob/master/src/services/paddleocr.ts"
click node_settings "https://github.com/jhuow/openmathpix/blob/master/src/main/store.ts"
click node_history "https://github.com/jhuow/openmathpix/blob/master/src/main/db.ts"

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_toolbar,node_status,node_ocrflow,node_result,node_preview,node_settingsui,node_historyui,node_uistate,node_user toneBlue
class node_overlay,node_capture toneAmber
class node_mainapp,node_bridge,node_handlers,node_types toneMint
class node_ocrservice,node_provider toneRose
class node_settings,node_history toneIndigo
```

## Components

### Renderer UI

- [App shell](https://github.com/jhuow/openmathpix/blob/master/src/renderer/App.tsx): `src/renderer/App.tsx`
- [Toolbar](https://github.com/jhuow/openmathpix/blob/master/src/renderer/components/Toolbar.tsx): `src/renderer/components/Toolbar.tsx`
- [Status bar](https://github.com/jhuow/openmathpix/blob/master/src/renderer/components/StatusBar.tsx): `src/renderer/components/StatusBar.tsx`
- [Recognition flow](https://github.com/jhuow/openmathpix/blob/master/src/renderer/hooks/useOCR.ts): `src/renderer/hooks/useOCR.ts`
- [Result tabs](https://github.com/jhuow/openmathpix/blob/master/src/renderer/pages/SnipResult.tsx): `src/renderer/pages/SnipResult.tsx`
- [Format preview](https://github.com/jhuow/openmathpix/blob/master/src/renderer/components/Preview.tsx): `src/renderer/components/Preview.tsx`
- [Settings page](https://github.com/jhuow/openmathpix/blob/master/src/renderer/pages/Settings.tsx): `src/renderer/pages/Settings.tsx`
- [History page](https://github.com/jhuow/openmathpix/blob/master/src/renderer/pages/History.tsx): `src/renderer/pages/History.tsx`
- [UI state](https://github.com/jhuow/openmathpix/blob/master/src/renderer/store.ts): `src/renderer/store.ts`

### Screen Capture

- [Selection overlay](https://github.com/jhuow/openmathpix/blob/master/src/renderer/overlay.ts): `src/renderer/overlay.ts`
- [Screen capture](https://github.com/jhuow/openmathpix/blob/master/src/main/capture.ts): `src/main/capture.ts`

### Main Process

- [Electron coordinator](https://github.com/jhuow/openmathpix/blob/master/src/main/index.ts): `src/main/index.ts`
- [Preload API](https://github.com/jhuow/openmathpix/blob/master/src/preload/index.ts): `src/preload/index.ts`
- [IPC handlers](https://github.com/jhuow/openmathpix/blob/master/src/main/ipc.ts): `src/main/ipc.ts`
- [Shared IPC types](https://github.com/jhuow/openmathpix/blob/master/src/shared/types.ts): `src/shared/types.ts`

### OCR Recognition

- [PaddleOCR client](https://github.com/jhuow/openmathpix/blob/master/src/services/paddleocr.ts): `src/services/paddleocr.ts`
- **PaddleOCR endpoint**

### Settings and History

- [Encrypted settings](https://github.com/jhuow/openmathpix/blob/master/src/main/store.ts): `src/main/store.ts`
- [Recognition history](https://github.com/jhuow/openmathpix/blob/master/src/main/db.ts): `src/main/db.ts`

### Other components

- **Desktop user**

## Connections

- Desktop user → Toolbar: starts snip (evidence: `README.md`)
- Desktop user → Recognition flow: pastes image (evidence: `README.md`)
- Toolbar → Screen capture: requests snip (evidence: `README.md`)
- Electron coordinator → Screen capture: starts snip (evidence: `src/main/index.ts`)
- Screen capture → Selection overlay: sends screen data (evidence: `src/main/capture.ts`)
- Selection overlay → Screen capture: sends selection (evidence: `src/main/capture.ts`)
- Screen capture → Recognition flow: sends captured image (evidence: `src/main/capture.ts`)
- App shell → Recognition flow: uses recognition (evidence: `src/renderer/App.tsx`)
- App shell → Toolbar: renders (evidence: `src/renderer/App.tsx`)
- App shell → Status bar: renders (evidence: `src/renderer/App.tsx`)
- App shell → Result tabs: renders (evidence: `src/renderer/App.tsx`)
- App shell → Settings page: renders (evidence: `src/renderer/App.tsx`)
- App shell → History page: renders (evidence: `src/renderer/App.tsx`)
- Result tabs → Format preview: renders (evidence: `src/renderer/pages/SnipResult.tsx`)
- Recognition flow → UI state: updates results (evidence: `src/renderer/hooks/useOCR.ts`)
- Recognition flow → Preload API: invokes recognition (evidence: `src/renderer/hooks/useOCR.ts`)
- Preload API → IPC handlers: dispatches IPC
- IPC handlers → PaddleOCR client: calls recognition (evidence: `src/main/ipc.ts`)
- PaddleOCR client → PaddleOCR endpoint: posts image (evidence: `src/services/paddleocr.ts`)
- IPC handlers → Encrypted settings: reads settings (evidence: `src/main/ipc.ts`)
- IPC handlers → Recognition history: saves and queries (evidence: `src/main/ipc.ts`)
- Settings page → Preload API: uses settings API (evidence: `README.md`)
- History page → Preload API: uses history API (evidence: `README.md`)
- Electron coordinator → Encrypted settings: loads settings (evidence: `src/main/index.ts`)
- Electron coordinator → Recognition history: initializes history (evidence: `src/main/index.ts`)
