# jhaygood86/peachpdf architecture

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

- Interactive diagram: https://gitdiagram.com/jhaygood86/peachpdf
- Repository: https://github.com/jhaygood86/peachpdf

## Overview

PeachPDF is a pure .NET 8+ HTML/CSS-to-PDF renderer, with optional direct C# document construction. The principal workflow is initiated by an external .NET library consumer calling `PdfGenerator.GeneratePdf`; PeachPDF loads supplied or configured content, resolves document styling and layout, renders specialized text/vector content, and returns a PDF document the consumer can save.

#### Public interfaces and hosts

- **External .NET library consumer** — null repository path; invokes the documented `PdfGenerator.GeneratePdf` or `CreateDocument` API and owns saving the returned document.
- **.NET rendering facade** — `src/PeachPDF`; exposes the documented HTML rendering, configuration, font-registration, and declarative document-building API.
- **External CLI user** — null repository path; invokes the documented `peachpdf` shell command.
- **CLI conversion runner** — `src/PeachPDF.Cli/CliRunner.cs`; participates in the standalone command-line HTML-to-PDF conversion application, though its detailed wiring was not sampled.
- **External browser-demo user** — null repository path; supplies content in the WebAssembly demo.
- **WebAssembly demo host** — `src/PeachPDF.Demo.BlazorWasm/Program.cs`; hosts the browser demo that the README says runs the same renderer locally for HTML, MHTML, and ZIP input.

#### Content, CSS, and document layout

- **External content/resource source** — null repository path; represents caller-selected local files, MHTML streams, or HTTP URI resources.
- **Network and local resource loading** — `src/PeachPDF/Network`; contains the loader subsystem documented to resolve HTML and relative stylesheets, images, and fonts from file, URI, MHTML, or data sources.
- **CSS parser, cascade, and property model** — `src/PeachPDF/CSS`; provides the CSS token, parser, rule, selector, value, and typed-property machinery used by rendering.
- **HTML DOM, pagination, and box layout** — `src/PeachPDF/Html/Core`; owns HTML box-tree construction, CSS layout, fragmentation, painting support, and document-level rendering behavior.
- **Generated-content resolver** — `src/PeachPDF/Html/Core/Dom/CssContentEngine.cs`; tokenizes CSS `content`, resolves text, quotes, images/gradients, counters, strings, and `leader()` segments for boxes and pseudo-elements.
- **CSS counter resolver** — `src/PeachPDF/Html/Core/Dom/CssCounterEngine.cs`; inherits, resets, sets, increments, and formats CSS counters for generated content and list markers, with decimal fallback for invalid styles.

#### Text and fonts

- **Bidi and text-shaping support** — `src/PeachPDF/Text/Bidi`; supplies the text-direction subsystem used by layout’s documented UAX#9 bidi behavior.
- **Automatic hyphenation engine** — `src/PeachPDF/Text/HyphenationEngine.cs`; lazily loads embedded Brotli-compressed patterns for roughly 70 languages, resolves BCP-47-like language tags, and applies Liang/TeX hyphenation scoring.
- **Font discovery and OpenType processing** — `src/PeachPDF/Fonts`; provides system/custom/web-font support and OpenType data needed for glyph selection, fallback, metrics, and specialized layout.

#### Specialized vector layout

- **SVG rendering subsystem** — `src/PeachPDF/Svg`; implements the repository’s native-vector SVG capability for inline and referenced SVG content.
- **MathML Core layout engine** — `src/PeachPDF/MathML/MathLayoutEngine.cs`; transforms a MathML node tree into positioned math boxes, using OpenType MATH metrics and glyph assemblies where available, with metric fallbacks otherwise.

#### PDF output

- **Embedded PDF graphics and serialization backend** — `src/PeachPDF/PdfSharpCore`; is the embedded fork identified by the README as PeachPDF’s PDF document, drawing, structure, annotation, and serialization implementation.
- **External PDF document/output destination** — null repository path; is the returned document and any stream or file destination written through its documented `Save` operation.

#### Relationships

