# thrishal12345/photo-text-editor architecture

> Architecture diagram of the GitHub repository thrishal12345/photo-text-editor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thrishal12345/photo-text-editor
- Repository: https://github.com/thrishal12345/photo-text-editor

## Overview

Photo Text Editor is a browser-only screenshot text editor. The main workflow loads an image, detects and groups text, analyzes its pixels, matches fonts, then lets the user edit and export a composited image. The README documents additional editing, replacement, undo/redo, and custom-font capabilities. Source excerpts show the app invoking OCR and font matching depending on pixel analysis; unsampled app details are represented only where documented, so some internal links use README evidence.

Main entry points: [`src/app.js`](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js) (Editor UI and workflow), [`src/ocr.js`](https://github.com/thrishal12345/photo-text-editor/blob/main/src/ocr.js) (OCR recognition), [`src/fontmatch.js`](https://github.com/thrishal12345/photo-text-editor/blob/main/src/fontmatch.js) (Font matching), [`src/fonts.js`](https://github.com/thrishal12345/photo-text-editor/blob/main/src/fonts.js) (Font candidates and uploads)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_editing["Editing experience"]
  node_app["Editor UI and workflow<br/>[app.js]"]
  node_image_input["Image input<br/>[app.js]"]
  node_text_editor["Line editing<br/>[app.js]"]
  node_find_replace["Find and replace<br/>[app.js]"]
  node_history["Undo and redo<br/>[app.js]"]
end

subgraph group_detection["Text detection"]
  node_ocr["OCR recognition<br/>[ocr.js]"]
  node_tesseract["Tesseract.js"]
  node_line_grouping["Word merge and lines<br/>[ocr.js]"]
end

subgraph group_matching["Pixel and font analysis"]
  node_pixel_analysis["Color, masks, alignment<br/>[analyze.js]"]
  node_erase["Text erasure<br/>[analyze.js]"]
  node_font_match["Font matching<br/>[fontmatch.js]"]
  node_font_catalog["Font candidates and uploads<br/>[fonts.js]"]
  node_google_fonts["Google Fonts"]
end

subgraph group_output["Image output"]
  node_canvas["Image canvas<br/>[app.js]"]
  node_render["Text rendering and composite<br/>[app.js]"]
  node_export["Copy and PNG export<br/>[app.js]"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_user -->|"uploads or pastes"| node_image_input
node_image_input -->|"loads image"| node_app
node_app -->|"requests detection"| node_ocr
node_ocr -->|"recognizes text"| node_tesseract
node_ocr -->|"groups words"| node_line_grouping
node_line_grouping -->|"returns lines"| node_app
node_app -->|"analyzes text pixels"| node_pixel_analysis
node_app -->|"matches fonts"| node_font_match
node_font_match -->|"uses metrics"| node_pixel_analysis
node_font_match -->|"tests candidates"| node_font_catalog
node_font_catalog -->|"loads font faces"| node_google_fonts
node_user -->|"edits detected lines"| node_text_editor
node_text_editor -->|"updates edit state"| node_app
node_user -->|"replaces text"| node_find_replace
node_find_replace -->|"updates matching lines"| node_app
node_user -->|"undoes or redoes"| node_history
node_history -->|"restores edits"| node_app
node_app -->|"erases old text"| node_erase
node_app -->|"draws source image"| node_canvas
node_app -->|"renders replacement"| node_render
node_render -->|"composites text"| node_canvas
node_user -->|"copies or downloads"| node_export
node_export -->|"exports result"| node_canvas

click node_app "https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js"
click node_image_input "https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js"
click node_text_editor "https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js"
click node_find_replace "https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js"
click node_history "https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js"
click node_ocr "https://github.com/thrishal12345/photo-text-editor/blob/main/src/ocr.js"
click node_line_grouping "https://github.com/thrishal12345/photo-text-editor/blob/main/src/ocr.js"
click node_pixel_analysis "https://github.com/thrishal12345/photo-text-editor/blob/main/src/analyze.js"
click node_erase "https://github.com/thrishal12345/photo-text-editor/blob/main/src/analyze.js"
click node_font_match "https://github.com/thrishal12345/photo-text-editor/blob/main/src/fontmatch.js"
click node_font_catalog "https://github.com/thrishal12345/photo-text-editor/blob/main/src/fonts.js"
click node_canvas "https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js"
click node_render "https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js"
click node_export "https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js"

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_image_input,node_text_editor,node_find_replace,node_history,node_user toneBlue
class node_ocr,node_tesseract,node_line_grouping toneAmber
class node_pixel_analysis,node_erase,node_font_match,node_font_catalog,node_google_fonts toneMint
class node_canvas,node_render,node_export toneRose
```

## Components

### Editing experience

- [Editor UI and workflow](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js): `src/app.js`
- [Image input](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js): `src/app.js`
- [Line editing](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js): `src/app.js`
- [Find and replace](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js): `src/app.js`
- [Undo and redo](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js): `src/app.js`

### Text detection

- [OCR recognition](https://github.com/thrishal12345/photo-text-editor/blob/main/src/ocr.js): `src/ocr.js`
- **Tesseract.js**
- [Word merge and lines](https://github.com/thrishal12345/photo-text-editor/blob/main/src/ocr.js): `src/ocr.js`

### Pixel and font analysis

- [Color, masks, alignment](https://github.com/thrishal12345/photo-text-editor/blob/main/src/analyze.js): `src/analyze.js`
- [Text erasure](https://github.com/thrishal12345/photo-text-editor/blob/main/src/analyze.js): `src/analyze.js`
- [Font matching](https://github.com/thrishal12345/photo-text-editor/blob/main/src/fontmatch.js): `src/fontmatch.js`
- [Font candidates and uploads](https://github.com/thrishal12345/photo-text-editor/blob/main/src/fonts.js): `src/fonts.js`
- **Google Fonts**

### Image output

- [Image canvas](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js): `src/app.js`
- [Text rendering and composite](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js): `src/app.js`
- [Copy and PNG export](https://github.com/thrishal12345/photo-text-editor/blob/main/src/app.js): `src/app.js`

### Other components

- **User**

## Connections

- User → Editor UI and workflow: uses (evidence: `README.md`)
- User → Image input: uploads or pastes (evidence: `README.md`)
- Image input → Editor UI and workflow: loads image (evidence: `src/app.js`)
- Editor UI and workflow → OCR recognition: requests detection (evidence: `src/app.js`)
- OCR recognition → Tesseract.js: recognizes text (evidence: `src/ocr.js`)
- OCR recognition → Word merge and lines: groups words (evidence: `README.md`)
- Word merge and lines → Editor UI and workflow: returns lines (evidence: `README.md`)
- Editor UI and workflow → Color, masks, alignment: analyzes text pixels (evidence: `README.md`)
- Editor UI and workflow → Font matching: matches fonts (evidence: `README.md`)
- Font matching → Color, masks, alignment: uses metrics (evidence: `src/fontmatch.js`)
- Font matching → Font candidates and uploads: tests candidates (evidence: `src/fontmatch.js`)
- Font candidates and uploads → Google Fonts: loads font faces (evidence: `src/fonts.js`)
- User → Line editing: edits detected lines (evidence: `README.md`)
- Line editing → Editor UI and workflow: updates edit state (evidence: `README.md`)
- User → Find and replace: replaces text (evidence: `README.md`)
- Find and replace → Editor UI and workflow: updates matching lines (evidence: `README.md`)
- User → Undo and redo: undoes or redoes (evidence: `README.md`)
- Undo and redo → Editor UI and workflow: restores edits (evidence: `README.md`)
- Editor UI and workflow → Text erasure: erases old text (evidence: `README.md`)
- Editor UI and workflow → Image canvas: draws source image (evidence: `src/app.js`)
- Editor UI and workflow → Text rendering and composite: renders replacement (evidence: `README.md`)
- Text rendering and composite → Image canvas: composites text (evidence: `README.md`)
- User → Copy and PNG export: copies or downloads (evidence: `README.md`)
- Copy and PNG export → Image canvas: exports result (evidence: `README.md`)
