# 0xmassi/webclaw architecture

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

- Interactive diagram: https://gitdiagram.com/0xmassi/webclaw
- Repository: https://github.com/0xmassi/webclaw

## Overview

#### Purpose and workspace
Webclaw is a Rust workspace that converts web URLs into clean Markdown, text, JSON, HTML, and LLM-ready context. It supports local-first scraping/crawling plus hosted fallbacks for protected or JavaScript-rendered sites. Workspace composition and shared dependency boundaries are defined in `Cargo.toml`; deployment is container-ready via `Dockerfile` and `docker-compose.yml`.

#### Entry points and delivery surfaces
Three Rust binaries expose the same underlying capabilities:
- CLI for one-shot scraping, crawling, mapping, batch work, branding, diffing, and LLM operations: `crates/webclaw-cli/src/main.rs`, `crates/webclaw-cli/src/bench.rs`.
- REST server with versioned operational routes: `crates/webclaw-server/src/main.rs`, `crates/webclaw-server/src/routes/mod.rs`.
- MCP stdio/server integration for agent clients: `crates/webclaw-mcp/src/main.rs`, `crates/webclaw-mcp/src/server.rs`, `crates/webclaw-mcp/src/tools.rs`.
A Node-based bootstrapper configures MCP clients: `packages/create-webclaw/index.mjs`.

#### Fetch, access, and crawl layer
`webclaw-fetch` owns network I/O and is the boundary between untrusted URLs/the web and pure extraction. Its fetch pipeline selects HTTP clients, browser/cloud paths, proxy/TLS behavior, and returns documents for downstream processing: `crates/webclaw-fetch/src/fetcher.rs`, `crates/webclaw-fetch/src/client.rs`, `crates/webclaw-fetch/src/document.rs`.
Crawling follows discovered links under crawl policy; mapping discovers URLs without full extraction. URL-security logic is a material SSRF/trust boundary: `crates/webclaw-fetch/src/crawler.rs`, `crates/webclaw-fetch/src/map.rs`, `crates/webclaw-fetch/src/url_security.rs`.

#### Extraction and normalized content
`webclaw-core` is the network-independent transformation engine. It parses and filters HTML, identifies main content/noise, extracts metadata and structured data, and emits normalized output types. Core orchestration and public API reside in `crates/webclaw-core/src/lib.rs`, `crates/webclaw-core/src/extractor.rs`, `crates/webclaw-core/src/types.rs`.
Format production and enrichment are separated into Markdown/LLM output, metadata, links/images, and structured-data stages: `crates/webclaw-core/src/markdown.rs`, `crates/webclaw-core/src/llm/mod.rs`, `crates/webclaw-core/src/structured_data.rs`. Specialized page handling exists for Reddit and YouTube: `crates/webclaw-core/src/reddit.rs`, `crates/webclaw-core/src/youtube.rs`.

#### Site-specific and document paths
The fetch crate dispatches domain/content-specific extractors before or alongside generic extraction, covering commerce, GitHub, social, package registries, and publication sites: `crates/webclaw-fetch/src/extractors/mod.rs`, `crates/webclaw-fetch/src/extractors/ecommerce_product.rs`, `crates/webclaw-fetch/src/extractors/github_repo.rs`.
PDF extraction is isolated behind a dedicated crate, preserving a document-type boundary: `crates/webclaw-pdf/src/lib.rs`, `crates/webclaw-pdf/src/error.rs`.

#### LLM-backed transformations
`webclaw-llm` implements structured extraction, cleaning, summarization, and chained LLM workflows over fetched/core-normalized content: `crates/webclaw-llm/src/lib.rs`, `crates/webclaw-llm/src/chain.rs`, `crates/webclaw-llm/src/extract.rs`.
Provider adapters isolate external model APIs and local runtime integration: `crates/webclaw-llm/src/provider.rs`, `crates/webclaw-llm/src/providers/openai.rs`, `crates/webclaw-llm/src/providers/ollama.rs`. Supported external services include OpenAI-compatible endpoints, Anthropic, Gemini, and Ollama.

#### Server control plane and infrastructure
The self-hosted server maps HTTP requests to scrape/crawl/map/batch/LLM/brand/diff operations, with shared application state and authentication boundaries: `crates/webclaw-server/src/routes/scrape.rs`, `crates/webclaw-server/src/routes/crawl.rs`, `crates/webclaw-server/src/state.rs`, `crates/webclaw-server/src/auth.rs`.
Hosted Webclaw is an optional external service, selected with API credentials for cloud rendering, protected-site access, search, research, and asynchronous workflows. Proxy infrastructure is configurable as a single endpoint or pool and integrated in `crates/webclaw-fetch/src/proxy.rs`; browser/cloud retrieval paths are in `crates/webclaw-fetch/src/browser.rs` and `crates/webclaw-fetch/src/cloud.rs`.

