# lulzx/tinypdf architecture

> Architecture diagram of the GitHub repository lulzx/tinypdf, 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/lulzx/tinypdf
- Repository: https://github.com/lulzx/tinypdf

## Overview

tinypdf is a minimal, dependency-free PDF creation library. A caller creates a document, adds pages with drawing callbacks, then builds bytes or a stream; the separate Markdown helper lays out Markdown into pages using the same document API. The implementation is concentrated in `src/index.ts`; the graph separates its main runtime responsibilities. The README documents the broader feature set, while sampled excerpts show only selected internal calls.

Main entry points: [`src/index.ts`](https://github.com/lulzx/tinypdf/blob/main/src/index.ts) (Document builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_caller(("Library caller"))
node_document["Document builder<br/>[index.ts]"]
node_canvas["Page canvas<br/>[index.ts]"]
node_text["Text metrics<br/>[index.ts]"]
node_jpeg["JPEG parser<br/>[index.ts]"]
node_serializer["PDF serializer<br/>[index.ts]"]
node_markdown["Markdown layout<br/>[index.ts]"]

node_caller -->|"creates document"| node_document
node_caller -->|"converts Markdown"| node_markdown
node_document -->|"adds pages"| node_canvas
node_canvas -->|"measures text"| node_text
node_canvas -->|"parses JPEG"| node_jpeg
node_document -->|"builds PDF"| node_serializer
node_markdown -->|"creates document"| node_document

click node_document "https://github.com/lulzx/tinypdf/blob/main/src/index.ts"
click node_canvas "https://github.com/lulzx/tinypdf/blob/main/src/index.ts"
click node_text "https://github.com/lulzx/tinypdf/blob/main/src/index.ts"
click node_jpeg "https://github.com/lulzx/tinypdf/blob/main/src/index.ts"
click node_serializer "https://github.com/lulzx/tinypdf/blob/main/src/index.ts"
click node_markdown "https://github.com/lulzx/tinypdf/blob/main/src/index.ts"

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_caller toneIndigo
class node_document,node_canvas,node_text,node_jpeg,node_serializer,node_markdown toneTeal
```

## Components

### Other components

- **Library caller**
- [Document builder](https://github.com/lulzx/tinypdf/blob/main/src/index.ts): `src/index.ts`
- [Page canvas](https://github.com/lulzx/tinypdf/blob/main/src/index.ts): `src/index.ts`
- [Text metrics](https://github.com/lulzx/tinypdf/blob/main/src/index.ts): `src/index.ts`
- [JPEG parser](https://github.com/lulzx/tinypdf/blob/main/src/index.ts): `src/index.ts`
- [PDF serializer](https://github.com/lulzx/tinypdf/blob/main/src/index.ts): `src/index.ts`
- [Markdown layout](https://github.com/lulzx/tinypdf/blob/main/src/index.ts): `src/index.ts`

## Connections

- Library caller → Document builder: creates document (evidence: `README.md`)
- Library caller → Markdown layout: converts Markdown (evidence: `README.md`)
- Document builder → Page canvas: adds pages (evidence: `README.md`)
- Page canvas → Text metrics: measures text (evidence: `src/index.ts`)
- Page canvas → JPEG parser: parses JPEG (evidence: `src/index.ts`)
- Document builder → PDF serializer: builds PDF (evidence: `src/index.ts`)
- Markdown layout → Document builder: creates document (evidence: `src/index.ts`)
