# ramdhanrs/codeigniter-pdf-generator-library architecture

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

- Interactive diagram: https://gitdiagram.com/ramdhanrs/codeigniter-pdf-generator-library
- Repository: https://github.com/ramdhanrs/codeigniter-pdf-generator-library

## Overview

##### Project type and purpose
- This is an “open-source tool” / CodeIgniter library whose sole responsibility is to take a CI view, hand the rendered HTML to the domPDF engine, and stream back a PDF to the client.
- It is not a full-stack app—it plugs into an existing CodeIgniter MVC app.

##### High-level components
a. CodeIgniter Application
- Controllers (your app controllers invoking the PDF library)
- Views (HTML templates to be converted)
b. PDF Generator Library (pdf.php)
- A CI library wrapper that provides a simple API: load_view(), render(), stream()
c. domPDF Engine
- External PHP library that transforms HTML+CSS into PDF bytes
d. Web Server / PHP Runtime
- Apache/Nginx + PHP executing CI + pdf.php + dompdf
e. Client Browser
- Receives the PDF stream as an HTTP response

##### Component interactions and data flow
1. Client issues HTTP request → Web Server
2. CodeIgniter Router dispatches to Controller
3. Controller loads PDF library (`$this->load->library('pdf')`)
4. Controller calls `pdf->load_view('some_view', $data)`
– CI View parser generates HTML output
5. PDF library passes HTML string into domPDF API
6. domPDF processes HTML/CSS → internal layout → PDF binary
7. PDF library calls dompdf->stream("filename.pdf")
8. PDF bytes sent as HTTP response with PDF headers → Client

##### Architectural patterns / principles
- Single-Responsibility: pdf.php only handles PDF orchestration, not view logic.
- Adapter/Wrapper: pdf.php adapts domPDF’s API to a CodeIgniter-friendly interface.
- Modular & Pluggable: the library lives in CI’s libraries directory and can be replaced/updated independently.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client Browser<br/>(Receives PDF)"]:::client

    %% Web Server
    Server["Web Server / PHP Runtime"]:::server

    %% CodeIgniter App
    subgraph "CodeIgniter App"
        CIController["CI Controller"]:::ci
        View["CI View (HTML Template)"]:::ci
    end

    %% PDF Library
    PDFLib["PDF Generator Library<br/>(pdf.php)"]:::pdflib

    %% domPDF Engine
    dom["domPDF Engine"]:::dom

    %% Project Files
    subgraph "Project Files"
        README["README.md"]:::docs
        LICENSE["LICENSE"]:::docs
        GITIGNORE[".gitignore"]:::docs
    end

    %% Flow
    Client -->|"HTTP Request"| Server
    Server -->|"Router dispatches"| CIController
    CIController -->|"load library"| PDFLib
    PDFLib -->|"load_view()"| View
    View -->|"HTML output"| PDFLib
    PDFLib -->|"HTML string"| dom
    dom -->|"PDF bytes"| PDFLib
    PDFLib -->|"stream() (PDF response)"| Server
    Server -->|"HTTP Response (PDF)"| Client

    %% Click events
    click PDFLib "https://github.com/ramdhanrs/codeigniter-pdf-generator-library/blob/master/libraries/pdf.php"
    click README "https://github.com/ramdhanrs/codeigniter-pdf-generator-library/blob/master/README.md"
    click LICENSE "https://github.com/ramdhanrs/codeigniter-pdf-generator-library/tree/master/LICENSE"
    click GITIGNORE "https://github.com/ramdhanrs/codeigniter-pdf-generator-library/blob/master/.gitignore"

    %% Styles
    classDef client fill:#fff2b2,stroke:#e6c200,color:#333;
    classDef server fill:#d9d9d9,stroke:#999,color:#333;
    classDef ci fill:#cce5ff,stroke:#4da3ff,color:#333;
    classDef pdflib fill:#ffe0b3,stroke:#ff9900,color:#333;
    classDef dom fill:#d9f2d9,stroke:#33cc33,color:#333;
    classDef docs fill:#f2f2f2,stroke:#cccccc,color:#333;
```
