# ashiqfury/pagepilot-summariser architecture

> Architecture diagram of the GitHub repository ashiqfury/pagepilot-summariser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashiqfury/pagepilot-summariser
- Repository: https://github.com/ashiqfury/pagepilot-summariser

## Overview

#### Purpose and Runtime

PagePilot Summariser is a Manifest-based Chrome extension that extracts readable text from the active webpage, sends it to a user-configured OpenAI-compatible chat-completions endpoint, and displays a bullet summary in the extension popup. Its browser integration and permissions boundary are defined in `manifest.json`.

#### Extension Entry Points

- Webpage-side extraction starts in `content.js`, injected into supported pages under manifest control.
- The user initiates work through the popup UI in `popup.html`; `popup.js` is the primary orchestration controller.
- Persistent provider configuration is managed by the options UI: `options.html` and `options.js`.
- Shared AI request and response-normalization logic resides in `summarizer.js`.

#### Page Content Extraction Boundary

`content.js` operates in the target page’s DOM context. It identifies likely readable containers (`article`, `main`, common content elements, then body fallback), strips whitespace and common subscription/noise patterns, and returns cleaned text through Chrome extension messaging.

This isolates untrusted, variable webpage structure from popup and provider logic. The content script should not own credentials, rendering, or remote API calls.

#### Popup Orchestration and Presentation

`popup.js` coordinates the end-to-end request after the user chooses to summarize:

1. Resolve the active tab and message `content.js` for extracted content.
2. Load endpoint, model, and API key from Chrome storage.
3. Pass content plus settings to the summarization layer.
4. Render normalized summary bullets and expose clipboard copy behavior.

`popup.html` provides the interaction surface, while `styles.css` is the shared presentation layer. The popup is the key control boundary between browser APIs, user state, and AI processing.

#### AI Provider Integration

`summarizer.js` builds the concise summarization prompt, invokes the configured OpenAI-compatible chat-completions API, handles provider failures/configuration mistakes, and converts returned model text into displayable bullets.

External requests are intentionally constrained by `manifest.json` host permissions, currently covering OpenRouter and OpenAI. Adding another compatible provider requires both a configurable endpoint and a corresponding host permission update.

#### Settings and Credential Flow

`options.js` persists the provider endpoint, model identifier, and API key through Chrome storage; `options.html` is the configuration entry point. The popup reads these values at summary time rather than embedding provider configuration in page scripts.

Credentials therefore remain extension-managed and are not passed into webpage DOM execution. The remote AI provider receives only the configured request metadata and extracted page text.

#### Primary Control Flow

User click in `popup.html` → `popup.js` queries active tab → message to `content.js` → cleaned text returned to popup → settings loaded from Chrome storage → `summarizer.js` calls OpenRouter/OpenAI-compatible endpoint → response transformed to bullets → popup renders and optionally copies output.

Failure points are page-script availability, empty/noisy extraction, missing settings, provider authentication/endpoint mismatch, network errors, and nonconforming provider responses.

