# slider3132/pdf-converter architecture

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

- Interactive diagram: https://gitdiagram.com/slider3132/pdf-converter
- Repository: https://github.com/slider3132/pdf-converter

## Overview

##### Project type and purpose
- This is a single-page/full-stack web application built with Next.js (App Router) that runs primarily in the browser but relies on an external PDF-generation API.
- Purpose: Let users enter text, send it to a remote service to get back a PDF blob, display that PDF, and keep a history of generated PDFs in localStorage.

##### File structure
- Top-level config and scripts:
- jest.config.ts, jest.setup.ts (tests)
- next.config.ts (Next.js settings)
- postcss.config.mjs, tailwind.config.js (CSS)
- tsconfig.json (TypeScript)
- Public assets: public/
- Source code under src/:
- src/app/ – Next.js App Router pages/layout/globals.css
- src/api/index.ts – wrapper around Axios calls to external API
- src/modules/convertor/ – core “convertTextToPDF” logic
- src/components/ – UI: TextInput, PdfViewer, HistoryWidget
- src/hooks/ – custom React hooks (localStorage, isClient)
- src/utils/ – helper functions (e.g., base64 ↔ Blob conversion)
- src/tests/ – unit tests for conversion module

##### README for additional insights
- Tech stack: Next.js 15, TypeScript, Tailwind CSS, Axios, @react-pdf-viewer/core, Jest
- Environment variables: DOMAIN and API_KEY used by convertTextToPDF
- Core flow:
- TextInput collects user text
- ConverterModule sends POST to `${DOMAIN}/create-pdf?apiKey=…`, gets Blob
- PdfViewer displays PDF via @react-pdf-viewer/core
- HistoryWidget reads/writes base64-encoded PDFs to localStorage

##### Diagramming recommendations
- From TextInput → ConverterModule → External API → ConverterModule
- From ConverterModule → PdfViewer (render path)
- From ConverterModule → localStorage (save) → HistoryWidget → PdfViewer (retrieve)
- UI components (e.g., light blue rectangles)
- Business logic modules (e.g., green rounds)
- External service (e.g., orange)
- Rectangles for components/modules

##### Detail
- Hook usage by annotating localStorage interactions with the hook names (useLocalStorageBase64).
- Don’t overcomplicate: focus on the five key elements—UI, converter logic, storage, external API, PDF viewer—and their interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraph: Next.js App Router
    subgraph "Next.js App Router" 
        direction TB
        Page["Page"] 
        Layout["Layout"] 
        GlobalsCSS["globals.css"] 
    end

    class Page,Layout,GlobalsCSS app

    %% Subgraph: UI Components
    subgraph "UI Components"
        direction TB
        TextInput["TextInput"]:::ui
        PdfViewer["PdfViewer"]:::ui
        HistoryWidget["HistoryWidget"]:::ui
    end

    %% Subgraph: Business Logic
    subgraph "Business Logic"
        direction TB
        Converter["ConverterModule"]:::logic
        APIClient["API Client"]:::logic
    end

    %% Subgraph: Hooks
    subgraph "Custom Hooks"
        direction TB
        useIsClient["useIsClient"]:::hook
        useLocalStorage["useLocalStorage"]:::hook
        useLocalStorageBase64["useLocalStorageBase64"]:::hook
    end

    %% Utility Functions
    Utils["Utils (base64↔Blob)"]:::util

    %% External API
    ExternalAPI["External PDF API\n(${DOMAIN}/create-pdf)"]:::external

    %% Storage
    LocalStorage["localStorage"]:::storage

    %% Connections
    TextInput -->|"enter text"| Converter
    Converter -->|"POST text → PDF Blob\n(env: DOMAIN, API_KEY)"| ExternalAPI
    ExternalAPI -->|"PDF Blob"| Converter
    Converter -->|"render Blob"| PdfViewer
    Converter -->|"save base64"| LocalStorage
    LocalStorage -->|"load base64"| HistoryWidget
    HistoryWidget -->|"select item"| PdfViewer
    HistoryWidget -->|"uses"| useLocalStorageBase64
    Converter -->|"uses"| APIClient
    Converter -->|"uses"| Utils
    HistoryWidget -->|"uses"| useLocalStorage
    anyclient(use detection) -->|"uses"| useIsClient

    %% App Router uses
    Page --> TextInput
    Layout --> PdfViewer
    Page --> HistoryWidget
    Layout --> GlobalsCSS

    %% Click Events
    click Page "https://github.com/slider3132/pdf-converter/blob/main/src/app/page.tsx"
    click Layout "https://github.com/slider3132/pdf-converter/blob/main/src/app/layout.tsx"
    click GlobalsCSS "https://github.com/slider3132/pdf-converter/blob/main/src/app/globals.css"
    click APIClient "https://github.com/slider3132/pdf-converter/blob/main/src/api/index.ts"
    click Converter "https://github.com/slider3132/pdf-converter/blob/main/src/modules/convertor/index.tsx"
    click TextInput "https://github.com/slider3132/pdf-converter/blob/main/src/components/TextInput.tsx"
    click PdfViewer "https://github.com/slider3132/pdf-converter/blob/main/src/components/PdfViewer.tsx"
    click HistoryWidget "https://github.com/slider3132/pdf-converter/blob/main/src/components/HistoryWidget.tsx"
    click useLocalStorage "https://github.com/slider3132/pdf-converter/blob/main/src/hooks/useLocalStorage.ts"
    click useLocalStorageBase64 "https://github.com/slider3132/pdf-converter/blob/main/src/hooks/useLocalStorageBase64.ts"
    click useIsClient "https://github.com/slider3132/pdf-converter/blob/main/src/hooks/useIsClient.ts"
    click Utils "https://github.com/slider3132/pdf-converter/blob/main/src/utils/index.ts"
    click Tests "https://github.com/slider3132/pdf-converter/blob/main/src/tests/convert.test.tsx"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef logic fill:#D0F0D0,stroke:#333,stroke-width:1px
    classDef external fill:#FFD8A8,stroke:#333,stroke-width:1px
    classDef storage fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef hook fill:#F5E0FF,stroke:#333,stroke-width:1px
    classDef util fill:#FFF4D6,stroke:#333,stroke-width:1px
    classDef app fill:#E8F5E9,stroke:#333,stroke-width:1px
    classDef test fill:#FFEBEE,stroke:#333,stroke-width:1px
```
