# typpo/quickchart architecture

> Architecture diagram of the GitHub repository typpo/quickchart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/typpo/quickchart
- Repository: https://github.com/typpo/quickchart

## Overview

1. **Repository shape**
   - This is a single-process **Node.js image-rendering service**. It exposes HTTP endpoints that turn request parameters into downloadable image artifacts rather than serving a traditional UI.
   - The main app entrypoint is `index.js`; the rest of the code is organized around renderers for different output types.

2. **Core runtime**
   - The server listens on `PORT` (default **3400**) and is designed to run either directly with Node or inside the provided `Dockerfile`.
   - The README indicates native image dependencies matter: **Cairo, Pango, libjpeg, libgif**. That means the architecture depends on system-level graphics libraries, not just npm packages.

3. **Primary request surface**
   - The service centers on a few API families:
     - **`/chart`** for Chart.js-based chart images
     - **`/qr`** for QR code generation
     - **`/graphviz`** for Graphviz/DOT rendering
     - **health endpoints** such as `/healthcheck` and `/healthcheck/chart`
   - This is an API-driven image generator; request parameters define the rendered output.

4. **Chart rendering subsystem**
   - `lib/charts.js` appears to be the main chart orchestration layer, translating URL/query inputs into chart output.
   - Supporting modules such as `lib/google_image_charts.js`, `lib/svg.js`, and `lib/pdf.js` suggest the chart pipeline can emit multiple formats or compatibility variants.
   - The README emphasizes Chart.js compatibility, so the chart subsystem is the most important functional path.

5. **Chart format handling**
   - `lib/svg.js` and `lib/pdf.js` indicate a format-conversion boundary around the chart renderer:
     - raster/image generation for standard responses
     - SVG export
     - PDF export
   - This implies a rendering core plus output adapters, rather than separate implementations for each format.

6. **QR code subsystem**
   - `lib/qr.js` is a distinct renderer for QR codes, with parameters for text, size, margin, error correction, colors, and output format.
   - This is a simpler independent path than charts, but it shares the same HTTP service and response model.

7. **Graphviz subsystem**
   - `lib/graphviz.js` handles graph rendering from DOT-like input.
   - Architecturally, it is another isolated renderer behind the same API layer, which means the service is a **multi-renderer image gateway** rather than a single-purpose chart app.

8. **Shared utilities and cross-cutting logic**
   - `lib/util.js` likely contains parsing, normalization, validation, or response helpers shared by the renderers.
   - `logging.js` and `telemetry.js` are cross-cutting support modules for operational visibility and request/event reporting.

9. **Security and trust boundary**
   - The README explicitly warns that chart configs may contain **arbitrary JavaScript** and should be treated as trusted input.
   - That means the main trust boundary is at the HTTP request edge; this repo does not appear to provide strong sandboxing itself.
   - In architecture terms, this service should be diagrammed as a **trusted internal renderer**, not a safe public script execution environment.

10. **Deployment model**
   - The repo is built for containerized deployment through `Dockerfile`, with `scripts/update_docker.sh` supporting image maintenance.
   - Production usage is expected to sit behind a reverse proxy or platform ingress, but the app itself is self-contained and stateless.

11. **Health and monitoring**
   - `/healthcheck` is a lightweight liveness endpoint.
   - `/healthcheck/chart` is a heavier “render-a-chart” probe used to validate the actual rendering pipeline, not just process uptime.
   - `test/monit/` contains configuration for process supervision, indicating this service is expected to be automatically restarted if unhealthy.

12. **Testing and validation**
   - `test/ci/` contains endpoint-focused integration tests for charts, QR codes, Graphviz, helpers, and color handling.
   - `test/perf/` suggests performance/regression checks for rendering throughput or latency.
   - These tests reinforce that the important architectural boundary is the **HTTP rendering contract** plus output correctness.

13. **High-level data flow**
   - A client sends a URL with parameters.
   - `index.js` routes the request to the appropriate renderer in `lib/`.
   - The renderer parses inputs, applies chart/QR/graph logic, generates an image or document response, and returns it over HTTP.
   - Logging/telemetry capture operational events around that flow.

