# ilaborie/html2pdf architecture

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

- Interactive diagram: https://gitdiagram.com/ilaborie/html2pdf
- Repository: https://github.com/ilaborie/html2pdf

## Overview

##### Main Components
- CLI Entry Point – Represented by src/main.rs which initializes the program.
- Argument Parsing Module – Handled in src/cli.rs where all command-line options, flags, and input file parameters are parsed.
- Core Conversion Logic – Contained in src/lib.rs that abstracts and orchestrates the conversion process (interacting with headless_chrome, handling options such as landscape mode, background printing, and header/footer templates).

##### Relationships and Data Flow
- Start at the CLI entry point (src/main.rs) which captures the command-line input.
- From the Argument Parsing module, flow into the core library module (src/lib.rs) that performs the actual conversion logic. Show how parameters and configuration are passed along.
- An “Environment Config” node to represent configuration values and logging options (like RUST_LOG) that influence behavior.

##### Architectural Patterns and Design Principles
- Layered separation: an interface layer (CLI), a business logic layer (conversion routines), and an integration layer (headless chrome).
- Although simple, note that the project design follows the Single Responsibility Principle by separating argument parsing from core functionality.
- The modular structure (separated into src/cli.rs, src/lib.rs, and src/main.rs) indicates that each component has a dedicated, well-defined role.

##### Technologies and Frameworks
- Rust and Cargo – Represent the build and dependency management system.
- headless_chrome crate – As the external library providing browser automation.
- GitHub Actions (visible from the .github directory) can be mentioned as part of the project’s CI/CD pipeline, but are not central to the runtime architecture.

##### Additional Elements
- Labels for each component with details such as file names.
- Annotations to indicate that the primary functionality is to convert HTML to PDF using a headless browser.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        cliMain["CLI Entry Point (src/main.rs)"]:::cli
        cliArg["Argument Parsing (src/cli.rs)"]:::cli
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        conv["Conversion Logic (src/lib.rs)"]:::business
    end

    %% External Dependency and Environment Configuration
    ext["headless_chrome (dependency)"]:::external
    env["Environment Config (.env)"]:::config

    %% Data Flow
    cliMain -->|"initiates"| cliArg
    cliArg -->|"parses_options"| conv
    conv -->|"calls_browser"| ext
    env -->|"supplies_config"| conv

    %% Click Events
    click cliMain "https://github.com/ilaborie/html2pdf/blob/main/src/main.rs"
    click cliArg "https://github.com/ilaborie/html2pdf/blob/main/src/cli.rs"
    click conv "https://github.com/ilaborie/html2pdf/blob/main/src/lib.rs"
    click ext "https://github.com/ilaborie/html2pdf/blob/main/Cargo.toml"
    click env "https://github.com/ilaborie/html2pdf/blob/main/.env"

    %% Styles
    classDef cli fill:#a2d2ff,stroke:#000,stroke-width:2px;
    classDef business fill:#caffbf,stroke:#000,stroke-width:2px;
    classDef external fill:#ffb4a2,stroke:#000,stroke-width:2px;
    classDef config fill:#f0efeb,stroke:#000,stroke-width:2px;
```
