# robbiesymonds/blueprint-pdf architecture

> Architecture diagram of the GitHub repository robbiesymonds/blueprint-pdf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/robbiesymonds/blueprint-pdf
- Repository: https://github.com/robbiesymonds/blueprint-pdf

## Overview

##### Overall Components
- Library Core: This consists of the “core” directory that holds the main implementation files (blueprint.ts, index.ts, types.ts). These files define the Blueprint class, the BlueprintSchema, and types that govern how the schematic is interpreted and rendered.
- Examples: There are example applications provided in “examples/client” and “examples/server”. These illustrate how the library can be used in both browser and Node.js contexts by showing an HTML client setup and an Express-like server app.
- Configuration & Meta: The project also includes standard configuration files (tsconfig.json, package.json, etc.) which ensure correct TypeScript compilation and dependency management.

##### Relationships and Interactions
- When “generate()” is called on a Blueprint instance, the engine processes the schema, converting these defined components into jsPDF instructions. This output (buffer/string/blob) is then returned.
- The CLI package simply wraps the core library functionality in a command-line interface, exposing it to end users who need to generate PDFs from JSON data without writing code.
- The examples in “examples/…” demonstrate integration and usage: one example runs in a browser (using Blobs and URL.createObjectURL) while the other shows server-side usage, indicating flexibility in deployment.

##### Architectural Patterns and Design Principles
- Modularized Design: The code is split between core logic, CLI interface, and examples. This separation promotes reuse of the core PDF generation functionality.
- Separation of Concerns: The blueprint schema definition is kept separate from the actual rendering logic; client and server examples illustrate how the same core library can be used in different runtime environments.
- Lightweight & Extensible: As indicated in the README, the library avoids heavy dependencies (no headless browser) and instead focuses on compile-time defined templates. The design supports dynamic templating through loops, conditionals, and style definitions.

##### Technologies, Frameworks, and Libraries
- TypeScript is used throughout, with type definitions playing a key role in the strongly-typed schema descriptions.
- jsPDF is used as underlying technology to convert the schema into PDF instructions.
- Node.js environment is supported (as well as browser usage), as shown by the examples and CLI’s reliance on Node.
- The CLI tool’s package.json and TypeScript config indicate typical npm package management and build processes.

##### Specific Elements
- “Core Library (blueprint-pdf)” with sub-nodes: “Blueprint”, “BlueprintSchema”, “Rendering Logic”
- “CLI Tool (@blueprint-pdf/cli)” showing that it acts as a wrapper around the core library.
- “Client Example” and “Server Example” illustrating how the library is consumed.
- “Configuration Files” (tsconfig.json, package.json) that support building and versioning.
- The flow from schema definition (with loops, conditionals, styles) into the Blueprint instance.
- The PDF generation process from the Blueprint instance to the jsPDF engine, and finally to the output (Buffer, Blob, etc.).
- Another for interfaces/CLI, and
- A different one for examples (client and server).
- Annotations to highlight architectural patterns (separation of concerns, modular design) and external dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User Input (Custom Blueprint Schema)"]:::core

    subgraph "Core Library (blueprint-pdf)"
        B1["Blueprint"]:::core
        B2["Core Index"]:::core
        B3["Types"]:::core
    end

    A -->|"feeds"| B1
    A -->|"feeds"| B2
    A -->|"feeds"| B3

    D["jsPDF Engine"]:::dependency
    B1 -->|"generates PDF via"| D
    B2 -->|"uses"| D
    B3 -->|"uses"| D

    E["PDF Output (Buffer/Blob/String)"]:::core
    D -->|"outputs"| E

    subgraph "CLI Tool (@blueprint-pdf/cli)"
        C1["CLI Interface"]:::cli
        C2["CLI package.json"]:::cli
        C3["CLI tsconfig.json"]:::cli
    end

    B2 -->|"wrapped by"| C1

    subgraph "Examples"
        X1["Client Example (Browser)"]:::example
        X2["Server Example (Node.js)"]:::example
    end

    E -->|"used in"| X1
    E -->|"used in"| X2

    subgraph "Configuration & Meta"
        M1["Root package.json"]:::config
        M2["Root tsconfig.json"]:::config
        M3[".gitignore"]:::config
        M4["README.md"]:::config
    end

    M1 ---|"configures"| B2
    M2 ---|"configures"| B2
    M3 ---|"ignored by"| B2
    M4 ---|"docs"| B2
    M1 ---|"configures"| C1
    M2 ---|"configures"| C1

    classDef core fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef cli fill:#ABEBC6,stroke:#1E8449,stroke-width:2px;
    classDef example fill:#F9E79F,stroke:#CA6F1E,stroke-width:2px;
    classDef config fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef dependency fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;

    click B1 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/core/blueprint.ts"
    click B2 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/core/index.ts"
    click B3 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/core/types.ts"
    click C1 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/cli/src/index.ts"
    click C2 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/cli/package.json"
    click C3 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/cli/tsconfig.json"
    click X1 "https://github.com/robbiesymonds/blueprint-pdf/tree/main/examples/client/"
    click X2 "https://github.com/robbiesymonds/blueprint-pdf/tree/main/examples/server/"
    click M1 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/package.json"
    click M2 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/tsconfig.json"
    click M3 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/.gitignore"
    click M4 "https://github.com/robbiesymonds/blueprint-pdf/blob/main/README.md"
```
