# vvdb-architecture/sumatrapdf architecture

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

- Interactive diagram: https://gitdiagram.com/vvdb-architecture/sumatrapdf
- Repository: https://github.com/vvdb-architecture/sumatrapdf

## Overview

#### Purpose and entry points
SumatraPDF is a native Windows multi-format document reader (PDF, EPUB, MOBI, FB2, CHM, XPS, DjVu). The primary executable initializes application state, command handling, windows, and document startup. Visual Studio solutions are the main developer entry points.
- `src/SumatraPDF.cpp`
- `src/SumatraStartup.cpp`
- `vs2022/SumatraPDF.sln`

#### Application shell and UI
The desktop shell is C++ on the Win32 API, with custom UI abstractions for windows, layout, controls, menus, tabs, toolbars, and canvas rendering. `WindowInfo` and `TabInfo` connect per-window UI state to loaded documents; commands/actions drive user operations.
- `src/WindowInfo.cpp`
- `src/Tabs.cpp`
- `src/wingui/WinGui.cpp`

#### Document-engine boundary
A common engine interface separates viewer/UI code from format-specific loaders and renderers. Engine selection/creation dispatches to MuPDF-backed formats, DjVu, images, ebooks, PostScript, CHM, and composite/multi-engine handling. This is the principal extension boundary for supported document types.
- `src/EngineBase.h`
- `src/EngineCreate.cpp`
- `src/EngineMupdf.cpp`

#### Viewing, rendering, and interaction flow
Opening a file creates an engine and display model; UI requests page rendering through a cache and canvas. Search, text selection, annotations, table of contents, and printing operate on document/engine representations rather than direct format parsers. Rendered page data is cached to support navigation and repaint.
- `src/DisplayModel.cpp`
- `src/RenderCache.cpp`
- `src/Canvas.cpp`

#### MuPDF platform core
The vendored MuPDF tree supplies the major parsing and graphics runtime: generic document APIs, PDF interpretation, raster drawing, text extraction, HTML/EPUB layout, XPS/SVG/CBZ support, fonts, color handling, and image/codec loading. Sumatra’s MuPDF adapter is the boundary between app engines and this library.
- `mupdf/include/mupdf/fitz/document.h`
- `mupdf/source/pdf/pdf-interpret.c`
- `mupdf/source/fitz/draw-device.c`

#### State, integrations, and Windows services
Preferences, file history, favorites, themes, translations, update checks, crash handling, installer/uninstaller, preview handler, and Windows Search IFilter are separate integration surfaces. Network access is limited to client concerns such as update checking; there is no server runtime in this repository.
- `src/AppPrefs.cpp`
- `src/UpdateCheck.cpp`
- `src/previewer/PdfPreviewDll.cpp`

#### Dependencies, build, and delivery
The application is primarily C/C++ built with Visual Studio 2019/2022; Go powers repository build/release automation. Vendored libraries cover font shaping/rasterization, compression/archive handling, image codecs, DjVu, color management, HTML parsing, and PDF support. Packaging includes an AppX manifest and a bundled Microsoft WebView2 SDK. CI runs through GitHub Actions; release automation includes signing and artifact upload code.
- `do/main.go`
- `premake5.lua`
- `appx/SumatraPDF.appxmanifest`

