# imshoaibarshad/web-scraper architecture

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

- Interactive diagram: https://gitdiagram.com/imshoaibarshad/web-scraper
- Repository: https://github.com/imshoaibarshad/web-scraper

## Overview

This is a command-line scraper for books.toscrape.com. The user configures a crawl; the CLI invokes the crawl driver, which fetches listing pages, parses book records, follows pagination, and optionally fetches and parses product details. The CLI then selects CSV or JSON output and reports crawl statistics. The README documents the main capabilities; the shown source confirms the runtime calls and parsing stages. The map omits tests and build machinery.

Main entry points: [`src/scraper.py`](https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.py) (Crawl driver), [`run.py`](https://github.com/imshoaibarshad/web-scraper/blob/master/run.py) (CLI), [`src/http.py`](https://github.com/imshoaibarshad/web-scraper/blob/master/src/http.py) (HTTP fetch), [`src/parse.py`](https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py) (Listing parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_crawl["Crawl and parsing"]
  node_driver["Crawl driver<br/>[scraper.py]"]
  node_fetch["HTTP fetch<br/>[http.py]"]
  node_listing["Listing parser<br/>[parse.py]"]
  node_pagination["Pagination parser<br/>[parse.py]"]
  node_enrich["Detail enrichment<br/>[scraper.py]"]
  node_detail["Product detail parser<br/>[parse.py]"]
  node_records["Book records<br/>[parse.py]"]
end

subgraph group_cli["Command-line orchestration"]
  node_command["CLI<br/>[run.py]"]
end

subgraph group_output["Output"]
  node_csv["CSV writer<br/>[scraper.py]"]
  node_json["JSON writer<br/>[scraper.py]"]
end

node_user(("User"))
node_website["Book website"]
node_files["Output files"]

node_user -->|"configures"| node_command
node_command -->|"starts crawl"| node_driver
node_driver -->|"fetches pages"| node_fetch
node_fetch -->|"requests pages"| node_website
node_driver -->|"parses listings"| node_listing
node_driver -->|"finds next page"| node_pagination
node_listing -->|"creates records"| node_records
node_driver -->|"optionally enriches"| node_enrich
node_enrich -->|"fetches products"| node_fetch
node_enrich -->|"parses details"| node_detail
node_detail -.->|"supplies fields"| node_records
node_command -->|"selects CSV"| node_csv
node_command -->|"selects JSON"| node_json
node_csv -->|"writes CSV"| node_files
node_json -->|"writes JSON"| node_files

click node_command "https://github.com/imshoaibarshad/web-scraper/blob/master/run.py"
click node_driver "https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.py"
click node_fetch "https://github.com/imshoaibarshad/web-scraper/blob/master/src/http.py"
click node_listing "https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py"
click node_pagination "https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py"
click node_enrich "https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.py"
click node_detail "https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py"
click node_records "https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py"
click node_csv "https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.py"
click node_json "https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.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_driver,node_fetch,node_listing,node_pagination,node_enrich,node_detail,node_records,node_user toneBlue
class node_command toneAmber
class node_csv,node_json toneMint
class node_website,node_files toneIndigo
```

## Components

### Crawl and parsing

- [Crawl driver](https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.py): `src/scraper.py`
- [HTTP fetch](https://github.com/imshoaibarshad/web-scraper/blob/master/src/http.py): `src/http.py`
- [Listing parser](https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py): `src/parse.py`
- [Pagination parser](https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py): `src/parse.py`
- [Detail enrichment](https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.py): `src/scraper.py`
- [Product detail parser](https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py): `src/parse.py`
- [Book records](https://github.com/imshoaibarshad/web-scraper/blob/master/src/parse.py): `src/parse.py`

### Command-line orchestration

- [CLI](https://github.com/imshoaibarshad/web-scraper/blob/master/run.py): `run.py`

### Output

- [CSV writer](https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.py): `src/scraper.py`
- [JSON writer](https://github.com/imshoaibarshad/web-scraper/blob/master/src/scraper.py): `src/scraper.py`

### Other components

- **User**
- **Book website**
- **Output files**

## Connections

- User → CLI: configures (evidence: `run.py`)
- CLI → Crawl driver: starts crawl (evidence: `run.py`)
- Crawl driver → HTTP fetch: fetches pages (evidence: `src/scraper.py`)
- HTTP fetch → Book website: requests pages (evidence: `README.md`)
- Crawl driver → Listing parser: parses listings (evidence: `src/scraper.py`)
- Crawl driver → Pagination parser: finds next page (evidence: `src/scraper.py`)
- Listing parser → Book records: creates records (evidence: `src/parse.py`)
- Crawl driver → Detail enrichment: optionally enriches (evidence: `src/scraper.py`)
- Detail enrichment → HTTP fetch: fetches products (evidence: `src/scraper.py`)
- Detail enrichment → Product detail parser: parses details (evidence: `src/scraper.py`)
- Product detail parser → Book records: supplies fields (evidence: `src/parse.py`)
- CLI → CSV writer: selects CSV (evidence: `run.py`)
- CLI → JSON writer: selects JSON (evidence: `run.py`)
- CSV writer → Output files: writes CSV (evidence: `src/scraper.py`)
- JSON writer → Output files: writes JSON (evidence: `src/scraper.py`)
