How appvantageasia/html2pdf-service works
Project Type and Purpose
• This is a single-purpose microservice: a Restful API that converts HTML into PDF (html2pdf-service).
• It uses Node.js + TypeScript (src/*.ts), Puppeteer under the hood (browser.ts), Dockerization (docker/*), and automated CI/CD.
File Structure
• Top-level “src” directory:
• index.ts: server bootstrap
• app.ts: Express app and route definitions
• browser.ts: Puppeteer launcher (Chrome/Chromium)
• render.ts: PDF rendering logic
• “docker/chrome” & “docker/chromium” folders: custom headless browser images
• CI/CD config: .circleci/config.yml and .github/workflows/docker-publish.yml
• “docs/”: static API docs published via GitHub Pages
• k6.js: performance/load-test script
README
• Confirms REST API, PDF-from-HTML conversion.
• Links to full documentation: shows endpoints, example requests/responses.
• Mentions containerized deployment (“docker-publish.yml”).
a. Client
• Any HTTP client (curl, Postman, frontend app, other microservice)
b. API Gateway / Node.js Server
• Express-based HTTP server (src/app.ts, src/index.ts)
c. PDF Generation Module
• Puppeteer wrapper (src/browser.ts)
• Rendering logic (src/render.ts)
d. Headless Browser Container
• Custom Chrome/Chromium Docker images (docker/chrome, docker/chromium)
e. CI/CD Pipeline
• CircleCI and GitHub Actions build → test → publish Docker image
f. Documentation Site
• Static API docs hosted on GitHub Pages (docs/)
1. Client sends HTTP POST (HTML payload) →
2. API Server receives request →
3. API calls PDF Generation Module →
4. Module spawns Puppeteer in headless container →
5. Puppeteer navigates to HTML → generates PDF stream →
6. Module returns PDF to API →
7. API streams PDF back to Client
8. CI/CD pipeline monitors repo → builds Docker image → pushes to registry
9. Documentation site is updated on GitHub Pages commits
Architectural Patterns & Design Principles
• Single-Responsibility Service: one API, one job (HTML → PDF).
• Modular Code: separation of HTTP handling (app.ts), business logic (render.ts), browser orchestration (browser.ts).
• Containerization: isolates dependencies (Chrome/Chromium) from host environment.
• CI/CD automation: ensures images are tested & published on push/tag.
Technologies & Frameworks to Annotate
• Node.js + TypeScript
• Express.js (HTTP routing)
• Puppeteer (headless browser)
• Docker (service & browser images)
• CircleCI / GitHub Actions (CI/CD)
• Yarn 3 (package management)
• k6 (load testing)
Essential Elements
• Client → API Server (Express)
• API Server → PDF Module (render.ts)
• PDF Module → Headless Browser (Puppeteer in Docker)
• CI/CD Toolchain → Docker Registry → Deployment
• Static Documentation Site