Skip to content

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

  1. n8n – Orchestrates workflows, collects data, and triggers document generation.
  2. nginx + PHP-FPM – Renders dynamic HTML templates (invoices, quotes, certificates).
  3. Gotenberg – Converts HTML documents into professional, branded PDFs.
  4. Cloudflare Tunnel – Provides secure remote access without opening firewall ports.
  5. 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)

  1. Trigger: A workflow in n8n starts (e.g., new invoice created in ERP).
  2. Template Rendering: n8n makes an HTTP request to nginx → PHP template.
  3. HTML Generation: PHP template fills variables (customer name, prices, etc.) and outputs branded HTML.
  4. PDF Conversion: n8n sends HTML to Gotenberg API.
  5. PDF Delivery: n8n stores, emails, or sends the PDF to a business system.
  6. 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.