A high-performance, containerized Node.js REST API microservice optimized for programmatically compiling dynamic HTML templates into production-grade PDFs. It processes JSON arrays and maps complex data fields into customized, highly polished document layouts at scale.
This microservice serves as an automated report layout manager. It is designed to decouple document generation workflows from main application engines, leveraging headless browser rendering inside an ultra-lean deployment environment.
- Automated PDF Compilation: Utilizes Puppeteer to orchestrate a headless Chromium instance, instantly transforming dynamically rendered HTML/CSS data templates into pixel-perfect PDF documents.
- Streamlined Containerization: Packaged entirely using Docker with an Alpine Linux base image, minimizing container size, ensuring isolation, and reducing runtime memory overhead.
- Dynamic Mapping Engine: Parses and maps structured complex JSON arrays into specified template layouts on the fly, rendering tables, lists, invoice parameters, and structural markers.
- RESTful Microservice Architecture: Exposes secure, lightweight HTTP endpoints built using Node.js and Express.js, making it easy to plug into any frontend or backend ecosystem.
- Runtime Environment: Node.js
- Backend Framework: Express.js
- Automation Engine: Puppeteer (Headless Chromium)
- DevOps & Infrastructure: Docker, Docker Compose, Alpine Linux
- Testing Tooling: Postman, Jest
├── config/ # Puppeteer and browser launch options
├── controllers/ # Document layout handlers and JSON parsing logic
├── templates/ # HTML/CSS skeleton layouts for report variations
├── routes/ # RESTful API route definitions (e.g., /api/generate)
├── utils/ # Clean helper functions (file I/O, base64 data streams)
├── Dockerfile # Multi-stage optimized Alpine Linux container build
├── docker-compose.yml # Local multi-service orchestrator setup
└── server.js # Microservice bootstrapper and application entry
- Docker Desktop installed OR Node.js (v18+)
- Clone the project repository:
git clone https://github.com cd doc-engine-api - Spin up the isolated container microservice:
The microservice server instance will initialize at
docker-compose up --build
http://localhost:5000.
- Install backend dependencies:
npm install
- Execute the local server build:
npm start
- Endpoint:
POST /api/documents/generate - Headers:
Content-Type: application/json - Payload Structure:
{
"templateName": "invoice_standard",
"dataFields": {
"invoiceId": "INV-2026-089",
"issuedDate": "2026-08-20",
"items": [
{ "description": "Consulting Services", "hours": 12, "rate": 75 }
]
}
}- Success Output: Returns a raw binary
.pdffile stream or a base64 encoded document download string.
Distributed open-source under the MIT License.