Architecture Overview
This project uses a containerized microservice architecture to handle automated PDF generation. Each service in the stack is responsible for a well-defined role, and together they form a seamless workflow.
High-Level Design
- n8n – Orchestrates workflows, collects data, and triggers document generation.
- nginx + PHP-FPM – Renders dynamic HTML templates (invoices, quotes, certificates).
- Gotenberg – Converts HTML documents into professional, branded PDFs.
- Cloudflare Tunnel – Provides secure remote access without opening firewall ports.
- Docker Compose – Ties all services together in a portable, reproducible setup.
Architecture Diagram
Component Breakdown
🔹 n8n
- Acts as the central automation engine.
- Fetches data from APIs or databases.
- Calls the PHP templates to generate HTML.
- Sends HTML to Gotenberg for PDF rendering.
- Distributes final PDF (email, storage, CRM upload).
🔹 nginx + PHP-FPM
- nginx handles HTTP requests and routes them to PHP-FPM.
- PHP-FPM executes dynamic PHP templates (e.g.,
invoice.php
,quote.php
). - Templates accept variables (e.g., customer name, price, date) and output HTML.
- Output HTML is passed to Gotenberg for PDF conversion.
🔹 Gotenberg
- A headless Chrome-based PDF generation service.
- Converts HTML → PDF with consistent formatting and styling.
- Ensures brand elements (logos, fonts, headers, footers) are preserved.
🔹 Cloudflare Tunnel
- Securely exposes the internal services to the outside world.
- Eliminates the need for port forwarding or exposing Docker containers directly.
- Managed with a simple
TUNNEL_TOKEN
for authentication.
🔹 Docker Compose
- Defines and runs the entire stack with a single command.
- Manages networking, volumes, and service dependencies.
- Enables easy updates (
docker-compose pull && docker-compose up -d
).
Data Flow (Step-by-Step)
- Trigger: A workflow in n8n starts (e.g., new invoice created in ERP).
- Template Rendering: n8n makes an HTTP request to nginx → PHP template.
- HTML Generation: PHP template fills variables (customer name, prices, etc.) and outputs branded HTML.
- PDF Conversion: n8n sends HTML to Gotenberg API.
- PDF Delivery: n8n stores, emails, or sends the PDF to a business system.
- Secure Access: If needed, Cloudflare Tunnel exposes the system externally.
Benefits of This Architecture
- Modular: Each service can be replaced or upgraded independently.
- Portable: Entire stack is containerized → easy to deploy anywhere.
- Scalable: Can add replicas of Gotenberg or n8n for higher workloads.
- Secure: Cloudflare Tunnel removes need for public IP or firewall tweaks.