# gildas-lormeau/singlefile architecture

> Architecture diagram of the GitHub repository gildas-lormeau/singlefile, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gildas-lormeau/singlefile
- Repository: https://github.com/gildas-lormeau/singlefile

## Overview

SingleFile is a browser extension (with a separately documented CLI) that captures a web page as a self-contained HTML archive. The central flow runs from a toolbar, menu, or shortcut request through background task orchestration, page/frame capture, then foreground or background saving and optional upload. Other documented workflows include batch and automatic saves, selection/frame capture, page annotation, configurable profiles, and archive editing. The graph combines excerpted dispatch and calls with README-described capabilities; links for unsampled subsystems are shown only when documented, and some are left unconnected where wiring is not evidenced.

Main entry points: [`src/core/bg/index.js`](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/index.js) (Background router), [`src/core/bg/downloads.js`](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/downloads.js) (Save orchestration), [`src/core/content/content.js`](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/content/content.js) (Page capture), [`src/ui/bg`](https://github.com/gildas-lormeau/singlefile/tree/master/src/ui/bg) (Toolbar and menus)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Extension interaction"]
  node_background_router["Background router<br/>[index.js]"]
  node_toolbar_menus["Toolbar and menus"]
  node_content_ui["Capture UI<br/>[content-ui.js]"]
end

subgraph group_capture["Capture and processing"]
  node_task_manager["Capture tasks<br/>[business.js]"]
  node_content_capture["Page capture<br/>[content.js]"]
  node_frame_capture["Frame capture<br/>[content-frames.js]"]
  node_page_fetch["Resource fetching<br/>[content-fetch.js]"]
  node_singlefile_engine["Archive generation"]
  node_page_data_api["Capture API<br/>[index.js]"]
end

subgraph group_save["Save and export"]
  node_background_save["Save orchestration<br/>[downloads.js]"]
  node_foreground_save["Foreground download<br/>[download.js]"]
  node_download_util["Browser download<br/>[download-util.js]"]
  node_serialization["Chunk serialization<br/>[yabson.js]"]
  node_cloud_destinations["Cloud destinations"]
  node_proof_service["Proof of existence<br/>[woleet.js]"]
end

subgraph group_configuration["Configuration and automation"]
  node_config["Profiles and options<br/>[config.js]"]
  node_autosave["Automatic saves<br/>[autosave.js]"]
  node_batch_save["Batch save"]
  node_tabs["Tab management<br/>[tabs.js]"]
end

subgraph group_editor["Archive editing"]
  node_editor["Archive editor"]
  node_editor_background["Editor coordination<br/>[editor.js]"]
  node_mhtml_converter["MHTML conversion<br/>[convert.js]"]
end

node_user(("User"))
node_external_services["Browser and cloud services"]

node_user -->|"requests capture"| node_toolbar_menus
node_toolbar_menus -->|"sends messages"| node_background_router
node_background_router -->|"dispatches tasks"| node_task_manager
node_task_manager -->|"injects scripts"| node_page_data_api
node_page_data_api -->|"uses fetch"| node_page_fetch
node_content_capture -.->|"fetches resources"| node_page_fetch
node_content_capture -.->|"captures frames"| node_frame_capture
node_content_capture -.->|"updates progress"| node_content_ui
node_task_manager -.->|"requests capture"| node_content_capture
node_content_capture -.->|"sends archive"| node_background_save
node_background_save -->|"serializes chunks"| node_serialization
node_foreground_save -->|"sends save data"| node_background_router
node_background_router -->|"routes downloads"| node_background_save
node_background_save -->|"downloads files"| node_download_util
node_background_save -->|"uploads archives"| node_cloud_destinations
node_background_save -->|"adds proof"| node_proof_service
node_background_save -.->|"uses browser storage"| node_external_services
node_toolbar_menus -.->|"configures autosave"| node_autosave
node_toolbar_menus -.->|"starts batch save"| node_batch_save
node_background_router -->|"routes settings"| node_config
node_background_router -->|"routes autosave"| node_autosave
node_background_router -->|"routes tab messages"| node_tabs
node_user -->|"annotates archive"| node_editor
node_editor -->|"downloads edited page"| node_foreground_save
node_editor -->|"converts MHTML"| node_mhtml_converter
node_editor -.->|"coordinates editor"| node_editor_background

click node_background_router "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/index.js"
click node_toolbar_menus "https://github.com/gildas-lormeau/singlefile/tree/master/src/ui/bg"
click node_content_ui "https://github.com/gildas-lormeau/singlefile/blob/master/src/ui/content/content-ui.js"
click node_task_manager "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/business.js"
click node_content_capture "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/content/content.js"
click node_frame_capture "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/content/content-frames.js"
click node_page_fetch "https://github.com/gildas-lormeau/singlefile/blob/master/src/lib/single-file/fetch/content/content-fetch.js"
click node_singlefile_engine "https://github.com/gildas-lormeau/singlefile/blob/master/lib/single-file-archive.js"
click node_page_data_api "https://github.com/gildas-lormeau/singlefile/blob/master/src/index.js"
click node_background_save "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/downloads.js"
click node_foreground_save "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/common/download.js"
click node_download_util "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/download-util.js"
click node_serialization "https://github.com/gildas-lormeau/singlefile/blob/master/src/lib/yabson/yabson.js"
click node_cloud_destinations "https://github.com/gildas-lormeau/singlefile/tree/master/src/lib"
click node_proof_service "https://github.com/gildas-lormeau/singlefile/blob/master/src/lib/woleet/woleet.js"
click node_config "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/config.js"
click node_autosave "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/autosave.js"
click node_batch_save "https://github.com/gildas-lormeau/singlefile/blob/master/src/ui/bg/ui-batch-save-urls.js"
click node_tabs "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/tabs.js"
click node_editor "https://github.com/gildas-lormeau/singlefile/blob/master/src/ui/content/content-ui-editor-web.js"
click node_editor_background "https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/editor.js"
click node_mhtml_converter "https://github.com/gildas-lormeau/singlefile/blob/master/src/lib/mhtml-to-html/convert.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_background_router,node_toolbar_menus,node_content_ui,node_user,node_external_services toneBlue
class node_task_manager,node_content_capture,node_frame_capture,node_page_fetch,node_singlefile_engine,node_page_data_api toneAmber
class node_background_save,node_foreground_save,node_download_util,node_serialization,node_cloud_destinations,node_proof_service toneMint
class node_config,node_autosave,node_batch_save,node_tabs toneRose
class node_editor,node_editor_background,node_mhtml_converter toneIndigo
```

## Components

### Extension interaction

- [Background router](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/index.js): `src/core/bg/index.js`
- [Toolbar and menus](https://github.com/gildas-lormeau/singlefile/tree/master/src/ui/bg): `src/ui/bg`
- [Capture UI](https://github.com/gildas-lormeau/singlefile/blob/master/src/ui/content/content-ui.js): `src/ui/content/content-ui.js`

### Capture and processing

- [Capture tasks](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/business.js): `src/core/bg/business.js`
- [Page capture](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/content/content.js): `src/core/content/content.js`
- [Frame capture](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/content/content-frames.js): `src/core/content/content-frames.js`
- [Resource fetching](https://github.com/gildas-lormeau/singlefile/blob/master/src/lib/single-file/fetch/content/content-fetch.js): `src/lib/single-file/fetch/content/content-fetch.js`
- [Archive generation](https://github.com/gildas-lormeau/singlefile/blob/master/lib/single-file-archive.js): `lib/single-file-archive.js`
- [Capture API](https://github.com/gildas-lormeau/singlefile/blob/master/src/index.js): `src/index.js`

### Save and export

- [Save orchestration](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/downloads.js): `src/core/bg/downloads.js`
- [Foreground download](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/common/download.js): `src/core/common/download.js`
- [Browser download](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/download-util.js): `src/core/bg/download-util.js`
- [Chunk serialization](https://github.com/gildas-lormeau/singlefile/blob/master/src/lib/yabson/yabson.js): `src/lib/yabson/yabson.js`
- [Cloud destinations](https://github.com/gildas-lormeau/singlefile/tree/master/src/lib): `src/lib`
- [Proof of existence](https://github.com/gildas-lormeau/singlefile/blob/master/src/lib/woleet/woleet.js): `src/lib/woleet/woleet.js`

### Configuration and automation

- [Profiles and options](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/config.js): `src/core/bg/config.js`
- [Automatic saves](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/autosave.js): `src/core/bg/autosave.js`
- [Batch save](https://github.com/gildas-lormeau/singlefile/blob/master/src/ui/bg/ui-batch-save-urls.js): `src/ui/bg/ui-batch-save-urls.js`
- [Tab management](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/tabs.js): `src/core/bg/tabs.js`

### Archive editing

- [Archive editor](https://github.com/gildas-lormeau/singlefile/blob/master/src/ui/content/content-ui-editor-web.js): `src/ui/content/content-ui-editor-web.js`
- [Editor coordination](https://github.com/gildas-lormeau/singlefile/blob/master/src/core/bg/editor.js): `src/core/bg/editor.js`
- [MHTML conversion](https://github.com/gildas-lormeau/singlefile/blob/master/src/lib/mhtml-to-html/convert.js): `src/lib/mhtml-to-html/convert.js`

### Other components

- **User**
- **Browser and cloud services**

## Connections

- User → Toolbar and menus: requests capture
- Toolbar and menus → Background router: sends messages (evidence: `src/core/bg/index.js`)
- Background router → Capture tasks: dispatches tasks (evidence: `src/core/bg/index.js`)
- Capture tasks → Capture API: injects scripts (evidence: `src/core/bg/business.js`)
- Capture API → Resource fetching: uses fetch (evidence: `src/index.js`)
- Page capture → Resource fetching: fetches resources (evidence: `src/core/content/content.js`)
- Page capture → Frame capture: captures frames
- Page capture → Capture UI: updates progress (evidence: `src/core/content/content.js`)
- Capture tasks → Page capture: requests capture
- Page capture → Save orchestration: sends archive
- Save orchestration → Chunk serialization: serializes chunks (evidence: `src/core/bg/downloads.js`)
- Foreground download → Background router: sends save data (evidence: `src/core/common/download.js`)
- Background router → Save orchestration: routes downloads (evidence: `src/core/bg/index.js`)
- Save orchestration → Browser download: downloads files (evidence: `src/core/bg/downloads.js`)
- Save orchestration → Cloud destinations: uploads archives (evidence: `src/core/bg/downloads.js`)
- Save orchestration → Proof of existence: adds proof (evidence: `src/core/bg/downloads.js`)
- Save orchestration → Browser and cloud services: uses browser storage
- Toolbar and menus → Automatic saves: configures autosave (evidence: `src/core/bg/autosave.js`)
- Toolbar and menus → Batch save: starts batch save
- Background router → Profiles and options: routes settings (evidence: `src/core/bg/index.js`)
- Background router → Automatic saves: routes autosave (evidence: `src/core/bg/index.js`)
- Background router → Tab management: routes tab messages (evidence: `src/core/bg/index.js`)
- User → Archive editor: annotates archive
- Archive editor → Foreground download: downloads edited page (evidence: `src/ui/content/content-ui-editor-web.js`)
- Archive editor → MHTML conversion: converts MHTML (evidence: `src/ui/content/content-ui-editor-web.js`)
- Archive editor → Editor coordination: coordinates editor