- **External .NET library consumer -> .NET rendering facade:** invokes `GeneratePdf` or `CreateDocument`; evidence: README API examples.
- **.NET rendering facade -> Network and local resource loading:** requests configured content and relative assets when a `NetworkLoader` is used; evidence: README loader examples.
- **Network and local resource loading -> External content/resource source:** reads local, MHTML, or HTTP-backed document resources; evidence: README behavior.
- **.NET rendering facade -> HTML DOM, pagination, and box layout:** submits HTML or the declaratively built document for rendering; evidence: README describes HTML-to-PDF and C# document construction.
- **HTML DOM, pagination, and box layout -> CSS parser, cascade, and property model:** applies CSS parsing and resolved properties during box layout; evidence: CSS/HTML subsystem organization and the generated-content implementation’s CSS parser use.
- **HTML DOM, pagination, and box layout -> Generated-content resolver:** resolves pseudo-element and box `content` during layout; evidence: generated-content source identifies `CssBox.ParseToWordsWithLeaders` as its consumer.
- **Generated-content resolver -> CSS parser, cascade, and property model:** tokenizes and parses `content` and image values through `CssValueParser`; evidence: direct calls in the source.
- **Generated-content resolver -> CSS counter resolver:** resolves `counter()` content through the shared counter-style resolver; evidence: counter-engine source documentation names `CssContentEngine`.
- **HTML DOM, pagination, and box layout -> Bidi and text-shaping support:** applies bidi resolution and line reordering for mixed-direction text; evidence: sampled layout tests identify real UAX#9 handling in layout.
- **HTML DOM, pagination, and box layout -> Automatic hyphenation engine:** requests hyphenation points for `hyphens: auto`; evidence: hyphenation-engine source documentation names `CssBox.ParseToWords` and `CssLayoutEngine.FlowBox`.
- **HTML DOM, pagination, and box layout -> SVG rendering subsystem:** renders supported SVG document content as vectors; evidence: README feature description.
- **HTML DOM, pagination, and box layout -> MathML Core layout engine:** dispatches inline MathML to specialized math layout; evidence: README MathML support and the engine’s MathNode-to-MathBox role.
- **MathML Core layout engine -> Font discovery and OpenType processing:** resolves math fonts and reads OpenType MATH metrics/assemblies; evidence: direct `ResolveFont` and OpenType imports in the source.
- **HTML DOM, pagination, and box layout -> Embedded PDF graphics and serialization backend:** renders the laid-out document into a PDF representation; evidence: documented HTML-to-PDF product behavior, although the bridge call site was not sampled.
- **Embedded PDF graphics and serialization backend -> External PDF document/output destination:** materializes the PDF document that callers save; evidence: README `document.Save(stream)` examples.
- **.NET rendering facade -> External .NET library consumer:** returns the generated PDF document; evidence: README assignment of `await generator.GeneratePdf(...)`.
- **External CLI user -> CLI conversion runner:** starts conversion with `peachpdf report.html -o report.pdf`; evidence: README CLI example.
- **CLI conversion runner -> External PDF document/output destination:** creates the requested PDF file; evidence: README describes the command as HTML-to-PDF conversion.
- **External browser-demo user -> WebAssembly demo host:** supplies browser-local HTML, MHTML, or ZIP content; evidence: README demo description.
- **WebAssembly demo host -> .NET rendering facade:** renders with the same library in WebAssembly; evidence: README statement.

#### Coverage limits

The sampled source does not include `PdfGenerator`, network-loader implementations, CLI startup code, or the renderer-to-PDF bridge, so their precise call order, object lifetimes, and error handling cannot be established. SVG and demo internals were not sampled; their responsibilities above rely on documented behavior plus repository organization.

