# numan-ahmad-gohar/capsule-hub architecture

> Architecture diagram of the GitHub repository numan-ahmad-gohar/capsule-hub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/numan-ahmad-gohar/capsule-hub
- Repository: https://github.com/numan-ahmad-gohar/capsule-hub

## Overview

Capsule Hub is a privacy-oriented Chrome extension for capturing conversations from ChatGPT, Claude, or Gemini, distilling them into reusable Capsules, storing them locally, and injecting them into another assistant. The popup coordinates capture and library actions; platform-specific content scripts read and insert conversation text, while the background worker coordinates extension messaging and distillation. The README documents the end-to-end pipeline and supported platforms; source excerpts show key interfaces, but the worker and platform adapters were not excerpted, so some links rely on explicit README documentation.

Main entry points: [`src/content-scripts/common.js`](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/common.js) (Content runtime), [`src/popup/App.jsx`](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/App.jsx) (Popup app), [`src/background/service-worker.js`](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/background/service-worker.js) (Background worker), [`src/popup/components/CapsulePreview.jsx`](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/CapsulePreview.jsx) (Capsule preview)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_popup["Popup and library"]
  node_popup_app["Popup app<br/>[App.jsx]"]
  node_popup_api["Popup API<br/>[api.js]"]
  node_library_ui["Capsule library UI<br/>[CapsuleList.jsx]"]
  node_capsule_card["Capsule card<br/>[CapsuleCard.jsx]"]
  node_preview["Capsule preview<br/>[CapsulePreview.jsx]"]
  node_settings["Settings UI<br/>[Settings.jsx]"]
end

subgraph group_runtime["Extension runtime"]
  node_worker["Background worker<br/>[service-worker.js]"]
  node_messaging["Message protocol<br/>[messaging.js]"]
end

subgraph group_platform["AI platform scripts"]
  node_common["Content runtime<br/>[common.js]"]
  node_dom_utils["DOM helpers<br/>[dom-utils.js]"]
  node_chatgpt["ChatGPT adapter<br/>[chatgpt.js]"]
  node_claude["Claude adapter<br/>[claude.js]"]
  node_gemini["Gemini adapter<br/>[gemini.js]"]
end

subgraph group_capsule["Capsule services"]
  node_schema["Capsule schema<br/>[capsule-schema.js]"]
  node_storage[("Local capsule storage<br/>[storage.js]")]
  node_llm["Distillation client<br/>[llm-client.js]"]
  node_formatter["Platform formatter<br/>[format.js]"]
end

node_user(("Extension user"))
node_ai_site(("Supported AI assistant"))
node_distill_service["Distillation service"]

node_user -->|"opens"| node_popup_app
node_popup_app -->|"requests capture"| node_popup_api
node_popup_api -->|"messages"| node_worker
node_popup_app -->|"loads library"| node_storage
node_popup_app -->|"renders"| node_library_ui
node_library_ui -->|"renders"| node_capsule_card
node_popup_app -->|"shows selection"| node_preview
node_preview -->|"formats capsule"| node_formatter
node_preview -->|"requests injection"| node_popup_api
node_popup_app -->|"renders settings"| node_settings
node_settings -->|"reads settings"| node_storage
node_worker -->|"uses protocol"| node_messaging
node_worker -->|"requests scrape or injection"| node_common
node_common -->|"sends capture"| node_worker
node_common -.->|"uses DOM helpers"| node_dom_utils
node_common -.->|"builds capsule input"| node_schema
node_chatgpt -->|"supplies adapter"| node_common
node_claude -->|"supplies adapter"| node_common
node_gemini -->|"supplies adapter"| node_common
node_ai_site -->|"hosts script"| node_common
node_worker -->|"requests distillation"| node_llm
node_llm -->|"posts transcript"| node_distill_service
node_worker -->|"saves capsule"| node_storage
node_llm -->|"selects fields"| node_schema
node_storage -->|"normalizes capsules"| node_schema
node_preview -->|"injects into composer"| node_common

