# saad5400/html-to-pdf architecture

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

- Interactive diagram: https://gitdiagram.com/saad5400/html-to-pdf
- Repository: https://github.com/saad5400/html-to-pdf

## Overview

This is a Chromium-backed HTML/URL-to-PDF service with a one-shot CLI and synchronous and asynchronous HTTP APIs. Its main workflow accepts and validates a render request, renders a PDF, and either returns it directly or processes it as a queued job for storage and optional signed-webhook delivery. The graph also preserves documented auth, health, metrics, file-download, and playground capabilities. Relationships involving unsampled routes and app wiring are based on README statements; source excerpts establish the renderer and worker internals.

Main entry points: [`src/services/pdf/renderer.ts`](https://github.com/saad5400/html-to-pdf/blob/main/src/services/pdf/renderer.ts) (PDF renderer), [`src/worker/index.ts`](https://github.com/saad5400/html-to-pdf/blob/main/src/worker/index.ts) (Job worker), [`src/app.ts`](https://github.com/saad5400/html-to-pdf/blob/main/src/app.ts) (HTTP application), [`src/routes/convert.ts`](https://github.com/saad5400/html-to-pdf/blob/main/src/routes/convert.ts) (Sync conversion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entrypoints["Entry points"]
  node_cli["One-shot CLI<br/>[htp.ts]"]
  node_api["HTTP application<br/>[app.ts]"]
  node_convert["Sync conversion<br/>[convert.ts]"]
  node_jobs["Job endpoints<br/>[jobs.ts]"]
end

subgraph group_rendering["PDF rendering"]
  node_schema["Request validation<br/>[convert.ts]"]
  node_renderer["PDF renderer<br/>[renderer.ts]"]
  node_options["PDF options<br/>[options.ts]"]
  node_browser["Browser pool<br/>[browser-pool.ts]"]
  node_limits["Render limits<br/>[limits.ts]"]
  node_ssrf["URL safety<br/>[ssrf.ts]"]
end

subgraph group_async["Async jobs and storage"]
  node_worker["Job worker<br/>[index.ts]"]
  node_queue["Job queue<br/>[index.ts]"]
  node_jobstore[("Job results<br/>[job-store.ts]")]
  node_storage["Storage adapter<br/>[index.ts]"]
  node_local[("Local storage<br/>[local.ts]")]
  node_s3[("S3 storage<br/>[s3.ts]")]
  node_webhook["Webhook delivery<br/>[webhook.ts]"]
end

subgraph group_service["HTTP service"]
  node_auth["API-key auth<br/>[auth.ts]"]
  node_keys["API-key verification<br/>[api-key.ts]"]
  node_files["PDF downloads<br/>[files.ts]"]
  node_health["Health checks<br/>[health.ts]"]
  node_metrics["Metrics<br/>[metrics.ts]"]
  node_playground["Playground UI<br/>[playground.ts]"]
end

node_caller(("API / CLI caller"))
node_redis[("Redis")]
node_webhookconsumer(("Webhook receiver"))

node_caller -->|"invokes"| node_cli
node_cli -->|"renders with"| node_renderer
node_caller -->|"requests service"| node_api
node_api -->|"serves endpoint"| node_convert
node_api -->|"serves endpoint"| node_jobs
node_convert -->|"validates with"| node_schema
node_convert -->|"renders with"| node_renderer
node_renderer -->|"builds options"| node_options
node_renderer -->|"checks out"| node_browser
node_renderer -->|"enforces limits"| node_limits
node_renderer -->|"checks URLs"| node_ssrf
node_jobs -->|"submits jobs"| node_queue
node_worker -->|"consumes jobs"| node_queue
node_worker -->|"renders with"| node_renderer
node_worker -->|"writes results"| node_jobstore
node_worker -->|"stores PDFs"| node_storage
node_storage -.->|"selects driver"| node_local
node_storage -.->|"selects driver"| node_s3
node_worker -->|"delivers events"| node_webhook
node_webhook -->|"validates target"| node_ssrf
node_webhook -->|"posts signed event"| node_webhookconsumer
node_queue -.->|"uses backend"| node_redis
node_jobs -.->|"reads status"| node_jobstore
node_caller -->|"authenticates"| node_auth
node_auth -->|"verifies key"| node_keys
node_caller -->|"downloads PDF"| node_files
node_caller -->|"checks health"| node_health
node_caller -->|"reads metrics"| node_metrics
node_caller -->|"uses interface"| node_playground

click node_cli "https://github.com/saad5400/html-to-pdf/blob/main/src/cli/htp.ts"
click node_api "https://github.com/saad5400/html-to-pdf/blob/main/src/app.ts"
click node_convert "https://github.com/saad5400/html-to-pdf/blob/main/src/routes/convert.ts"
click node_jobs "https://github.com/saad5400/html-to-pdf/blob/main/src/routes/jobs.ts"
click node_schema "https://github.com/saad5400/html-to-pdf/blob/main/src/schemas/convert.ts"
click node_renderer "https://github.com/saad5400/html-to-pdf/blob/main/src/services/pdf/renderer.ts"
click node_options "https://github.com/saad5400/html-to-pdf/blob/main/src/services/pdf/options.ts"
click node_browser "https://github.com/saad5400/html-to-pdf/blob/main/src/services/pdf/browser-pool.ts"
click node_limits "https://github.com/saad5400/html-to-pdf/blob/main/src/security/limits.ts"
click node_ssrf "https://github.com/saad5400/html-to-pdf/blob/main/src/security/ssrf.ts"
click node_worker "https://github.com/saad5400/html-to-pdf/blob/main/src/worker/index.ts"
click node_queue "https://github.com/saad5400/html-to-pdf/blob/main/src/services/queue/index.ts"
click node_jobstore "https://github.com/saad5400/html-to-pdf/blob/main/src/services/queue/job-store.ts"
click node_storage "https://github.com/saad5400/html-to-pdf/blob/main/src/services/storage/index.ts"
click node_local "https://github.com/saad5400/html-to-pdf/blob/main/src/services/storage/local.ts"
click node_s3 "https://github.com/saad5400/html-to-pdf/blob/main/src/services/storage/s3.ts"
click node_webhook "https://github.com/saad5400/html-to-pdf/blob/main/src/services/queue/webhook.ts"
click node_auth "https://github.com/saad5400/html-to-pdf/blob/main/src/plugins/auth.ts"
click node_keys "https://github.com/saad5400/html-to-pdf/blob/main/src/services/auth/api-key.ts"
click node_files "https://github.com/saad5400/html-to-pdf/blob/main/src/routes/files.ts"
click node_health "https://github.com/saad5400/html-to-pdf/blob/main/src/routes/health.ts"
click node_metrics "https://github.com/saad5400/html-to-pdf/blob/main/src/plugins/metrics.ts"
click node_playground "https://github.com/saad5400/html-to-pdf/blob/main/src/routes/playground.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_cli,node_api,node_convert,node_jobs toneBlue
class node_schema,node_renderer,node_options,node_browser,node_limits,node_ssrf,node_redis toneAmber
class node_worker,node_queue,node_jobstore,node_storage,node_local,node_s3,node_webhook,node_caller,node_webhookconsumer toneMint
class node_auth,node_keys,node_files,node_health,node_metrics,node_playground toneRose
```

## Components

### Entry points

- [One-shot CLI](https://github.com/saad5400/html-to-pdf/blob/main/src/cli/htp.ts): `src/cli/htp.ts`
- [HTTP application](https://github.com/saad5400/html-to-pdf/blob/main/src/app.ts): `src/app.ts`
- [Sync conversion](https://github.com/saad5400/html-to-pdf/blob/main/src/routes/convert.ts): `src/routes/convert.ts`
- [Job endpoints](https://github.com/saad5400/html-to-pdf/blob/main/src/routes/jobs.ts): `src/routes/jobs.ts`

### PDF rendering

- [Request validation](https://github.com/saad5400/html-to-pdf/blob/main/src/schemas/convert.ts): `src/schemas/convert.ts`
- [PDF renderer](https://github.com/saad5400/html-to-pdf/blob/main/src/services/pdf/renderer.ts): `src/services/pdf/renderer.ts`
- [PDF options](https://github.com/saad5400/html-to-pdf/blob/main/src/services/pdf/options.ts): `src/services/pdf/options.ts`
- [Browser pool](https://github.com/saad5400/html-to-pdf/blob/main/src/services/pdf/browser-pool.ts): `src/services/pdf/browser-pool.ts`
- [Render limits](https://github.com/saad5400/html-to-pdf/blob/main/src/security/limits.ts): `src/security/limits.ts`
- [URL safety](https://github.com/saad5400/html-to-pdf/blob/main/src/security/ssrf.ts): `src/security/ssrf.ts`

### Async jobs and storage

- [Job worker](https://github.com/saad5400/html-to-pdf/blob/main/src/worker/index.ts): `src/worker/index.ts`
- [Job queue](https://github.com/saad5400/html-to-pdf/blob/main/src/services/queue/index.ts): `src/services/queue/index.ts`
- [Job results](https://github.com/saad5400/html-to-pdf/blob/main/src/services/queue/job-store.ts): `src/services/queue/job-store.ts`
- [Storage adapter](https://github.com/saad5400/html-to-pdf/blob/main/src/services/storage/index.ts): `src/services/storage/index.ts`
- [Local storage](https://github.com/saad5400/html-to-pdf/blob/main/src/services/storage/local.ts): `src/services/storage/local.ts`
- [S3 storage](https://github.com/saad5400/html-to-pdf/blob/main/src/services/storage/s3.ts): `src/services/storage/s3.ts`
- [Webhook delivery](https://github.com/saad5400/html-to-pdf/blob/main/src/services/queue/webhook.ts): `src/services/queue/webhook.ts`

### HTTP service

- [API-key auth](https://github.com/saad5400/html-to-pdf/blob/main/src/plugins/auth.ts): `src/plugins/auth.ts`
- [API-key verification](https://github.com/saad5400/html-to-pdf/blob/main/src/services/auth/api-key.ts): `src/services/auth/api-key.ts`
- [PDF downloads](https://github.com/saad5400/html-to-pdf/blob/main/src/routes/files.ts): `src/routes/files.ts`
- [Health checks](https://github.com/saad5400/html-to-pdf/blob/main/src/routes/health.ts): `src/routes/health.ts`
- [Metrics](https://github.com/saad5400/html-to-pdf/blob/main/src/plugins/metrics.ts): `src/plugins/metrics.ts`
- [Playground UI](https://github.com/saad5400/html-to-pdf/blob/main/src/routes/playground.ts): `src/routes/playground.ts`

### Other components

- **API / CLI caller**
- **Redis**
- **Webhook receiver**

## Connections

- API / CLI caller → One-shot CLI: invokes (evidence: `README.md`)
- One-shot CLI → PDF renderer: renders with (evidence: `src/cli/htp.ts`)
- API / CLI caller → HTTP application: requests service (evidence: `README.md`)
- HTTP application → Sync conversion: serves endpoint (evidence: `README.md`)
- HTTP application → Job endpoints: serves endpoint (evidence: `README.md`)
- Sync conversion → Request validation: validates with (evidence: `src/routes/convert.ts`)
- Sync conversion → PDF renderer: renders with (evidence: `src/routes/convert.ts`)
- PDF renderer → PDF options: builds options (evidence: `src/services/pdf/renderer.ts`)
- PDF renderer → Browser pool: checks out (evidence: `src/services/pdf/renderer.ts`)
- PDF renderer → Render limits: enforces limits (evidence: `src/services/pdf/renderer.ts`)
- PDF renderer → URL safety: checks URLs (evidence: `src/services/pdf/renderer.ts`)
- Job endpoints → Job queue: submits jobs (evidence: `README.md`)
- Job worker → Job queue: consumes jobs (evidence: `src/worker/index.ts`)
- Job worker → PDF renderer: renders with (evidence: `src/worker/index.ts`)
- Job worker → Job results: writes results (evidence: `src/worker/index.ts`)
- Job worker → Storage adapter: stores PDFs (evidence: `src/worker/index.ts`)
- Storage adapter → Local storage: selects driver
- Storage adapter → S3 storage: selects driver
- Job worker → Webhook delivery: delivers events (evidence: `src/worker/index.ts`)
- Webhook delivery → URL safety: validates target (evidence: `src/services/queue/webhook.ts`)
- Webhook delivery → Webhook receiver: posts signed event (evidence: `src/services/queue/webhook.ts`)
- Job queue → Redis: uses backend
- Job endpoints → Job results: reads status
- API / CLI caller → API-key auth: authenticates (evidence: `README.md`)
- API-key auth → API-key verification: verifies key (evidence: `src/plugins/auth.ts`)
- API / CLI caller → PDF downloads: downloads PDF (evidence: `README.md`)
- API / CLI caller → Health checks: checks health (evidence: `README.md`)
- API / CLI caller → Metrics: reads metrics (evidence: `README.md`)
- API / CLI caller → Playground UI: uses interface (evidence: `README.md`)