Main entry points: [`src/SumatraPDF.cpp`](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/SumatraPDF.cpp) (Application executable), [`src/WindowInfo.cpp`](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/WindowInfo.cpp) (Window state), [`src/EngineMupdf.cpp`](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/EngineMupdf.cpp) (MuPDF adapter), [`src/DisplayModel.cpp`](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/DisplayModel.cpp) (Display model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Desktop application"]
  node_app["Application executable<br/>Win32 entry point<br/>[SumatraPDF.cpp]"]
  node_startup["Startup flow<br/>application initialization<br/>[SumatraStartup.cpp]"]
  node_window["Window state<br/>window and document state<br/>[WindowInfo.cpp]"]
  node_tabs["Tabs<br/>tab UI<br/>[Tabs.cpp]"]
  node_wingui["WinGui<br/>custom Win32 UI toolkit<br/>[WinGui.cpp]"]
  node_display["Display model<br/>document view model<br/>[DisplayModel.cpp]"]
  node_rendercache["Render cache<br/>[RenderCache.cpp]"]
  node_canvas["Canvas<br/>[Canvas.cpp]"]
  node_prefs["Preferences and history<br/>local application state<br/>[AppPrefs.cpp]"]
  node_updates["Update checker<br/>network client integration<br/>[UpdateCheck.cpp]"]
  node_preview["PDF preview handler<br/>Windows shell integration<br/>[PdfPreviewDll.cpp]"]
end

subgraph group_engines["Document engines"]
  node_engineapi{{"Engine interface<br/>format-neutral document API<br/>[EngineBase.h]"}}
  node_enginecreate["Engine selection<br/>engine factory<br/>[EngineCreate.cpp]"]
  node_enginemupdf["MuPDF adapter<br/>engine implementation<br/>[EngineMupdf.cpp]"]
end

subgraph group_mupdf["MuPDF core"]
  node_mupdfdoc{{"MuPDF document API<br/>document runtime API<br/>[document.h]"}}
  node_pdfinterpret["PDF interpreter<br/>PDF execution<br/>[pdf-interpret.c]"]
  node_drawdevice["Raster draw device<br/>graphics rendering<br/>[draw-device.c]"]
end

subgraph group_delivery["Build and delivery"]
  node_solution["Visual Studio solution<br/>developer entry point<br/>[SumatraPDF.sln]"]
  node_buildautomation["Build and release automation<br/>Go automation<br/>[main.go]"]
  node_premake["Premake build definition<br/>build generation<br/>[premake5.lua]"]
  node_appx["AppX package manifest<br/>Windows package"]
end

node_solution -->|"builds from"| node_premake
node_premake -->|"builds"| node_app
node_buildautomation -->|"orchestrates"| node_premake
node_buildautomation -->|"packages and signs"| node_appx
node_app -->|"initializes"| node_startup
node_startup -->|"loads state"| node_prefs
node_app -->|"creates"| node_window
node_window -->|"hosts"| node_tabs
node_window -->|"uses"| node_wingui
node_window -->|"owns view"| node_display
node_display -->|"opens through"| node_enginecreate
node_enginecreate -->|"returns"| node_engineapi
node_enginemupdf -->|"implements"| node_engineapi
node_enginecreate -->|"selects for supported formats"| node_enginemupdf
node_display -->|"requests pages"| node_rendercache
node_rendercache -->|"supplies rendered pages"| node_canvas
node_canvas -->|"renders via"| node_wingui
node_enginemupdf -->|"uses"| node_mupdfdoc
node_mupdfdoc -->|"supports PDF processing"| node_pdfinterpret
node_pdfinterpret -->|"draws through"| node_drawdevice
node_app -.->|"checks updates"| node_updates
node_preview -->|"renders PDFs with"| node_enginemupdf

click node_solution "https://github.com/vvdb-architecture/sumatrapdf/blob/master/vs2022/SumatraPDF.sln"
click node_app "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/SumatraPDF.cpp"
click node_startup "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/SumatraStartup.cpp"
click node_window "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/WindowInfo.cpp"
click node_tabs "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/Tabs.cpp"
click node_wingui "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/wingui/WinGui.cpp"
click node_display "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/DisplayModel.cpp"
click node_rendercache "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/RenderCache.cpp"
click node_canvas "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/Canvas.cpp"
click node_prefs "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/AppPrefs.cpp"
click node_updates "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/UpdateCheck.cpp"
click node_preview "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/previewer/PdfPreviewDll.cpp"
click node_engineapi "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/EngineBase.h"
click node_enginecreate "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/EngineCreate.cpp"
click node_enginemupdf "https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/EngineMupdf.cpp"
click node_mupdfdoc "https://github.com/vvdb-architecture/sumatrapdf/blob/master/mupdf/include/mupdf/fitz/document.h"
click node_pdfinterpret "https://github.com/vvdb-architecture/sumatrapdf/blob/master/mupdf/source/pdf/pdf-interpret.c"
click node_drawdevice "https://github.com/vvdb-architecture/sumatrapdf/blob/master/mupdf/source/fitz/draw-device.c"
click node_buildautomation "https://github.com/vvdb-architecture/sumatrapdf/blob/master/do/main.go"
click node_premake "https://github.com/vvdb-architecture/sumatrapdf/blob/master/premake5.lua"
click node_appx "https://github.com/vvdb-architecture/sumatrapdf/blob/master/appx/SumatraPDF.appxmanifest"

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_startup,node_window,node_tabs,node_wingui,node_display,node_rendercache,node_canvas,node_prefs,node_updates,node_preview toneBlue
class node_engineapi,node_enginecreate,node_enginemupdf toneAmber
class node_mupdfdoc,node_pdfinterpret,node_drawdevice toneMint
class node_solution,node_buildautomation,node_premake,node_appx toneRose
```

## Components

### Desktop application

Native Win32 reader shell and document viewing pipeline.

- [Application executable](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/SumatraPDF.cpp): Win32 entry point · Initializes application state, commands, windows, and document startup. · `src/SumatraPDF.cpp`
- [Startup flow](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/SumatraStartup.cpp): application initialization · `src/SumatraStartup.cpp`
- [Window state](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/WindowInfo.cpp): window and document state · Connects each viewer window to its loaded document and UI state. · `src/WindowInfo.cpp`
- [Tabs](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/Tabs.cpp): tab UI · `src/Tabs.cpp`
- [WinGui](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/wingui/WinGui.cpp): custom Win32 UI toolkit · Provides windows, layouts, controls, menus, and canvas UI abstractions. · `src/wingui/WinGui.cpp`
- [Display model](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/DisplayModel.cpp): document view model · Represents the loaded document for viewing and interaction. · `src/DisplayModel.cpp`
- [Render cache](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/RenderCache.cpp): page render cache · Caches rendered page data for navigation and repaint. · `src/RenderCache.cpp`
- [Canvas](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/Canvas.cpp): canvas rendering · `src/Canvas.cpp`
- [Preferences and history](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/AppPrefs.cpp): local application state · Stores preferences, file history, favorites, themes, and translations. · `src/AppPrefs.cpp`
- [Update checker](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/UpdateCheck.cpp): network client integration · Checks for application updates; the repository has no server runtime. · `src/UpdateCheck.cpp`
- [PDF preview handler](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/previewer/PdfPreviewDll.cpp): Windows shell integration · `src/previewer/PdfPreviewDll.cpp`

### Document engines

Format-neutral engine boundary and dispatch.

- [Engine interface](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/EngineBase.h): format-neutral document API · Principal extension boundary between viewer code and document formats. · `src/EngineBase.h`
- [Engine selection](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/EngineCreate.cpp): engine factory · Dispatches files to MuPDF, DjVu, images, ebooks, PostScript, CHM, and composite engines. · `src/EngineCreate.cpp`
- [MuPDF adapter](https://github.com/vvdb-architecture/sumatrapdf/blob/master/src/EngineMupdf.cpp): engine implementation · Adapts Sumatra's engine API to the MuPDF runtime. · `src/EngineMupdf.cpp`

### MuPDF core

Vendored parsing, interpretation, and graphics runtime.

- [MuPDF document API](https://github.com/vvdb-architecture/sumatrapdf/blob/master/mupdf/include/mupdf/fitz/document.h): document runtime API · Generic document abstraction used by MuPDF-backed formats. · `mupdf/include/mupdf/fitz/document.h`
- [PDF interpreter](https://github.com/vvdb-architecture/sumatrapdf/blob/master/mupdf/source/pdf/pdf-interpret.c): PDF execution · `mupdf/source/pdf/pdf-interpret.c`
- [Raster draw device](https://github.com/vvdb-architecture/sumatrapdf/blob/master/mupdf/source/fitz/draw-device.c): graphics rendering · `mupdf/source/fitz/draw-device.c`

### Build and delivery

Visual Studio builds, Go automation, and AppX packaging.

- [Visual Studio solution](https://github.com/vvdb-architecture/sumatrapdf/blob/master/vs2022/SumatraPDF.sln): developer entry point · `vs2022/SumatraPDF.sln`
- [Build and release automation](https://github.com/vvdb-architecture/sumatrapdf/blob/master/do/main.go): Go automation · Builds, signs, and uploads release artifacts. · `do/main.go`
- [Premake build definition](https://github.com/vvdb-architecture/sumatrapdf/blob/master/premake5.lua): build generation · `premake5.lua`
- [AppX package manifest](https://github.com/vvdb-architecture/sumatrapdf/blob/master/appx/SumatraPDF.appxmanifest): Windows package · `appx/SumatraPDF.appxmanifest`

## Connections

- Visual Studio solution → Premake build definition: builds from
- Premake build definition → Application executable: builds
- Build and release automation → Premake build definition: orchestrates
- Build and release automation → AppX package manifest: packages and signs
- Application executable → Startup flow: initializes
- Startup flow → Preferences and history: loads state
- Application executable → Window state: creates
- Window state → Tabs: hosts
- Window state → WinGui: uses
- Window state → Display model: owns view
- Display model → Engine selection: opens through
- Engine selection → Engine interface: returns
- MuPDF adapter → Engine interface: implements
- Engine selection → MuPDF adapter: selects for supported formats
- Display model → Render cache: requests pages
- Render cache → Canvas: supplies rendered pages
- Canvas → WinGui: renders via
- MuPDF adapter → MuPDF document API: uses
- MuPDF document API → PDF interpreter: supports PDF processing
- PDF interpreter → Raster draw device: draws through
- Application executable → Update checker: checks updates
- PDF preview handler → MuPDF adapter: renders PDFs with
