# timf34/pagesource architecture

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

- Interactive diagram: https://gitdiagram.com/timf34/pagesource
- Repository: https://github.com/timf34/pagesource

## Overview

pagesource is a command-line webpage resource capture tool. A user supplies a URL and options; the CLI validates the URL, asks a headless browser to load the page and collect successful network responses, then saves eligible resources under host and URL-path directories. The saver handles external-resource filtering, inferred extensions, path safety, and duplicate names. The README documents these capabilities; the sampled source shows the main call flow, while browser internals are represented at the component level.

Main entry points: [`src/pagesource/cli.py`](https://github.com/timf34/pagesource/blob/main/src/pagesource/cli.py) (CLI command), [`src/pagesource/browser.py`](https://github.com/timf34/pagesource/blob/main/src/pagesource/browser.py) (Browser capture), [`src/pagesource/downloader.py`](https://github.com/timf34/pagesource/blob/main/src/pagesource/downloader.py) (Resource saver), [`src/pagesource/utils.py`](https://github.com/timf34/pagesource/blob/main/src/pagesource/utils.py) (URL validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_command["Command orchestration"]
  node_cli["CLI command<br/>[cli.py]"]
  node_url["URL validation<br/>[utils.py]"]
end

subgraph group_capture["Page capture"]
  node_browser["Browser capture<br/>[browser.py]"]
  node_resource["Captured resources<br/>[browser.py]"]
end

subgraph group_save["Resource output"]
  node_saver["Resource saver<br/>[downloader.py]"]
  node_path["Path and MIME utilities<br/>[utils.py]"]
end

node_user(("CLI user"))
node_page(("Target webpage"))
node_output["Saved resource files"]

node_user -->|"provides URL"| node_cli
node_cli -->|"validates with"| node_url
node_cli -->|"requests capture"| node_browser
node_browser -->|"loads page"| node_page
node_page -->|"serves responses"| node_browser
node_browser -->|"collects bodies"| node_resource
node_cli -->|"saves resources"| node_saver
node_saver -->|"derives paths"| node_path
node_saver -->|"writes files"| node_output

click node_cli "https://github.com/timf34/pagesource/blob/main/src/pagesource/cli.py"
click node_url "https://github.com/timf34/pagesource/blob/main/src/pagesource/utils.py"
click node_browser "https://github.com/timf34/pagesource/blob/main/src/pagesource/browser.py"
click node_resource "https://github.com/timf34/pagesource/blob/main/src/pagesource/browser.py"
click node_saver "https://github.com/timf34/pagesource/blob/main/src/pagesource/downloader.py"
click node_path "https://github.com/timf34/pagesource/blob/main/src/pagesource/utils.py"

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_cli,node_url,node_user toneBlue
class node_browser,node_resource toneAmber
class node_saver,node_path toneMint
class node_page,node_output toneIndigo
```

## Components

### Command orchestration

- [CLI command](https://github.com/timf34/pagesource/blob/main/src/pagesource/cli.py): `src/pagesource/cli.py`
- [URL validation](https://github.com/timf34/pagesource/blob/main/src/pagesource/utils.py): `src/pagesource/utils.py`

### Page capture

- [Browser capture](https://github.com/timf34/pagesource/blob/main/src/pagesource/browser.py): `src/pagesource/browser.py`
- [Captured resources](https://github.com/timf34/pagesource/blob/main/src/pagesource/browser.py): `src/pagesource/browser.py`

### Resource output

- [Resource saver](https://github.com/timf34/pagesource/blob/main/src/pagesource/downloader.py): `src/pagesource/downloader.py`
- [Path and MIME utilities](https://github.com/timf34/pagesource/blob/main/src/pagesource/utils.py): `src/pagesource/utils.py`

### Other components

- **CLI user**
- **Target webpage**
- **Saved resource files**

## Connections

- CLI user → CLI command: provides URL (evidence: `README.md`)
- CLI command → URL validation: validates with (evidence: `src/pagesource/cli.py`)
- CLI command → Browser capture: requests capture (evidence: `src/pagesource/cli.py`)
- Browser capture → Target webpage: loads page (evidence: `README.md`)
- Target webpage → Browser capture: serves responses (evidence: `README.md`)
- Browser capture → Captured resources: collects bodies (evidence: `src/pagesource/browser.py`)
- CLI command → Resource saver: saves resources (evidence: `src/pagesource/cli.py`)
- Resource saver → Path and MIME utilities: derives paths (evidence: `src/pagesource/downloader.py`)
- Resource saver → Saved resource files: writes files (evidence: `src/pagesource/downloader.py`)