Main entry points: [`src/PeachPDF/Html/Core`](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Html/Core) (HTML Layout Engine), [`src/PeachPDF`](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF) (.NET Rendering Facade), [`src/PeachPDF/Html/Core/Dom/CssContentEngine.cs`](https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/Html/Core/Dom/CssContentEngine.cs) (Generated Content Resolver), [`src/PeachPDF.Cli/CliRunner.cs`](https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF.Cli/CliRunner.cs) (CLI Conversion Runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Public Interfaces"]
  node_library_consumer((".NET Library Consumer<br/>external actor"))
  node_rendering_facade[".NET Rendering Facade<br/>library API"]
  node_cli_user(("External CLI User<br/>external actor"))
  node_cli_runner["CLI Conversion Runner<br/>CLI application"]
  node_demo_user(("External Browser-Demo User<br/>external actor"))
  node_demo_host["WebAssembly Demo Host<br/>[Program.cs]"]
end

subgraph group_content["Content and Layout"]
  node_content_source(("External Content Source<br/>external resource"))
  node_resource_loader["Resource Loading<br/>resource loader"]
  node_css_engine["CSS Parser and Cascade<br/>CSS subsystem"]
  node_html_layout["HTML Layout Engine<br/>layout subsystem"]
  node_content_engine["Generated Content Resolver<br/>CSS content subsystem"]
  node_counter_engine["CSS Counter Resolver<br/>CSS counter subsystem"]
end

subgraph group_text["Text and Fonts"]
  node_bidi["Bidi Text Shaping<br/>text subsystem"]
  node_hyphenation["Automatic Hyphenation<br/>text subsystem"]
  node_fonts["Font and OpenType Processing<br/>font subsystem"]
end

subgraph group_specialized["Specialized Layout"]
  node_svg["SVG Rendering<br/>vector subsystem"]
  node_mathml["MathML Layout Engine<br/>math layout subsystem"]
end

subgraph group_output["PDF Output"]
  node_pdf_backend["PDF Graphics Backend<br/>PDF backend"]
  node_pdf_destination["PDF Output Destination<br/>external output"]
end

node_library_consumer -->|"invokes API"| node_rendering_facade
node_rendering_facade -->|"requests resources"| node_resource_loader
node_resource_loader -->|"reads resources"| node_content_source
node_rendering_facade -->|"submits document"| node_html_layout
node_html_layout -->|"applies CSS"| node_css_engine
node_html_layout -->|"resolves content"| node_content_engine
node_content_engine -->|"parses values"| node_css_engine
node_content_engine -->|"resolves counters"| node_counter_engine
node_html_layout -->|"reorders text"| node_bidi
node_html_layout -->|"requests hyphenation"| node_hyphenation
node_html_layout -->|"renders SVG"| node_svg
node_html_layout -->|"dispatches MathML"| node_mathml
node_mathml -->|"resolves math fonts"| node_fonts
node_html_layout -->|"renders PDF"| node_pdf_backend
node_pdf_backend -->|"writes document"| node_pdf_destination
node_rendering_facade -->|"returns document"| node_library_consumer
node_cli_user -->|"starts conversion"| node_cli_runner
node_cli_runner -->|"creates PDF file"| node_pdf_destination
node_demo_user -->|"supplies content"| node_demo_host
node_demo_host -->|"renders locally"| node_rendering_facade

click node_rendering_facade "https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF"
click node_cli_runner "https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF.Cli/CliRunner.cs"
click node_demo_host "https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF.Demo.BlazorWasm/Program.cs"
click node_resource_loader "https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Network"
click node_css_engine "https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/CSS"
click node_html_layout "https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Html/Core"
click node_content_engine "https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/Html/Core/Dom/CssContentEngine.cs"
click node_counter_engine "https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/Html/Core/Dom/CssCounterEngine.cs"
click node_bidi "https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Text/Bidi"
click node_hyphenation "https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/Text/HyphenationEngine.cs"
click node_fonts "https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Fonts"
click node_svg "https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Svg"
click node_mathml "https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/MathML/MathLayoutEngine.cs"
click node_pdf_backend "https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/PdfSharpCore"

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_library_consumer,node_rendering_facade,node_cli_user,node_cli_runner,node_demo_user,node_demo_host toneBlue
class node_content_source,node_resource_loader,node_css_engine,node_html_layout,node_content_engine,node_counter_engine toneAmber
class node_bidi,node_hyphenation,node_fonts toneMint
class node_svg,node_mathml toneRose
class node_pdf_backend,node_pdf_destination toneIndigo
```

## Components

### Public Interfaces

Library, CLI, and browser-demo entry points

- **.NET Library Consumer**: external actor · Calls GeneratePdf or CreateDocument and saves the returned document
- [.NET Rendering Facade](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF): library API · Documented HTML rendering, configuration, font registration, and document-building API · `src/PeachPDF`
- **External CLI User**: external actor · Invokes the peachpdf shell command
- [CLI Conversion Runner](https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF.Cli/CliRunner.cs): CLI application · Runs standalone command-line HTML-to-PDF conversion · `src/PeachPDF.Cli/CliRunner.cs`
- **External Browser-Demo User**: external actor · Supplies content to the WebAssembly demo
- [WebAssembly Demo Host](https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF.Demo.BlazorWasm/Program.cs): demo host · Hosts browser-local rendering for HTML, MHTML, and ZIP input · `src/PeachPDF.Demo.BlazorWasm/Program.cs`

### Content and Layout

Resource loading, CSS, HTML layout, and generated content

- **External Content Source**: external resource · Caller-selected local files, MHTML streams, or HTTP URI resources
- [Resource Loading](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Network): resource loader · Resolves HTML and relative stylesheets, images, and fonts · `src/PeachPDF/Network`
- [CSS Parser and Cascade](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/CSS): CSS subsystem · Parses CSS rules, selectors, values, and typed properties · `src/PeachPDF/CSS`
- [HTML Layout Engine](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Html/Core): layout subsystem · Builds box trees, paginates, fragments, paints, and renders documents · `src/PeachPDF/Html/Core`
- [Generated Content Resolver](https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/Html/Core/Dom/CssContentEngine.cs): CSS content subsystem · Resolves content tokens, quotes, images, counters, strings, and leaders · `src/PeachPDF/Html/Core/Dom/CssContentEngine.cs`
- [CSS Counter Resolver](https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/Html/Core/Dom/CssCounterEngine.cs): CSS counter subsystem · Handles counter inheritance, resets, increments, and formatting · `src/PeachPDF/Html/Core/Dom/CssCounterEngine.cs`

### Text and Fonts

Text direction, hyphenation, and font processing

- [Bidi Text Shaping](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Text/Bidi): text subsystem · Provides text direction and UAX#9 line reordering · `src/PeachPDF/Text/Bidi`
- [Automatic Hyphenation](https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/Text/HyphenationEngine.cs): text subsystem · Loads language patterns and computes hyphenation points · `src/PeachPDF/Text/HyphenationEngine.cs`
- [Font and OpenType Processing](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Fonts): font subsystem · Provides font discovery, fallback, metrics, glyph selection, and OpenType data · `src/PeachPDF/Fonts`

### Specialized Layout

SVG and MathML rendering

- [SVG Rendering](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/Svg): vector subsystem · Renders inline and referenced SVG content as native vectors · `src/PeachPDF/Svg`
- [MathML Layout Engine](https://github.com/jhaygood86/peachpdf/blob/main/src/PeachPDF/MathML/MathLayoutEngine.cs): math layout subsystem · Positions MathML boxes using OpenType MATH metrics and glyph assemblies · `src/PeachPDF/MathML/MathLayoutEngine.cs`

### PDF Output

PDF serialization and output destinations

- [PDF Graphics Backend](https://github.com/jhaygood86/peachpdf/tree/main/src/PeachPDF/PdfSharpCore): PDF backend · Embedded document, drawing, structure, annotation, and serialization implementation · `src/PeachPDF/PdfSharpCore`
- **PDF Output Destination**: external output · Returned document and stream or file destination written through Save

## Connections

- .NET Library Consumer → .NET Rendering Facade: invokes API · Calls GeneratePdf or CreateDocument
- .NET Rendering Facade → Resource Loading: requests resources · Requests configured content and relative assets when using a NetworkLoader
- Resource Loading → External Content Source: reads resources · Reads local, MHTML, or HTTP-backed document resources
- .NET Rendering Facade → HTML Layout Engine: submits document · Submits HTML or a declaratively built document for rendering
- HTML Layout Engine → CSS Parser and Cascade: applies CSS · Applies parsed and resolved properties during box layout
- HTML Layout Engine → Generated Content Resolver: resolves content · Resolves pseudo-element and box content during layout
- Generated Content Resolver → CSS Parser and Cascade: parses values · Tokenizes and parses content and image values
- Generated Content Resolver → CSS Counter Resolver: resolves counters · Uses the shared counter-style resolver for counter content
- HTML Layout Engine → Bidi Text Shaping: reorders text · Applies bidi resolution and line reordering
- HTML Layout Engine → Automatic Hyphenation: requests hyphenation · Requests points for hyphens: auto
- HTML Layout Engine → SVG Rendering: renders SVG · Renders supported SVG document content as vectors
- HTML Layout Engine → MathML Layout Engine: dispatches MathML · Dispatches inline MathML to specialized layout
- MathML Layout Engine → Font and OpenType Processing: resolves math fonts · Reads OpenType MATH metrics and assemblies
- HTML Layout Engine → PDF Graphics Backend: renders PDF · Renders the laid-out document into a PDF representation
- PDF Graphics Backend → PDF Output Destination: writes document · Materializes the PDF document callers save
- .NET Rendering Facade → .NET Library Consumer: returns document · Returns the generated PDF document
- External CLI User → CLI Conversion Runner: starts conversion · Invokes peachpdf report.html -o report.pdf
- CLI Conversion Runner → PDF Output Destination: creates PDF file · Creates the requested PDF file
- External Browser-Demo User → WebAssembly Demo Host: supplies content · Supplies browser-local HTML, MHTML, or ZIP content
- WebAssembly Demo Host → .NET Rendering Facade: renders locally · Uses the same library in WebAssembly
