# samarthpardhi/munch-the-tabs-snapper architecture

> Architecture diagram of the GitHub repository samarthpardhi/munch-the-tabs-snapper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samarthpardhi/munch-the-tabs-snapper
- Repository: https://github.com/samarthpardhi/munch-the-tabs-snapper

## Overview

##### Project type and purpose
- This is a single‐browser extension (“Munch the Tabs Killer”) whose sole function is to let users save the URL of the currently active tab and then close it via a keyboard shortcut.
- All logic runs client-side in the browser; there is no external server or database.

##### File structure
- background.js: the background service worker/page that listens for the keyboard command, saves URLs, and closes tabs via the browser API.

##### README for additional insights
- Confirms the keyboard shortcuts, key features (save+close tab, view saved URLs).
- No external services or backends are mentioned—everything is handled via browser.storage.local or sync.

##### Main components to surface
a. Browser Host
- Chrome/Edge/Brave or Firefox runtime that loads the extension.
b. Manifest Configuration
- Declares permissions (tabs, storage, commands) and links to background and popup.
c. Background Script (background.js)
- Listens for the `Alt+Shift+W` (or Mac equivalent) command.
- Invokes browser.tabs API to get current tab’s URL, writes into browser.storage.local, then closes the tab.
d. Storage Layer (browser.storage.local or sync)
- Persists the list of saved URLs.
e. Popup UI (popup.html + popup.js + popup.css)
- On open, reads saved URLs from storage and displays them.
- Allows simple management (e.g., remove a URL).
f. Browser APIs
- tabs API for querying and closing tabs.
- storage API for persisting data.
- commands API for keyboard shortcuts.

##### Relationships and interactions
- User presses keyboard shortcut → Commands API dispatches event to Background Script → Background Script calls Tabs API to fetch current tab URL → Background Script calls Storage API to append URL → Background Script calls Tabs API to close the tab.

##### Architectural patterns and design principles
- Event-driven architecture: background script reacts to keyboard commands and browser events.
- Separation of concerns: background.js handles logic/event processing; popup.js handles UI and read operations.

##### Final checklist
- All six components represented.
- A title: “Munch the Tabs Killer – Architecture Overview.”
- Footnote: “Data persists in browser.storage.local (or sync).”

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Title
    title["Munch the Tabs Killer – Architecture Overview"]

    %% Components
    subgraph "Browser Platform"
        direction TB
        Host["Browser Host"]:::browser
        subgraph "Browser APIs"
            direction TB
            CommandsAPI["Commands API"]:::browser
            TabsAPI["Tabs API"]:::browser
            StorageAPI["Storage API"]:::browser
        end
    end

    Manifest["manifest.json\n(Entrypoint Configuration)"]:::config
    click Manifest "https://github.com/samarthpardhi/munch-the-tabs-snapper/blob/main/manifest.json"

    Background["background.js\nEvent Listener & Tab Manager"]:::logic
    click Background "https://github.com/samarthpardhi/munch-the-tabs-snapper/blob/main/background.js"

    StorageLayer["browser.storage.local\n(Persistent Storage)"]:::data

    subgraph "Popup UI"
        direction TB
        PopupHTML["popup.html\n(User Interface)"]:::logic
        click PopupHTML "https://github.com/samarthpardhi/munch-the-tabs-snapper/blob/main/popup.html"
        PopupJS["popup.js\n(UI Logic)"]:::logic
        click PopupJS "https://github.com/samarthpardhi/munch-the-tabs-snapper/blob/main/popup.js"
        PopupCSS["popup.css\n(Styles)"]:::logic
        click PopupCSS "https://github.com/samarthpardhi/munch-the-tabs-snapper/blob/main/popup.css"
    end

    Icons["icons/"]:::assets
    click Icons "https://github.com/samarthpardhi/munch-the-tabs-snapper/tree/main/icons/"

    %% Interactions
    Manifest -->|"loads extension"| Host
    Host -->|"commands.onCommand"| CommandsAPI
    CommandsAPI -->|"onCommand event"| Background
    Background -->|"tabs.query(currentTab)"| TabsAPI
    Background -->|"storage.set(url)"| StorageAPI
    Background -->|"tabs.remove(tabId)"| TabsAPI

    Host -->|"popup.html on icon click"| PopupHTML
    PopupHTML -->|"loads script"| PopupJS
    PopupHTML -->|"loads styles"| PopupCSS
    PopupJS -->|"storage.get()"| StorageAPI
    PopupJS -->|"render URLs"| PopupHTML

    StorageAPI -->|"write/read"| StorageLayer
    StorageLayer -->|"data"| StorageAPI

    %% Assets
    Host -->|"uses icons"| Icons

    %% Legend
    classDef config fill:#d3d3d3,stroke:#333,stroke-width:1px;
    classDef logic fill:#add8e6,stroke:#333,stroke-width:1px;
    classDef browser fill:#555,stroke:#fff,stroke-width:1px,color:#fff;
    classDef data fill:#90ee90,stroke:#333,stroke-width:1px;
    classDef assets fill:#fffacd,stroke:#333,stroke-width:1px;

    %% Footnote
    footnote["Footnote: Data persists in browser.storage.local (or sync)."]
```