14. **How to draw the diagram**
   - Represent this repo as one **HTTP API service** with multiple renderer backends:
     - request ingress
     - routing/controller layer
     - chart / QR / Graphviz renderers
     - shared utilities and format adapters
     - health/ops endpoints
   - Show the native graphics/runtime dependency layer underneath, since it is essential to successful rendering.

Main entry points: [`lib/charts.js`](https://github.com/typpo/quickchart/blob/master/lib/charts.js) (Chart API), [`index.js`](https://github.com/typpo/quickchart/blob/master/index.js) (Request router), [`lib/util.js`](https://github.com/typpo/quickchart/blob/master/lib/util.js) (Helpers), [`lib/qr.js`](https://github.com/typpo/quickchart/blob/master/lib/qr.js) (QR API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_api["HTTP service"]
  node_node_service["QuickChart<br/>node server<br/>[index.js]"]
  node_node_routes["Request router<br/>http routing<br/>[index.js]"]
  node_node_health(("Health checks<br/>probe endpoints<br/>[index.js]"))
end

subgraph group_group_renderers["Renderers"]
  node_node_charts["Chart API<br/>chart renderer<br/>[charts.js]"]
  node_node_googlecharts["Google charts<br/>chart compat"]
  node_node_svg["SVG output<br/>format adapter<br/>[svg.js]"]
  node_node_pdf["PDF output<br/>format adapter<br/>[pdf.js]"]
  node_node_qr["QR API<br/>qr renderer<br/>[qr.js]"]
  node_node_graphviz["Graphviz API<br/>dot renderer<br/>[graphviz.js]"]
end

subgraph group_group_support["Support"]
  node_node_util["Helpers<br/>shared utilities<br/>[util.js]"]
  node_node_logging["Logging<br/>observability<br/>[logging.js]"]
  node_node_telemetry["Telemetry<br/>observability<br/>[telemetry.js]"]
end

subgraph group_group_ops["Ops"]
  node_node_docker["Docker<br/>deployment"]
  node_node_native[("Native libs<br/>system deps")]
  node_node_tests["Integration tests<br/>test suite<br/>[app.js]"]
  node_node_perf["Perf checks<br/>benchmark<br/>[run.sh]"]
end

node_node_service -->|"serves"| node_node_routes
node_node_routes -->|"/chart"| node_node_charts
node_node_routes -->|"/qr"| node_node_qr
node_node_routes -->|"/graphviz"| node_node_graphviz
node_node_routes -->|"health"| node_node_health
node_node_charts -->|"uses"| node_node_util
node_node_charts -->|"compat"| node_node_googlecharts
node_node_charts -->|"exports"| node_node_svg
node_node_charts -->|"exports"| node_node_pdf
node_node_qr -->|"uses"| node_node_util
node_node_graphviz -->|"uses"| node_node_util
node_node_service -->|"logs"| node_node_logging
node_node_service -->|"reports"| node_node_telemetry
node_node_docker -->|"depends on"| node_node_native
node_node_tests -.->|"verifies"| node_node_routes
node_node_perf -.->|"measures"| node_node_charts
node_node_health -->|"probes"| node_node_charts

click node_node_service "https://github.com/typpo/quickchart/blob/master/index.js"
click node_node_routes "https://github.com/typpo/quickchart/blob/master/index.js"
click node_node_health "https://github.com/typpo/quickchart/blob/master/index.js"
click node_node_charts "https://github.com/typpo/quickchart/blob/master/lib/charts.js"
click node_node_googlecharts "https://github.com/typpo/quickchart/blob/master/lib/google_image_charts.js"
click node_node_svg "https://github.com/typpo/quickchart/blob/master/lib/svg.js"
click node_node_pdf "https://github.com/typpo/quickchart/blob/master/lib/pdf.js"
click node_node_qr "https://github.com/typpo/quickchart/blob/master/lib/qr.js"
click node_node_graphviz "https://github.com/typpo/quickchart/blob/master/lib/graphviz.js"
click node_node_util "https://github.com/typpo/quickchart/blob/master/lib/util.js"
click node_node_logging "https://github.com/typpo/quickchart/blob/master/logging.js"
click node_node_telemetry "https://github.com/typpo/quickchart/blob/master/telemetry.js"
click node_node_docker "https://github.com/typpo/quickchart/tree/master/Dockerfile"
click node_node_tests "https://github.com/typpo/quickchart/blob/master/test/ci/app.js"
click node_node_perf "https://github.com/typpo/quickchart/blob/master/test/perf/run.sh"

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_node_service,node_node_routes,node_node_health toneBlue
class node_node_charts,node_node_googlecharts,node_node_svg,node_node_pdf,node_node_qr,node_node_graphviz toneAmber
class node_node_util,node_node_logging,node_node_telemetry toneMint
class node_node_docker,node_node_native,node_node_tests,node_node_perf toneRose
```

## Components

### HTTP service

Request ingress and routing

- [QuickChart](https://github.com/typpo/quickchart/blob/master/index.js): node server · Main HTTP image-rendering service entrypoint · `index.js`
- [Request router](https://github.com/typpo/quickchart/blob/master/index.js): http routing · Dispatches endpoints to the right renderer · `index.js`
- [Health checks](https://github.com/typpo/quickchart/blob/master/index.js): probe endpoints · Liveness and render-check endpoints · `index.js`

### Renderers

Primary image generation backends

- [Chart API](https://github.com/typpo/quickchart/blob/master/lib/charts.js): chart renderer · Chart.js-compatible rendering orchestration · `lib/charts.js`
- [Google charts](https://github.com/typpo/quickchart/blob/master/lib/google_image_charts.js): chart compat · Compatibility layer for Google Image Charts-style inputs · `lib/google_image_charts.js`
- [SVG output](https://github.com/typpo/quickchart/blob/master/lib/svg.js): format adapter · SVG export and response formatting · `lib/svg.js`
- [PDF output](https://github.com/typpo/quickchart/blob/master/lib/pdf.js): format adapter · PDF export and response formatting · `lib/pdf.js`
- [QR API](https://github.com/typpo/quickchart/blob/master/lib/qr.js): qr renderer · QR code generation pipeline · `lib/qr.js`
- [Graphviz API](https://github.com/typpo/quickchart/blob/master/lib/graphviz.js): dot renderer · DOT/Graphviz rendering pipeline · `lib/graphviz.js`

### Support

Shared utilities and operational concerns

- [Helpers](https://github.com/typpo/quickchart/blob/master/lib/util.js): shared utilities · Parsing, normalization, and common response helpers · `lib/util.js`
- [Logging](https://github.com/typpo/quickchart/blob/master/logging.js): observability · Request and application logging · `logging.js`
- [Telemetry](https://github.com/typpo/quickchart/blob/master/telemetry.js): observability · Operational event reporting · `telemetry.js`

### Ops

Deployment, monitoring, and validation

- [Docker](https://github.com/typpo/quickchart/tree/master/Dockerfile): deployment · Container entrypoint and runtime packaging · `Dockerfile`
- **Native libs**: system deps · Cairo, Pango, libjpeg, and libgif rendering dependencies
- [Integration tests](https://github.com/typpo/quickchart/blob/master/test/ci/app.js): test suite · Endpoint and rendering validation coverage · `test/ci/app.js`
- [Perf checks](https://github.com/typpo/quickchart/blob/master/test/perf/run.sh): benchmark · Rendering throughput and regression checks · `test/perf/run.sh`

## Connections

- QuickChart → Request router: serves · Starts the HTTP server and accepts requests
- Request router → Chart API: /chart · Routes chart requests to the chart pipeline
- Request router → QR API: /qr · Routes QR requests to the QR pipeline
- Request router → Graphviz API: /graphviz · Routes Graphviz requests to the DOT renderer
- Request router → Health checks: health · Exposes liveness and render-probe endpoints
- Chart API → Helpers: uses · Shares parsing and normalization helpers
- Chart API → Google charts: compat · Supports Google Image Charts-style behavior
- Chart API → SVG output: exports · Can emit SVG responses
- Chart API → PDF output: exports · Can emit PDF responses
- QR API → Helpers: uses · Shares request parsing and response helpers
- Graphviz API → Helpers: uses · Shares request parsing and response helpers
- QuickChart → Logging: logs · Records service activity and failures
- QuickChart → Telemetry: reports · Sends operational telemetry
- Docker → Native libs: depends on · Container runtime requires native graphics libraries
- Integration tests → Request router: verifies · Exercises HTTP rendering contract
- Perf checks → Chart API: measures · Tracks rendering performance and regressions
- Health checks → Chart API: probes · Render-check endpoint validates the chart pipeline
