# 00dhkim/notion-marp-extension architecture

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

- Interactive diagram: https://gitdiagram.com/00dhkim/notion-marp-extension
- Repository: https://github.com/00dhkim/notion-marp-extension

## Overview

##### Project type and purpose
- This is a Chrome extension (“notion-marp-extension”) that runs entirely client-side in the browser.
- Its job is to take a Notion page, call the Notion API to fetch its contents, send that to an LLM (Gemini) to insert slide separators, render the result with the Marp library into a PDF, and download that PDF—all without a server component.

##### File structure
- Top level:
- manifest.json – Chrome Extension Manifest V3 definition
- background.js – Service Worker / background script handling messaging and API calls
- contentScript.js – Injected into Notion pages, adds the “Export → Marp” button
- options.html + options.js – Extension options UI where the user supplies Notion API and Gemini keys
- utils/marp.esm.js – The Marp rendering library, packaged for client-side PDF generation
- rollup.config.js, package.json – Build configuration and dependencies
- Build artifacts:
- After `npm run build`, a `dist/` folder holds the bundle for deployment.

##### README for additional insights
- All calls to external services (Notion API, Gemini) happen in background.js via Fetch.
- contentScript sends a Chrome runtime message to background.js when the user clicks the export button.
- The Marp library is used entirely client-side to convert Markdown to PDF.

##### Main components and interactions
a. Browser & Extension Shell
- Chrome Extension container, handling manifest, security, permissions.
b. contentScript
- Injected into Notion pages, UI component to render Export button.
- Listens for button clicks, sends messages to background.
c. background.js (Service Worker)
- Receives messages from contentScript.
- Holds user API tokens (from options page) via chrome.storage.
- Orchestrates:
1. Fetch Notion page data from Notion API.
2. Send content to Gemini LLM API to insert slide separators.
3. Receive processed Markdown.
4. Pass Markdown to Marp library for PDF generation.
- Uses utils/marp.esm.js in the bundle.
- Triggers a download of the resulting PDF in the user’s browser.
d. options UI
- options.html + options.js
- Allows user to configure and save API keys via chrome.storage.
e. External Services
- Notion REST API
- Gemini (LLM) API
f. Marp Renderer
- utils/marp.esm.js (bundled by Rollup)

##### Architectural patterns and design principles
- Chrome Extension MV* pattern
- contentScript (View/UI) ←→ background.js (Controller/Orchestrator)
- Message-passing
- Use chrome.runtime.sendMessage and onMessage to decouple UI injection from API logic.
- Client-side only
- No server deployment; all APIs are called from the browser background script.
- Modular bundling with Rollup
- Separate code into modules (utils, contentScript, background) and bundle for V3.

##### Detailed component breakdown to capture
- User’s Browser (Chrome)
- Chrome Extension Host
- manifest.json (permissions)
- contentScript.js
- background.js (Service Worker)
- options.html + options.js
- utils/marp.esm.js
- Storage
- chrome.storage (holds API keys)
- External:
- Notion REST API
- Gemini LLM API

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser/Chrome Extension Host"
        direction TB
        Manifest["manifest.json"]:::extcomp
        Content["contentScript.js"]:::extcomp
        Background["background.js"]:::extcomp
        OptionsUI["options.html"]:::extcomp
        OptionsJS["options.js"]:::extcomp
        MarpLib["utils/marp.esm.js"]:::lib
    end

    Storage["chrome.storage"]:::storage

    subgraph "External Services"
        direction TB
        Notion["Notion REST API"]:::external
        Gemini["Gemini LLM API"]:::external
    end

    Download["Browser Download API"]:::browser

    subgraph "Project Files"
        direction TB
        Rollup["rollup.config.js"]:::config
        Package["package.json"]:::config
        PackageLock["package-lock.json"]:::config
        Icons["icons/"]:::asset
        Readme["README.md"]:::doc
        Gitignore[".gitignore"]:::doc
    end

    Content -->|"exportRequest message"| Background
    Background -->|"GET page data"| Notion
    Background -->|"POST for slide segmentation"| Gemini
    Background -->|"PDF render"| MarpLib
    Background -->|"trigger download"| Download
    OptionsUI -->|"save keys"| Storage
    Background -->|"access keys"| Storage

    classDef extcomp fill:#cce5ff,stroke:#004085,color:#004085;
    classDef external fill:#d4edda,stroke:#155724,color:#155724;
    classDef lib fill:#fff3cd,stroke:#856404,color:#856404;
    classDef storage fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef browser fill:#d1ecf1,stroke:#0c5460,color:#0c5460;
    classDef config fill:#f0f3ff,stroke:#3b4cb8,color:#3b4cb8;
    classDef asset fill:#e6ffed,stroke:#1e7e34,color:#1e7e34;
    classDef doc fill:#fefefe,stroke:#6c757d,color:#6c757d;

    click Manifest "https://github.com/00dhkim/notion-marp-extension/blob/main/manifest.json"
    click Content "https://github.com/00dhkim/notion-marp-extension/blob/main/contentScript.js"
    click Background "https://github.com/00dhkim/notion-marp-extension/blob/main/background.js"
    click OptionsUI "https://github.com/00dhkim/notion-marp-extension/blob/main/options.html"
    click OptionsJS "https://github.com/00dhkim/notion-marp-extension/blob/main/options.js"
    click MarpLib "https://github.com/00dhkim/notion-marp-extension/blob/main/utils/marp.esm.js"
    click Rollup "https://github.com/00dhkim/notion-marp-extension/blob/main/rollup.config.js"
    click Package "https://github.com/00dhkim/notion-marp-extension/blob/main/package.json"
    click PackageLock "https://github.com/00dhkim/notion-marp-extension/blob/main/package-lock.json"
    click Icons "https://github.com/00dhkim/notion-marp-extension/tree/main/icons/"
    click Readme "https://github.com/00dhkim/notion-marp-extension/blob/main/README.md"
    click Gitignore "https://github.com/00dhkim/notion-marp-extension/blob/main/.gitignore"
```
