# iggredible/copy-formatter architecture

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

- Interactive diagram: https://gitdiagram.com/iggredible/copy-formatter
- Repository: https://github.com/iggredible/copy-formatter

## Overview

##### Project type and purpose
- This is a Chrome browser extension (“Copy Formatter”) that intercepts copy‐paste operations and applies user‐defined formatting templates (e.g., Markdown links).
- Key indicators: presence of manifest.json, background.js, src/views/popup, src/views/options, use of Chrome extension APIs, README describing a right-click/context-menu tool.

##### File structure
Top-level:
- manifest.json – extension metadata and permissions
- background.js – background script (event listeners, context menu registration)
- src/ – core logic modules (clipboard, formatters, menus, storage, defaultMenuItems)
- src/views/ – UI for popup (action and content) and options page
- package.json / package-lock.json – Node toolchain, build scripts, dependencies

Patterns & roles:
- background script = central event hub
- content script(s) (e.g., clipboard.js injected?)
- UI pages (popup.html/js, options.html/js)
- Storage module abstracts chrome.storage API
- Formatters define pluggable template functions

##### README for additional insights
- Describes workflow: select text → open context menu or keyboard shortcut → choose template → paste auto-formatted text
- Mentions “templates,” “clipboard,” “Obsidian markdown,” “Vimium integration”

##### Elements
- Blue for extension “core logic” modules
- Green for UI components
- Orange for Chrome APIs/external services

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Context
    subgraph "Browser Context"
        direction TB
        Selection["User selects text in page"]:::external
        ContextMenu["Context Menu Entry"]:::external
        Shortcut["Keyboard Shortcut (chrome.commands)"]:::external
    end

    %% Background Service
    subgraph "Background Service" 
        direction TB
        BG["background.js"]:::background
    end

    %% Core Logic Modules
    subgraph "Core Logic Modules"
        direction TB
        Menus["menus.js"]:::core
        DefaultItems["defaultMenuItems.js"]:::core
        Formatters["formatters.js"]:::core
        Storage["storage.js"]:::core
        Clipboard["clipboard.js"]:::core
    end

    %% UI Components
    subgraph "UI Components"
        direction TB
        subgraph "Popup UI"
            direction TB
            PopupActionHTML["popup.html (Action View)"]:::ui
            PopupActionJS["popup.js (Action View)"]:::ui
            PopupContentCSS["content.css (Preview)"]:::ui
            PopupContentJS["content.js (Preview)"]:::ui
        end
        subgraph "Options Page"
            direction TB
            OptionsHTML["options.html"]:::ui
            OptionsCSS["options.css"]:::ui
            OptionsJS["options.js"]:::ui
        end
    end

    %% External APIs
    subgraph "Chrome APIs & Browser"
        direction TB
        ChromeContext["chrome.contextMenus"]:::api
        ChromeCommands["chrome.commands"]:::api
        ChromeStorage["chrome.storage"]:::api
        DOMClipboard["DOM / Clipboard API"]:::api
    end

    %% Configuration & Build
    subgraph "Config & Build Tools"
        direction TB
        Manifest["manifest.json"]:::config
        IconGen["icon_generator.js"]:::build
        PackageJSON["package.json"]:::config
        PackageLock["package-lock.json"]:::config
        IconsDir["icons"]:::config
    end

    %% Data Flow & Relationships
    Selection --> ContextMenu
    Selection --> Shortcut
    ContextMenu -->|onClicked| BG
    Shortcut -->|onCommand| BG
    BG -->|register menus| Menus
    BG -->|load default items| DefaultItems
    BG -->|fetch templates| Storage
    BG -->|open popup UI| PopupActionHTML
    PopupActionHTML --> PopupActionJS
    PopupActionJS -->|send choice| BG
    BG -->|apply formatting| Formatters
    Formatters -->|formatted text| Clipboard
    Clipboard -->|write| DOMClipboard
    OptionsHTML --> OptionsJS
    OptionsJS -->|save templates| Storage
    Storage -->|use chrome.storage| ChromeStorage
    Menus -->|use chrome.contextMenus| ChromeContext
    Shortcut -->|use chrome.commands| ChromeCommands
    IconGen -->|build icons| IconsDir
    PackageJSON -->|defines script| IconGen
    PackageLock --> PackageJSON
    Manifest -->|permissions| ChromeContext
    Manifest -->|permissions| ChromeCommands
    Manifest -->|permissions| ChromeStorage
    Manifest -->|permissions| DOMClipboard

    %% Click Events
    click Manifest "https://github.com/iggredible/copy-formatter/blob/main/manifest.json"
    click BG "https://github.com/iggredible/copy-formatter/blob/main/background.js"
    click Menus "https://github.com/iggredible/copy-formatter/blob/main/src/menus.js"
    click DefaultItems "https://github.com/iggredible/copy-formatter/blob/main/src/defaultMenuItems.js"
    click Formatters "https://github.com/iggredible/copy-formatter/blob/main/src/formatters.js"
    click Clipboard "https://github.com/iggredible/copy-formatter/blob/main/src/clipboard.js"
    click Storage "https://github.com/iggredible/copy-formatter/blob/main/src/storage.js"
    click PopupActionHTML "https://github.com/iggredible/copy-formatter/blob/main/src/views/popup/action/popup.html"
    click PopupActionJS "https://github.com/iggredible/copy-formatter/blob/main/src/views/popup/action/popup.js"
    click PopupContentCSS "https://github.com/iggredible/copy-formatter/blob/main/src/views/popup/content/content.css"
    click PopupContentJS "https://github.com/iggredible/copy-formatter/blob/main/src/views/popup/content/content.js"
    click OptionsHTML "https://github.com/iggredible/copy-formatter/blob/main/src/views/options/options.html"
    click OptionsCSS "https://github.com/iggredible/copy-formatter/blob/main/src/views/options/options.css"
    click OptionsJS "https://github.com/iggredible/copy-formatter/blob/main/src/views/options/options.js"
    click IconGen "https://github.com/iggredible/copy-formatter/blob/main/scripts/icon_generator.js"
    click PackageJSON "https://github.com/iggredible/copy-formatter/blob/main/package.json"
    click PackageLock "https://github.com/iggredible/copy-formatter/blob/main/package-lock.json"
    click IconsDir "https://github.com/iggredible/copy-formatter/tree/main/icons"

    %% Styles
    classDef core fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef ui fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20;
    classDef api fill:#FFE0B2,stroke:#E65100,color:#E65100;
    classDef background fill:#E1BEE7,stroke:#4A148C,color:#4A148C;
    classDef external fill:#FFCDD2,stroke:#B71C1C,color:#B71C1C;
    classDef config fill:#CFD8DC,stroke:#37474F,color:#37474F;
    classDef build fill:#FFF9C4,stroke:#F57F17,color:#F57F17;
```
