# artifexsoftware/mupdf architecture

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

- Interactive diagram: https://gitdiagram.com/artifexsoftware/mupdf
- Repository: https://github.com/artifexsoftware/mupdf

## Overview

MuPDF is a document framework for viewing and converting PDF, XPS, and ebook documents. Its principal workflow is to open a document, interpret or lay out its content, then render or convert it. The tree also shows PDF-specific editing and signing, text search, and bindings for several platforms. The README documents the product scope; sampled source is incomplete, so links among format handlers and rendering stages are shown as unverified rather than asserted as observed calls.

Main entry points: [`include/mupdf/fitz.h`](https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz.h) (Fitz API), [`include/mupdf/fitz/device.h`](https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz/device.h) (Rendering devices), [`source/pdf`](https://github.com/artifexsoftware/mupdf/tree/master/source/pdf) (PDF engine), [`source/html`](https://github.com/artifexsoftware/mupdf/tree/master/source/html) (HTML and EPUB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Document core"]
  node_api["Fitz API<br/>[fitz.h]"]
  node_context["Runtime context<br/>[context.c]"]
end

subgraph group_formats["Document formats"]
  node_pdf["PDF engine"]
  node_html["HTML and EPUB"]
  node_xps["XPS engine"]
  node_svg["SVG engine<br/>[svg-run.c]"]
  node_cbz["Comic archives<br/>[mucbz.c]"]
  node_pdfedit["PDF annotations<br/>[annot.h]"]
  node_signing["PDF signing<br/>[pkcs7-openssl.c]"]
end

subgraph group_processing["Content processing"]
  node_reflow["Document reflow<br/>[reflow-doc.c]"]
  node_layout["HTML layout<br/>[html-layout.c]"]
  node_text["Text extraction<br/>[structured-text.h]"]
  node_search["Text search<br/>[stext-search.c]"]
  node_render["Rendering devices<br/>[device.h]"]
  node_output["Document output<br/>[writer.h]"]
end

subgraph group_interfaces["User interfaces"]
  node_desktop["Desktop viewer<br/>[gl-main.c]"]
  node_x11["X11 viewer<br/>[pdfapp.c]"]
  node_javascript["JavaScript bindings<br/>[murun.c]"]
  node_wasm["WebAssembly API<br/>[mupdf.ts]"]
  node_java["Java bindings<br/>[context.c]"]
end

node_user(("Document user"))

node_user -->|"uses framework"| node_api
node_api -.->|"opens PDF"| node_pdf
node_api -.->|"opens XPS"| node_xps
node_api -.->|"opens ebooks"| node_html
node_html -.->|"lays out content"| node_layout
node_pdf -.->|"renders pages"| node_render
node_xps -.->|"renders pages"| node_render
node_html -.->|"renders pages"| node_render
node_svg -.->|"renders graphics"| node_render
node_cbz -.->|"renders pages"| node_render
node_render -.->|"extracts text"| node_text
node_text -.->|"searches text"| node_search
node_api -.->|"converts documents"| node_output
node_pdf -.->|"supports annotations"| node_pdfedit
node_pdf -.->|"signs documents"| node_signing
node_user -.->|"views documents"| node_desktop
node_user -.->|"views documents"| node_x11
node_user -.->|"uses bindings"| node_javascript
node_user -.->|"uses bindings"| node_wasm
node_user -.->|"uses bindings"| node_java
node_context -.->|"provides runtime"| node_api
node_reflow -.->|"reflows content"| node_html

click node_api "https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz.h"
click node_context "https://github.com/artifexsoftware/mupdf/blob/master/source/fitz/context.c"
click node_pdf "https://github.com/artifexsoftware/mupdf/tree/master/source/pdf"
click node_html "https://github.com/artifexsoftware/mupdf/tree/master/source/html"
click node_xps "https://github.com/artifexsoftware/mupdf/tree/master/source/xps"
click node_svg "https://github.com/artifexsoftware/mupdf/blob/master/source/svg/svg-run.c"
click node_cbz "https://github.com/artifexsoftware/mupdf/blob/master/source/cbz/mucbz.c"
click node_reflow "https://github.com/artifexsoftware/mupdf/blob/master/source/reflow/reflow-doc.c"
click node_layout "https://github.com/artifexsoftware/mupdf/blob/master/source/html/html-layout.c"
click node_text "https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz/structured-text.h"
click node_search "https://github.com/artifexsoftware/mupdf/blob/master/source/fitz/stext-search.c"
click node_render "https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz/device.h"
click node_output "https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz/writer.h"
click node_pdfedit "https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/pdf/annot.h"
click node_signing "https://github.com/artifexsoftware/mupdf/blob/master/source/helpers/pkcs7/pkcs7-openssl.c"
click node_desktop "https://github.com/artifexsoftware/mupdf/blob/master/platform/gl/gl-main.c"
click node_x11 "https://github.com/artifexsoftware/mupdf/blob/master/platform/x11/pdfapp.c"
click node_javascript "https://github.com/artifexsoftware/mupdf/blob/master/source/tools/murun.c"
click node_wasm "https://github.com/artifexsoftware/mupdf/blob/master/platform/wasm/lib/mupdf.ts"
click node_java "https://github.com/artifexsoftware/mupdf/blob/master/platform/java/jni/context.c"

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_api,node_context,node_user toneBlue
class node_pdf,node_html,node_xps,node_svg,node_cbz,node_pdfedit,node_signing toneAmber
class node_reflow,node_layout,node_text,node_search,node_render,node_output toneMint
class node_desktop,node_x11,node_javascript,node_wasm,node_java toneRose
```

## Components

### Document core

- [Fitz API](https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz.h): `include/mupdf/fitz.h`
- [Runtime context](https://github.com/artifexsoftware/mupdf/blob/master/source/fitz/context.c): `source/fitz/context.c`

### Document formats

- [PDF engine](https://github.com/artifexsoftware/mupdf/tree/master/source/pdf): `source/pdf`
- [HTML and EPUB](https://github.com/artifexsoftware/mupdf/tree/master/source/html): `source/html`
- [XPS engine](https://github.com/artifexsoftware/mupdf/tree/master/source/xps): `source/xps`
- [SVG engine](https://github.com/artifexsoftware/mupdf/blob/master/source/svg/svg-run.c): `source/svg/svg-run.c`
- [Comic archives](https://github.com/artifexsoftware/mupdf/blob/master/source/cbz/mucbz.c): `source/cbz/mucbz.c`
- [PDF annotations](https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/pdf/annot.h): `include/mupdf/pdf/annot.h`
- [PDF signing](https://github.com/artifexsoftware/mupdf/blob/master/source/helpers/pkcs7/pkcs7-openssl.c): `source/helpers/pkcs7/pkcs7-openssl.c`

### Content processing

- [Document reflow](https://github.com/artifexsoftware/mupdf/blob/master/source/reflow/reflow-doc.c): `source/reflow/reflow-doc.c`
- [HTML layout](https://github.com/artifexsoftware/mupdf/blob/master/source/html/html-layout.c): `source/html/html-layout.c`
- [Text extraction](https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz/structured-text.h): `include/mupdf/fitz/structured-text.h`
- [Text search](https://github.com/artifexsoftware/mupdf/blob/master/source/fitz/stext-search.c): `source/fitz/stext-search.c`
- [Rendering devices](https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz/device.h): `include/mupdf/fitz/device.h`
- [Document output](https://github.com/artifexsoftware/mupdf/blob/master/include/mupdf/fitz/writer.h): `include/mupdf/fitz/writer.h`

### User interfaces

- [Desktop viewer](https://github.com/artifexsoftware/mupdf/blob/master/platform/gl/gl-main.c): `platform/gl/gl-main.c`
- [X11 viewer](https://github.com/artifexsoftware/mupdf/blob/master/platform/x11/pdfapp.c): `platform/x11/pdfapp.c`
- [JavaScript bindings](https://github.com/artifexsoftware/mupdf/blob/master/source/tools/murun.c): `source/tools/murun.c`
- [WebAssembly API](https://github.com/artifexsoftware/mupdf/blob/master/platform/wasm/lib/mupdf.ts): `platform/wasm/lib/mupdf.ts`
- [Java bindings](https://github.com/artifexsoftware/mupdf/blob/master/platform/java/jni/context.c): `platform/java/jni/context.c`

### Other components

- **Document user**

## Connections

- Document user → Fitz API: uses framework (evidence: `README`)
- Fitz API → PDF engine: opens PDF (evidence: `source/pdf/pdf-xref.c`)
- Fitz API → XPS engine: opens XPS (evidence: `source/xps/xps-path.c`)
- Fitz API → HTML and EPUB: opens ebooks (evidence: `source/html/html-layout.c`)
- HTML and EPUB → HTML layout: lays out content (evidence: `source/html/html-layout.c`)
- PDF engine → Rendering devices: renders pages
- XPS engine → Rendering devices: renders pages
- HTML and EPUB → Rendering devices: renders pages
- SVG engine → Rendering devices: renders graphics
- Comic archives → Rendering devices: renders pages
- Rendering devices → Text extraction: extracts text (evidence: `include/mupdf/fitz/structured-text.h`)
- Text extraction → Text search: searches text
- Fitz API → Document output: converts documents
- PDF engine → PDF annotations: supports annotations
- PDF engine → PDF signing: signs documents
- Document user → Desktop viewer: views documents
- Document user → X11 viewer: views documents
- Document user → JavaScript bindings: uses bindings
- Document user → WebAssembly API: uses bindings
- Document user → Java bindings: uses bindings
- Runtime context → Fitz API: provides runtime (evidence: `source/fitz/context.c`)
- Document reflow → HTML and EPUB: reflows content
