# khanhdocnope/tun architecture

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

- Interactive diagram: https://gitdiagram.com/khanhdocnope/tun
- Repository: https://github.com/khanhdocnope/tun

## Overview

Manga Studio Pro combines batch OCR/translation and text removal with a canvas-based typesetting studio, backed by serverless APIs and GPU processing. The documented page workflow runs from user-uploaded manga through OCR/translation and cleaning to editable/exportable output; async jobs support chapter-scale processing. The graph preserves the documented detection, masking, inpainting, and translation stages. Some backend and editor modules were not sampled, so their internal connections are limited to README claims or omitted where evidence was unavailable.

Main entry points: [`web-in-vercel/public/typeset/js/app.js`](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/app.js) (Typeset Studio), [`colab-backend/manga_cleaner.py`](https://github.com/khanhdocnope/tun/blob/main/colab-backend/manga_cleaner.py) (Inpainting Pipeline), [`web-in-vercel/public/batch-studio/app.js`](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/app.js) (Batch Studio), [`web-in-vercel/server.js`](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/server.js) (Web Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Studio Interfaces"]
  node_batch["Batch Studio<br/>[app.js]"]
  node_batch_ui["Batch UI<br/>[ui.js]"]
  node_batch_queue["Batch Queue<br/>[queue.js]"]
  node_batch_api["Batch API Client<br/>[api.js]"]
  node_batch_state["Batch State<br/>[state.js]"]
  node_batch_storage[("Batch Storage<br/>[storage.js]")]
end

subgraph group_web["Web API"]
  node_server["Web Server<br/>[server.js]"]
  node_vision["Vision API<br/>[ai-vision.js]"]
  node_gemini_helper["Gemini Helper<br/>[batch-helper.js]"]
  node_contract["Manga Contract<br/>[manga-contract.js]"]
  node_clean_api["Clean API<br/>[clean.js]"]
  node_jobs_api["Jobs API<br/>[jobs.js]"]
end

subgraph group_gpu["GPU Processing"]
  node_backend["GPU API Server<br/>[server.py]"]
  node_job_engine["Async Job Engine<br/>[job_engine.py]"]
  node_cleaner["Inpainting Pipeline<br/>[manga_cleaner.py]"]
  node_bubble_detect["Bubble Detection<br/>[bubble_detector.py]"]
  node_text_detect["Text Detection<br/>[text_detector.py]"]
  node_mask_logic["Mask Logic<br/>[mask_logic.py]"]
end

subgraph group_typeset["Typesetting"]
  node_typeset_app["Typeset Studio<br/>[app.js]"]
  node_canvas["Canvas Editor<br/>[canvas-editor.js]"]
  node_translator["Text Translator<br/>[translator.js]"]
  node_typeset_storage[("Typeset Storage<br/>[storage.js]")]
  node_web_lama["Browser Inpainter<br/>[web-lama.js]"]
end

node_reader(("Reader / Creator"))
node_gemini["Google Gemini"]

node_reader -->|"uses"| node_batch
node_batch -->|"starts jobs"| node_batch_queue
node_batch -->|"renders"| node_batch_ui
node_batch_ui -->|"invokes"| node_batch_api
node_batch_queue -->|"dispatches"| node_batch_api
node_batch_api -->|"persists"| node_batch_storage
node_batch -->|"calls API"| node_server
node_server -->|"routes"| node_vision
node_server -->|"routes"| node_clean_api
node_server -->|"routes"| node_jobs_api
node_vision -->|"uses"| node_gemini_helper
node_vision -->|"normalizes"| node_contract
node_gemini_helper -->|"requests vision"| node_gemini
node_clean_api -->|"proxies cleaning"| node_backend
node_jobs_api -->|"proxies jobs"| node_backend
node_backend -->|"dispatches jobs"| node_job_engine
node_backend -->|"requests cleaning"| node_cleaner
node_job_engine -->|"processes pages"| node_cleaner
node_cleaner -->|"detects bubbles"| node_bubble_detect
node_cleaner -->|"detects text"| node_text_detect
node_cleaner -->|"builds masks"| node_mask_logic
node_reader -->|"edits pages"| node_typeset_app
node_typeset_app -->|"edits canvas"| node_canvas
node_typeset_app -->|"translates text"| node_translator
node_typeset_app -->|"stores pages"| node_typeset_storage
node_typeset_app -->|"cleans locally"| node_web_lama
node_typeset_app -.->|"translates with"| node_gemini

click node_batch "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/app.js"
click node_batch_ui "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/ui.js"
click node_batch_queue "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/queue.js"
click node_batch_api "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/api.js"
click node_batch_state "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/state.js"
click node_batch_storage "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/storage.js"
click node_server "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/server.js"
click node_vision "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/ai-vision.js"
click node_gemini_helper "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/batch-helper.js"
click node_contract "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/manga-contract.js"
click node_clean_api "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/clean.js"
click node_jobs_api "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/jobs.js"
click node_backend "https://github.com/khanhdocnope/tun/blob/main/colab-backend/server.py"
click node_job_engine "https://github.com/khanhdocnope/tun/blob/main/colab-backend/job_engine.py"
click node_cleaner "https://github.com/khanhdocnope/tun/blob/main/colab-backend/manga_cleaner.py"
click node_bubble_detect "https://github.com/khanhdocnope/tun/blob/main/colab-backend/bubble_detector.py"
click node_text_detect "https://github.com/khanhdocnope/tun/blob/main/colab-backend/text_detector.py"
click node_mask_logic "https://github.com/khanhdocnope/tun/blob/main/colab-backend/mask_logic.py"
click node_typeset_app "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/app.js"
click node_canvas "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/canvas-editor.js"
click node_translator "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/translator.js"
click node_typeset_storage "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/storage.js"
click node_web_lama "https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/web-lama.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_batch,node_batch_ui,node_batch_queue,node_batch_api,node_batch_state,node_batch_storage toneBlue
class node_server,node_vision,node_gemini_helper,node_contract,node_clean_api,node_jobs_api toneAmber
class node_backend,node_job_engine,node_cleaner,node_bubble_detect,node_text_detect,node_mask_logic toneMint
class node_typeset_app,node_canvas,node_translator,node_typeset_storage,node_web_lama toneRose
class node_reader,node_gemini toneIndigo
```

## Components

### Studio Interfaces

- [Batch Studio](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/app.js): `web-in-vercel/public/batch-studio/app.js`
- [Batch UI](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/ui.js): `web-in-vercel/public/batch-studio/js/ui.js`
- [Batch Queue](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/queue.js): `web-in-vercel/public/batch-studio/js/queue.js`
- [Batch API Client](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/api.js): `web-in-vercel/public/batch-studio/js/api.js`
- [Batch State](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/state.js): `web-in-vercel/public/batch-studio/js/state.js`
- [Batch Storage](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/batch-studio/js/storage.js): `web-in-vercel/public/batch-studio/js/storage.js`

### Web API

- [Web Server](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/server.js): `web-in-vercel/server.js`
- [Vision API](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/ai-vision.js): `web-in-vercel/api/ai-vision.js`
- [Gemini Helper](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/batch-helper.js): `web-in-vercel/api/batch-helper.js`
- [Manga Contract](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/manga-contract.js): `web-in-vercel/api/manga-contract.js`
- [Clean API](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/clean.js): `web-in-vercel/api/clean.js`
- [Jobs API](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/api/jobs.js): `web-in-vercel/api/jobs.js`

### GPU Processing

- [GPU API Server](https://github.com/khanhdocnope/tun/blob/main/colab-backend/server.py): `colab-backend/server.py`
- [Async Job Engine](https://github.com/khanhdocnope/tun/blob/main/colab-backend/job_engine.py): `colab-backend/job_engine.py`
- [Inpainting Pipeline](https://github.com/khanhdocnope/tun/blob/main/colab-backend/manga_cleaner.py): `colab-backend/manga_cleaner.py`
- [Bubble Detection](https://github.com/khanhdocnope/tun/blob/main/colab-backend/bubble_detector.py): `colab-backend/bubble_detector.py`
- [Text Detection](https://github.com/khanhdocnope/tun/blob/main/colab-backend/text_detector.py): `colab-backend/text_detector.py`
- [Mask Logic](https://github.com/khanhdocnope/tun/blob/main/colab-backend/mask_logic.py): `colab-backend/mask_logic.py`

### Typesetting

- [Typeset Studio](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/app.js): `web-in-vercel/public/typeset/js/app.js`
- [Canvas Editor](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/canvas-editor.js): `web-in-vercel/public/typeset/js/canvas-editor.js`
- [Text Translator](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/translator.js): `web-in-vercel/public/typeset/js/translator.js`
- [Typeset Storage](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/storage.js): `web-in-vercel/public/typeset/js/storage.js`
- [Browser Inpainter](https://github.com/khanhdocnope/tun/blob/main/web-in-vercel/public/typeset/js/web-lama.js): `web-in-vercel/public/typeset/js/web-lama.js`

### Other components

- **Reader / Creator**
- **Google Gemini**

## Connections

- Reader / Creator → Batch Studio: uses (evidence: `README.md`)
- Batch Studio → Batch Queue: starts jobs (evidence: `web-in-vercel/public/batch-studio/app.js`)
- Batch Studio → Batch UI: renders (evidence: `web-in-vercel/public/batch-studio/app.js`)
- Batch UI → Batch API Client: invokes (evidence: `web-in-vercel/public/batch-studio/js/ui.js`)
- Batch Queue → Batch API Client: dispatches (evidence: `web-in-vercel/public/batch-studio/js/queue.js`)
- Batch API Client → Batch Storage: persists (evidence: `web-in-vercel/public/batch-studio/js/api.js`)
- Batch Studio → Web Server: calls API (evidence: `README.md`)
- Web Server → Vision API: routes (evidence: `web-in-vercel/server.js`)
- Web Server → Clean API: routes (evidence: `web-in-vercel/server.js`)
- Web Server → Jobs API: routes (evidence: `web-in-vercel/server.js`)
- Vision API → Gemini Helper: uses (evidence: `web-in-vercel/api/ai-vision.js`)
- Vision API → Manga Contract: normalizes (evidence: `web-in-vercel/api/ai-vision.js`)
- Gemini Helper → Google Gemini: requests vision (evidence: `README.md`)
- Clean API → GPU API Server: proxies cleaning (evidence: `README.md`)
- Jobs API → GPU API Server: proxies jobs (evidence: `README.md`)
- GPU API Server → Async Job Engine: dispatches jobs (evidence: `colab-backend/server.py`)
- GPU API Server → Inpainting Pipeline: requests cleaning (evidence: `colab-backend/server.py`)
- Async Job Engine → Inpainting Pipeline: processes pages (evidence: `colab-backend/job_engine.py`)
- Inpainting Pipeline → Bubble Detection: detects bubbles (evidence: `README.md`)
- Inpainting Pipeline → Text Detection: detects text
- Inpainting Pipeline → Mask Logic: builds masks
- Reader / Creator → Typeset Studio: edits pages (evidence: `README.md`)
- Typeset Studio → Canvas Editor: edits canvas (evidence: `web-in-vercel/public/typeset/js/app.js`)
- Typeset Studio → Text Translator: translates text (evidence: `web-in-vercel/public/typeset/js/app.js`)
- Typeset Studio → Typeset Storage: stores pages (evidence: `web-in-vercel/public/typeset/js/app.js`)
- Typeset Studio → Browser Inpainter: cleans locally (evidence: `web-in-vercel/public/typeset/js/app.js`)
- Typeset Studio → Google Gemini: translates with