click node_popup_app "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/App.jsx"
click node_popup_api "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/api.js"
click node_library_ui "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/CapsuleList.jsx"
click node_capsule_card "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/CapsuleCard.jsx"
click node_preview "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/CapsulePreview.jsx"
click node_settings "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/Settings.jsx"
click node_worker "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/background/service-worker.js"
click node_messaging "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/messaging.js"
click node_common "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/common.js"
click node_dom_utils "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/dom-utils.js"
click node_chatgpt "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/chatgpt.js"
click node_claude "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/claude.js"
click node_gemini "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/gemini.js"
click node_schema "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/capsule-schema.js"
click node_storage "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/storage.js"
click node_llm "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/llm-client.js"
click node_formatter "https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/format.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_popup_app,node_popup_api,node_library_ui,node_capsule_card,node_preview,node_settings,node_user toneBlue
class node_worker,node_messaging toneAmber
class node_common,node_dom_utils,node_chatgpt,node_claude,node_gemini toneMint
class node_schema,node_storage,node_llm,node_formatter toneRose
class node_ai_site,node_distill_service toneIndigo
```

## Components

### Popup and library

- [Popup app](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/App.jsx): `src/popup/App.jsx`
- [Popup API](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/api.js): `src/popup/api.js`
- [Capsule library UI](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/CapsuleList.jsx): `src/popup/components/CapsuleList.jsx`
- [Capsule card](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/CapsuleCard.jsx): `src/popup/components/CapsuleCard.jsx`
- [Capsule preview](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/CapsulePreview.jsx): `src/popup/components/CapsulePreview.jsx`
- [Settings UI](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/popup/components/Settings.jsx): `src/popup/components/Settings.jsx`

### Extension runtime

- [Background worker](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/background/service-worker.js): `src/background/service-worker.js`
- [Message protocol](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/messaging.js): `src/lib/messaging.js`

### AI platform scripts

- [Content runtime](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/common.js): `src/content-scripts/common.js`
- [DOM helpers](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/dom-utils.js): `src/content-scripts/dom-utils.js`
- [ChatGPT adapter](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/chatgpt.js): `src/content-scripts/chatgpt.js`
- [Claude adapter](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/claude.js): `src/content-scripts/claude.js`
- [Gemini adapter](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/content-scripts/gemini.js): `src/content-scripts/gemini.js`

### Capsule services

- [Capsule schema](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/capsule-schema.js): `src/lib/capsule-schema.js`
- [Local capsule storage](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/storage.js): `src/lib/storage.js`
- [Distillation client](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/llm-client.js): `src/lib/llm-client.js`
- [Platform formatter](https://github.com/numan-ahmad-gohar/capsule-hub/blob/main/src/lib/format.js): `src/lib/format.js`

### Other components

- **Extension user**
- **Supported AI assistant**
- **Distillation service**

## Connections

- Extension user → Popup app: opens (evidence: `README.md`)
- Popup app → Popup API: requests capture (evidence: `src/popup/App.jsx`)
- Popup API → Background worker: messages (evidence: `src/popup/api.js`)
- Popup app → Local capsule storage: loads library (evidence: `src/popup/App.jsx`)
- Popup app → Capsule library UI: renders (evidence: `src/popup/App.jsx`)
- Capsule library UI → Capsule card: renders (evidence: `src/popup/components/CapsuleList.jsx`)
- Popup app → Capsule preview: shows selection (evidence: `src/popup/App.jsx`)
- Capsule preview → Platform formatter: formats capsule (evidence: `src/popup/components/CapsulePreview.jsx`)
- Capsule preview → Popup API: requests injection (evidence: `src/popup/components/CapsulePreview.jsx`)
- Popup app → Settings UI: renders settings (evidence: `src/popup/App.jsx`)
- Settings UI → Local capsule storage: reads settings (evidence: `src/popup/components/Settings.jsx`)
- Background worker → Message protocol: uses protocol (evidence: `src/background/service-worker.js`)
- Background worker → Content runtime: requests scrape or injection (evidence: `README.md`)
- Content runtime → Background worker: sends capture (evidence: `src/content-scripts/common.js`)
- Content runtime → DOM helpers: uses DOM helpers
- Content runtime → Capsule schema: builds capsule input
- ChatGPT adapter → Content runtime: supplies adapter (evidence: `src/content-scripts/common.js`)
- Claude adapter → Content runtime: supplies adapter (evidence: `src/content-scripts/common.js`)
- Gemini adapter → Content runtime: supplies adapter (evidence: `src/content-scripts/common.js`)
- Supported AI assistant → Content runtime: hosts script (evidence: `README.md`)
- Background worker → Distillation client: requests distillation (evidence: `README.md`)
- Distillation client → Distillation service: posts transcript (evidence: `src/lib/llm-client.js`)
- Background worker → Local capsule storage: saves capsule (evidence: `README.md`)
- Distillation client → Capsule schema: selects fields (evidence: `src/lib/llm-client.js`)
- Local capsule storage → Capsule schema: normalizes capsules (evidence: `src/lib/storage.js`)
- Capsule preview → Content runtime: injects into composer (evidence: `README.md`)