Main entry points: [`crates/webclaw-fetch/src/fetcher.rs`](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/fetcher.rs) (Fetch pipeline), [`crates/webclaw-llm/src/chain.rs`](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-llm/src/chain.rs) (LLM workflows), [`crates/webclaw-server/src/routes/mod.rs`](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-server/src/routes/mod.rs) (Operational routes), [`crates/webclaw-mcp/src/server.rs`](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-mcp/src/server.rs) (MCP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entrypoints["Delivery surfaces"]
  node_cli["CLI<br/>Rust binary<br/>[main.rs]"]
  node_rest_server["REST server<br/>Rust binary<br/>[main.rs]"]
  node_mcp_server["MCP server<br/>Rust binary<br/>[server.rs]"]
  node_mcp_bootstrapper["MCP bootstrapper<br/>Node package<br/>[index.mjs]"]
  node_server_routes["Operational routes<br/>HTTP routes<br/>[mod.rs]"]
  node_server_auth_state["Auth and app state<br/>control plane<br/>[auth.rs]"]
end

subgraph group_processing["Content pipeline"]
  node_fetch_pipeline{{"Fetch pipeline<br/>Rust crate<br/>[fetcher.rs]"}}
  node_crawl_map["Crawl and map<br/>discovery<br/>[crawler.rs]"]
  node_url_security{{"URL security<br/>SSRF boundary<br/>[url_security.rs]"}}
  node_site_extractors["Site extractors<br/>specialized extraction<br/>[mod.rs]"]
  node_core_extraction{{"Core extraction<br/>Rust crate<br/>[extractor.rs]"}}
  node_content_formats["Content formats<br/>output stage<br/>[markdown.rs]"]
  node_pdf_extraction["PDF extraction<br/>Rust crate<br/>[lib.rs]"]
  node_llm_workflows{{"LLM workflows<br/>Rust crate<br/>[chain.rs]"}}
end

subgraph group_integrations["External access"]
  node_llm_providers["Model providers<br/>provider adapters<br/>[provider.rs]"]
  node_web(("Target websites<br/>untrusted web"))
  node_hosted_access["Hosted access<br/>external service<br/>[cloud.rs]"]
  node_proxy_browser["Proxy and browser<br/>retrieval adapters<br/>[browser.rs]"]
  node_model_apis(("Model APIs<br/>external models"))
end

node_mcp_bootstrapper -->|"configures clients for"| node_mcp_server
node_cli -->|"invokes"| node_fetch_pipeline
node_cli -->|"invokes"| node_llm_workflows
node_rest_server -->|"serves"| node_server_routes
node_server_routes -->|"uses"| node_server_auth_state
node_server_routes -->|"dispatches"| node_fetch_pipeline
node_server_routes -->|"dispatches"| node_llm_workflows
node_mcp_server -->|"invokes"| node_fetch_pipeline
node_mcp_server -->|"invokes"| node_llm_workflows
node_crawl_map -->|"validates discovered URLs"| node_url_security
node_crawl_map -->|"fetches permitted URLs"| node_fetch_pipeline
node_fetch_pipeline -->|"checks targets"| node_url_security
node_fetch_pipeline -->|"retrieves"| node_web
node_fetch_pipeline -->|"selects"| node_proxy_browser
node_fetch_pipeline -.->|"falls back to"| node_hosted_access
node_fetch_pipeline -->|"dispatches specialized content"| node_site_extractors
node_fetch_pipeline -->|"passes documents to"| node_core_extraction
node_fetch_pipeline -->|"routes PDFs to"| node_pdf_extraction
node_site_extractors -->|"enriches generic extraction"| node_core_extraction
node_core_extraction -->|"normalizes into"| node_content_formats
node_content_formats -->|"supplies context to"| node_llm_workflows
node_llm_workflows -->|"uses"| node_llm_providers
node_llm_providers -->|"calls"| node_model_apis

click node_cli "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-cli/src/main.rs"
click node_rest_server "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-server/src/main.rs"
click node_mcp_server "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-mcp/src/server.rs"
click node_mcp_bootstrapper "https://github.com/0xmassi/webclaw/blob/main/packages/create-webclaw/index.mjs"
click node_server_routes "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-server/src/routes/mod.rs"
click node_server_auth_state "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-server/src/auth.rs"
click node_fetch_pipeline "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/fetcher.rs"
click node_crawl_map "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/crawler.rs"
click node_url_security "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/url_security.rs"
click node_site_extractors "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/extractors/mod.rs"
click node_core_extraction "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-core/src/extractor.rs"
click node_content_formats "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-core/src/markdown.rs"
click node_pdf_extraction "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-pdf/src/lib.rs"
click node_llm_workflows "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-llm/src/chain.rs"
click node_llm_providers "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-llm/src/provider.rs"
click node_hosted_access "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/cloud.rs"
click node_proxy_browser "https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/browser.rs"

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_rest_server,node_mcp_server,node_mcp_bootstrapper,node_server_routes,node_server_auth_state toneBlue
class node_fetch_pipeline,node_crawl_map,node_url_security,node_site_extractors,node_core_extraction,node_content_formats,node_pdf_extraction,node_llm_workflows toneAmber
class node_llm_providers,node_web,node_hosted_access,node_proxy_browser,node_model_apis toneMint
```

## Components

### Delivery surfaces

- [CLI](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-cli/src/main.rs): Rust binary · One-shot and batch content operations. · `crates/webclaw-cli/src/main.rs`
- [REST server](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-server/src/main.rs): Rust binary · Versioned self-hosted operational API. · `crates/webclaw-server/src/main.rs`
- [MCP server](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-mcp/src/server.rs): Rust binary · Stdio integration for agent clients. · `crates/webclaw-mcp/src/server.rs`
- [MCP bootstrapper](https://github.com/0xmassi/webclaw/blob/main/packages/create-webclaw/index.mjs): Node package · Configures MCP clients. · `packages/create-webclaw/index.mjs`
- [Operational routes](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-server/src/routes/mod.rs): HTTP routes · Scrape, crawl, map, batch, LLM, brand, and diff endpoints. · `crates/webclaw-server/src/routes/mod.rs`
- [Auth and app state](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-server/src/auth.rs): control plane · Shared state and authentication boundary. · `crates/webclaw-server/src/auth.rs`

### Content pipeline

- [Fetch pipeline](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/fetcher.rs): Rust crate · Network boundary that selects retrieval paths and returns documents. · `crates/webclaw-fetch/src/fetcher.rs`
- [Crawl and map](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/crawler.rs): discovery · Follows permitted links or discovers URLs without full extraction. · `crates/webclaw-fetch/src/crawler.rs`
- [URL security](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/url_security.rs): SSRF boundary · Validates URL trust before network access. · `crates/webclaw-fetch/src/url_security.rs`
- [Site extractors](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/extractors/mod.rs): specialized extraction · Domain-specific handlers run beside generic extraction. · `crates/webclaw-fetch/src/extractors/mod.rs`
- [Core extraction](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-core/src/extractor.rs): Rust crate · Network-independent HTML parsing, filtering, and normalization. · `crates/webclaw-core/src/extractor.rs`
- [Content formats](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-core/src/markdown.rs): output stage · Produces Markdown, LLM context, metadata, links, and structured data. · `crates/webclaw-core/src/markdown.rs`
- [PDF extraction](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-pdf/src/lib.rs): Rust crate · Dedicated document-type extraction boundary. · `crates/webclaw-pdf/src/lib.rs`
- [LLM workflows](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-llm/src/chain.rs): Rust crate · Structured extraction, cleaning, summaries, and chains. · `crates/webclaw-llm/src/chain.rs`

### External access

- [Model providers](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-llm/src/provider.rs): provider adapters · Adapters for hosted APIs and local Ollama. · `crates/webclaw-llm/src/provider.rs`
- **Target websites**: untrusted web
- [Hosted access](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/cloud.rs): external service · Optional rendering, protected-site, search, and async fallback. · `crates/webclaw-fetch/src/cloud.rs`
- [Proxy and browser](https://github.com/0xmassi/webclaw/blob/main/crates/webclaw-fetch/src/browser.rs): retrieval adapters · Configurable proxy and browser-based retrieval. · `crates/webclaw-fetch/src/browser.rs`
- **Model APIs**: external models · OpenAI-compatible, Anthropic, Gemini, and Ollama endpoints.

## Connections

- MCP bootstrapper → MCP server: configures clients for
- CLI → Fetch pipeline: invokes
- CLI → LLM workflows: invokes
- REST server → Operational routes: serves
- Operational routes → Auth and app state: uses
- Operational routes → Fetch pipeline: dispatches
- Operational routes → LLM workflows: dispatches
- MCP server → Fetch pipeline: invokes
- MCP server → LLM workflows: invokes
- Crawl and map → URL security: validates discovered URLs
- Crawl and map → Fetch pipeline: fetches permitted URLs
- Fetch pipeline → URL security: checks targets
- Fetch pipeline → Target websites: retrieves
- Fetch pipeline → Proxy and browser: selects
- Fetch pipeline → Hosted access: falls back to
- Fetch pipeline → Site extractors: dispatches specialized content
- Fetch pipeline → Core extraction: passes documents to
- Fetch pipeline → PDF extraction: routes PDFs to
- Site extractors → Core extraction: enriches generic extraction
- Core extraction → Content formats: normalizes into
- Content formats → LLM workflows: supplies context to
- LLM workflows → Model providers: uses
- Model providers → Model APIs: calls