Main entry points: [`popup.js`](https://github.com/ashiqfury/pagepilot-summariser/blob/main/popup.js) (Popup Controller), [`content.js`](https://github.com/ashiqfury/pagepilot-summariser/blob/main/content.js) (Content Extractor), [`summarizer.js`](https://github.com/ashiqfury/pagepilot-summariser/blob/main/summarizer.js) (Summarization Layer), [`manifest.json`](https://github.com/ashiqfury/pagepilot-summariser/blob/main/manifest.json) (Extension Manifest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Chrome Extension"]
  node_manifest["Extension Manifest<br/>[manifest.json]"]
  node_popup_html["Popup UI<br/>popup view<br/>[popup.html]"]
  node_popup_js["Popup Controller<br/>orchestrator<br/>[popup.js]"]
  node_content_js["Content Extractor<br/>content script<br/>[content.js]"]
  node_storage[("Chrome Storage<br/>extension storage")]
  node_options_html["Options UI<br/>settings view<br/>[options.html]"]
  node_options_js["Settings Controller<br/>options script<br/>[options.js]"]
  node_summarizer_js["Summarization Layer<br/>AI client<br/>[summarizer.js]"]
  node_styles["Shared Styles<br/>stylesheet<br/>[styles.css]"]
  node_summary_bullets["Normalized Bullets<br/>presentation data"]
end

subgraph group_provider["AI Provider"]
  node_provider_api{{"OpenAI-Compatible API<br/>external chat completions"}}
end

node_page_dom["Active Page DOM<br/>untrusted page"]

node_manifest -->|"injects on supported pages"| node_content_js
node_manifest -->|"host permissions"| node_provider_api
node_popup_html -->|"summarize action"| node_popup_js
node_styles -->|"styles"| node_popup_html
node_popup_js -->|"message active tab"| node_content_js
node_content_js -->|"reads readable content"| node_page_dom
node_content_js -->|"returns cleaned text"| node_popup_js
node_options_html -->|"settings submission"| node_options_js
node_options_js -->|"persists endpoint, model, key"| node_storage
node_popup_js -->|"loads settings"| node_storage
node_popup_js -->|"content and settings"| node_summarizer_js
node_summarizer_js -->|"chat-completions request"| node_provider_api
node_provider_api -->|"model response"| node_summarizer_js
node_summarizer_js -->|"normalizes response"| node_summary_bullets
node_summary_bullets -->|"render and copy"| node_popup_js

click node_manifest "https://github.com/ashiqfury/pagepilot-summariser/blob/main/manifest.json"
click node_popup_html "https://github.com/ashiqfury/pagepilot-summariser/blob/main/popup.html"
click node_popup_js "https://github.com/ashiqfury/pagepilot-summariser/blob/main/popup.js"
click node_content_js "https://github.com/ashiqfury/pagepilot-summariser/blob/main/content.js"
click node_options_html "https://github.com/ashiqfury/pagepilot-summariser/blob/main/options.html"
click node_options_js "https://github.com/ashiqfury/pagepilot-summariser/blob/main/options.js"
click node_summarizer_js "https://github.com/ashiqfury/pagepilot-summariser/blob/main/summarizer.js"
click node_styles "https://github.com/ashiqfury/pagepilot-summariser/blob/main/styles.css"

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_manifest,node_popup_html,node_popup_js,node_content_js,node_storage,node_options_html,node_options_js,node_summarizer_js,node_styles,node_summary_bullets toneBlue
class node_provider_api toneAmber
class node_page_dom toneNeutral
```

## Components

### Chrome Extension

Browser-managed UI, scripts, storage, and permission boundary.

- [Extension Manifest](https://github.com/ashiqfury/pagepilot-summariser/blob/main/manifest.json): manifest · Defines injection, permissions, and allowed provider hosts. · `manifest.json`
- [Popup UI](https://github.com/ashiqfury/pagepilot-summariser/blob/main/popup.html): popup view · User entry point and summary display. · `popup.html`
- [Popup Controller](https://github.com/ashiqfury/pagepilot-summariser/blob/main/popup.js): orchestrator · Coordinates tab messaging, settings, summarization, rendering, and copy. · `popup.js`
- [Content Extractor](https://github.com/ashiqfury/pagepilot-summariser/blob/main/content.js): content script · Extracts and cleans readable text in the target page DOM. · `content.js`
- **Chrome Storage**: extension storage · Persists endpoint, model, and API key.
- [Options UI](https://github.com/ashiqfury/pagepilot-summariser/blob/main/options.html): settings view · Provider configuration entry point. · `options.html`
- [Settings Controller](https://github.com/ashiqfury/pagepilot-summariser/blob/main/options.js): options script · Saves provider settings to extension storage. · `options.js`
- [Summarization Layer](https://github.com/ashiqfury/pagepilot-summariser/blob/main/summarizer.js): AI client · Builds prompts, calls chat completions, handles failures, and normalizes bullets. · `summarizer.js`
- [Shared Styles](https://github.com/ashiqfury/pagepilot-summariser/blob/main/styles.css): stylesheet · `styles.css`
- **Normalized Bullets**: presentation data · Displayable summary returned from the AI layer.

### AI Provider

- **OpenAI-Compatible API**: external chat completions · Configured OpenRouter or OpenAI endpoint.

### Other components

- **Active Page DOM**: untrusted page · Variable webpage content isolated from credentials and provider calls.

## Connections

- Extension Manifest → Content Extractor: injects on supported pages
- Extension Manifest → OpenAI-Compatible API: host permissions · Restricts permitted remote provider hosts.
- Popup UI → Popup Controller: summarize action
- Shared Styles → Popup UI: styles
- Popup Controller → Content Extractor: message active tab
- Content Extractor → Active Page DOM: reads readable content
- Content Extractor → Popup Controller: returns cleaned text
- Options UI → Settings Controller: settings submission
- Settings Controller → Chrome Storage: persists endpoint, model, key
- Popup Controller → Chrome Storage: loads settings
- Popup Controller → Summarization Layer: content and settings
- Summarization Layer → OpenAI-Compatible API: chat-completions request · Sends extracted text and configured request metadata.
- OpenAI-Compatible API → Summarization Layer: model response
- Summarization Layer → Normalized Bullets: normalizes response
- Normalized Bullets → Popup Controller: render and copy
