> ## Documentation Index
> Fetch the complete documentation index at: https://koharu.rs/llms.txt
> Use this file to discover all available pages before exploring further.

# How Koharu works

> What happens between importing a scan and exporting a lettered page, and the rules every run follows.

Koharu turns a scan into a lettered page in four stages. Each stage writes ordinary project data: layers you can select, edit, hide, and undo. A result is a starting point you keep working on, not a finished image.

```mermaid theme={null}
flowchart LR
  scan["Scan"] --> detection["Detection"]
  detection --> ocr["OCR"] --> translation["Translation"]
  detection --> cleanup["Cleanup"]
  translation --> page["Lettered page"]
  cleanup --> page
  page --> export["PNG, PSD, CBZ, PDF"]
```

## What each stage writes

**1. Detection**

**Koharu Layout HighRes** reads the scan and writes the page's panels, balloons, and text blocks
in reading order, with each block's frame, tilt, direction, and mask. See [detection and
OCR](https://koharu.rs/how-it-works/detection.md).

**2. OCR**

**Hayai OCR** reads the scan inside each block's frame and writes the block's source text. See
[OCR](https://koharu.rs/how-it-works/detection.md#ocr).

**3. Cleanup**

The **Inpainting** stage, **LaMa** by default, reads the scan with each block's mask, balloon,
and panel, and writes each block's clean-up, shown through its mask. See
[cleanup](https://koharu.rs/how-it-works/cleanup.md).

**4. Translation**

**Index-Translate 9B** reads the page's source texts in reading order, and with **Vision** the
scan, and writes each block's translation and where it goes. See
[translation](https://koharu.rs/how-it-works/translation.md).

There is no typesetting stage. Translation places each text as it writes it, and the renderer fits it to its frame every time it draws the page. See [fitting translations](https://koharu.rs/how-it-works/lettering.md).

## Rules every run follows

* **A run does what it was asked.** It runs the stages you chose on the pages or texts you gave it. It never decides that a page needs no work, and nothing reruns because something it read changed: fix a source text, and its translation stays as it was until you translate that text again.
* **A stage never runs another.** OCR without detection reads the blocks already there. A stage with nothing to do, such as OCR on a page without text, does nothing and doesn't fail.
* **A rerun replaces.** A model's result overwrites what is there, your own edits included, and undo is the way back. A lock is the exception: no stage writes a locked text block or one inside a locked layer.
* **Each page's stage is one undo step,** written as soon as it finishes, so a run that stops or fails keeps what it finished.
* **A failure belongs to a page or to the run.** A page the translation model blocks or can't answer is left untranslated, and the run goes on. Any other failure would happen again on the next page, so it ends the run and names the page, the stage, and the reason.
* **Nothing runs by itself.** A model runs when you choose **Run**, run a stage from a page's or a text's menu, release a **Remove** stroke, choose **Generate**, or ask the Agent.

## Where it runs

Detection, OCR, cleanup, and Koharu's own translation models run on your GPU, which also draws the page. A hosted provider you connect receives what translation or the Agent sends it: each page's text, and the page image when **Vision** is on. See [models on your GPU](https://koharu.rs/how-it-works/runtime.md).

## In this section

> [card] [Pages, layers, and history](https://koharu.rs/how-it-works/projects.md)
>
> What a project holds, how a text block keeps its four parts, and how edits and undo work.

> [card] [Detection and OCR](https://koharu.rs/how-it-works/detection.md)
>
> How Koharu finds lettering, orders it, measures it, and reads it.

> [card] [Cleanup](https://koharu.rs/how-it-works/cleanup.md)
>
> Why most lettering is filled without a model, and how the model redraws the rest.

> [card] [Translation](https://koharu.rs/how-it-works/translation.md)
>
> One conversation per project, what the model receives, and when a page is asked again.

> [card] [Fitting translations](https://koharu.rs/how-it-works/lettering.md)
>
> Where a translation goes, how large it's lettered, and how it gets its colours.

> [card] [Drawing the page](https://koharu.rs/how-it-works/rendering.md)
>
> One renderer for the canvas and every export, vertical text, ruby, and fonts.

> [card] [Models on your GPU](https://koharu.rs/how-it-works/runtime.md)
>
> Which GPU runs the models, what downloads, and how memory and runs are shared.

> [!NOTE]
>
> These pages explain behaviour you can see in the app. The design behind each part, with its
> measurements and sources, is in the README of the crate that owns it, linked at the end of each
> page.

Design and sources: the [`koharu-pipeline` README](https://github.com/koharu-rs/koharu/blob/main/crates/koharu-pipeline/README.md).


## Related topics

- [Architecture](https://koharu.rs/development/architecture.md)
- [Process pages](https://koharu.rs/guides/processing.md)
- [Work with Koharu Agent](https://koharu.rs/agent/projects.md)
- [Koharu documentation](https://koharu.rs/index.md)
- [Pages, layers, and history](https://koharu.rs/how-it-works/projects.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.