# mrmps/pdf2md architecture

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

- Interactive diagram: https://gitdiagram.com/mrmps/pdf2md
- Repository: https://github.com/mrmps/pdf2md

## Overview

##### Project type and overall purpose
- This is a browser-based, single-page application built with Next.js (App Router), React, TypeScript, and Tailwind CSS.
- There is no back-end or server-side data storage; all PDF processing happens locally in the user’s browser via the `@opendocsg/pdf2md` library.
- The app is statically hosted (e.g., on Vercel, Netlify, or any static‐file server).

##### Main architectural components
a. Static Host / CDN
- Serves built assets: HTML, JS bundles, CSS, images (in `public/`)
- Examples: Vercel, Netlify, AWS S3 + CloudFront
b. Next.js Build Process (Node.js)
- Transpiles TypeScript (`tsconfig.json`)
- Bundles React components (`app/`, `components/`, `hooks/`)
- Processes Tailwind CSS (`tailwind.config.ts`, `postcss.config.mjs`)
c. Browser Client (Runtime)
1. UI Layer
– Layout & routing (`app/layout.tsx`, `app/page.tsx`)
– Theme & style providers (`components/theme-provider.tsx`, `app/globals.css`)
– Core React components (`components/…`, `components/ui/…`)
2. PDF Upload & Conversion
– File Uploader (`components/file-uploader.tsx`)
– Conversion Engine: `@opendocsg/pdf2md` (invoked from `pdf2md-loader.tsx`)
3. Markdown Preview & Output
– Markdown Previewer (`components/markdown-preview.tsx`)
– Download / Copy UI (`components/pdf2md-loader.tsx` & download button)
4. Utility Hooks & Helpers
– `hooks/use-toast.ts` (notifications)
– `hooks/use-mobile.tsx` (responsive behavior)
– `lib/utils.ts` (shared utilities)

##### Relationships and data flow
- User → Browser UI → File Uploader
- Uploaded PDF → `pdf2md` library (in-browser) → Markdown string
- Markdown string → Markdown Preview component → Rendered HTML
- User actions → Download / Copy operations
- Toasts & alerts reflect success/failure at each step

##### Architectural patterns & principles
- Component-based UI (React + shadcn/ui)
- Separation of concerns:
- Layout & routing ↔ UI components ↔ business logic (conversion) ↔ utilities
- Zero trust / privacy-first: all data stays on client
- Offline-capable static PWA

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::user
    Browser["Browser"]:::browser

    subgraph "Static Hosting / CDN"
        SH["Static Host / CDN"]:::host
    end

    subgraph "Build & Deployment"
        TS["tsconfig.json"]:::build
        NC["next.config.mjs"]:::build
        PKG["package.json"]:::build
        TW["tailwind.config.ts"]:::build
        PC["postcss.config.mjs"]:::build
    end

    subgraph "Browser Runtime (Client)"
        subgraph "Layout & Routing"
            Layout["app/layout.tsx"]:::component
            Page["app/page.tsx"]:::component
            Globals["app/globals.css"]:::component
        end
        Theme["components/theme-provider.tsx"]:::component
        subgraph "Core React Components"
            FAQ["components/faq-section.tsx"]:::component
            GitHub["components/github-star-button.tsx"]:::component
            UI["components/ui/..."]:::component
        end
        Uploader["components/file-uploader.tsx"]:::component
        Loader["components/pdf2md-loader.tsx"]:::component
        Preview["components/markdown-preview.tsx"]:::component
        subgraph "Utilities & Hooks"
            ToastHook["hooks/use-toast.ts"]:::component
            ToastUI["components/ui/use-toast.ts"]:::component
            MobileHook["hooks/use-mobile.tsx"]:::component
            MobileUI["components/ui/use-mobile.tsx"]:::component
            Utils["lib/utils.ts"]:::component
        end
        PDF2MD["@opendocsg/pdf2md"]:::library
    end

    %% Connections
    SH -->|Serves assets| Browser
    TS --> SH
    NC --> SH
    PKG --> SH
    TW --> SH
    PC --> SH

    Browser -->|Loads UI| Layout
    Layout --> Page
    Page --> Uploader
    Uploader --> Loader
    Loader --> PDF2MD
    PDF2MD --> Preview
    Preview -->|Render Markdown| Browser
    User -->|Upload PDF| Uploader
    User -->|Download/Copy| Preview

    %% Click Events
    click SH "https://github.com/mrmps/pdf2md/tree/main/public/"
    click TS "https://github.com/mrmps/pdf2md/blob/main/tsconfig.json"
    click NC "https://github.com/mrmps/pdf2md/blob/main/next.config.mjs"
    click PKG "https://github.com/mrmps/pdf2md/blob/main/package.json"
    click TW "https://github.com/mrmps/pdf2md/blob/main/tailwind.config.ts"
    click PC "https://github.com/mrmps/pdf2md/blob/main/postcss.config.mjs"
    click Layout "https://github.com/mrmps/pdf2md/blob/main/app/layout.tsx"
    click Page "https://github.com/mrmps/pdf2md/blob/main/app/page.tsx"
    click Globals "https://github.com/mrmps/pdf2md/blob/main/app/globals.css"
    click Theme "https://github.com/mrmps/pdf2md/blob/main/components/theme-provider.tsx"
    click FAQ "https://github.com/mrmps/pdf2md/blob/main/components/faq-section.tsx"
    click GitHub "https://github.com/mrmps/pdf2md/blob/main/components/github-star-button.tsx"
    click UI "https://github.com/mrmps/pdf2md/tree/main/components/ui/"
    click Uploader "https://github.com/mrmps/pdf2md/blob/main/components/file-uploader.tsx"
    click Loader "https://github.com/mrmps/pdf2md/blob/main/components/pdf2md-loader.tsx"
    click Preview "https://github.com/mrmps/pdf2md/blob/main/components/markdown-preview.tsx"
    click ToastHook "https://github.com/mrmps/pdf2md/blob/main/hooks/use-toast.ts"
    click ToastUI "https://github.com/mrmps/pdf2md/blob/main/components/ui/use-toast.ts"
    click MobileHook "https://github.com/mrmps/pdf2md/blob/main/hooks/use-mobile.tsx"
    click MobileUI "https://github.com/mrmps/pdf2md/blob/main/components/ui/use-mobile.tsx"
    click Utils "https://github.com/mrmps/pdf2md/blob/main/lib/utils.ts"

    %% Styles
    classDef host fill:#e0f7fa,stroke:#0288d1,color:#01579b;
    classDef build fill:#f1f8e9,stroke:#689f38,color:#33691e;
    classDef browser fill:#fff3e0,stroke:#ef6c00,color:#e65100;
    classDef component fill:#e8eaf6,stroke:#5c6bc0,color:#283593;
    classDef library fill:#fce4ec,stroke:#d81b60,color:#880e4f;
    classDef user fill:#ede7f6,stroke:#7e57c2,color:#4a148c;
```
