# samex111/web-scrapper architecture

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

- Interactive diagram: https://gitdiagram.com/samex111/web-scrapper
- Repository: https://github.com/samex111/web-scrapper

## Overview

This is a web-scraping and lead-intelligence platform. Users submit website URLs through the dashboard or API; jobs are queued for asynchronous scraping, where sites are rendered and analyzed into scored business leads stored for dashboard review or export. The README also documents SEO/metadata extraction, social discovery, authentication, API-key access and quota controls. The graph combines sampled call relationships with README-documented architecture; several route and frontend implementation details were not sampled.

Main entry points: [`backend/src/queue/worker.ts`](https://github.com/samex111/web-scrapper/blob/main/backend/src/queue/worker.ts) (Scrape worker), [`backend/src/index.ts`](https://github.com/samex111/web-scrapper/blob/main/backend/src/index.ts) (Express API), [`frontend/lib/api.ts`](https://github.com/samex111/web-scrapper/blob/main/frontend/lib/api.ts) (Frontend API client), [`backend/src/db/client.ts`](https://github.com/samex111/web-scrapper/blob/main/backend/src/db/client.ts) (Lead database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_lead_review["Lead review<br/>[LeadTable.tsx]"]
  node_export_ui["Lead export UI<br/>[exportLead.tsx]"]
  node_api_client["Frontend API client<br/>[api.ts]"]
end

subgraph group_access["API and access"]
  node_express_api["Express API<br/>[index.ts]"]
  node_auth["Authentication<br/>[auth.routes.ts]"]
  node_api_keys["API key access<br/>[apiKey.routes.ts]"]
  node_quota["Quota controls"]
  node_scrape_routes["Scrape submission<br/>[scrape.routes.ts]"]
end

subgraph group_processing["Scraping and enrichment"]
  node_ai_discovery["Search discovery<br/>[ai.controller.ts]"]
  node_query_opt["Query optimization<br/>[queryOptimizer.ts]"]
  node_web_search["Web search"]
  node_url_extract["URL extraction<br/>[urlExtractor.ts]"]
  node_scraper["Site analysis<br/>[engine.ts]"]
  node_worker["Scrape worker<br/>[worker.ts]"]
end

subgraph group_state["Queue and persistence"]
  node_queue["Job queue<br/>[jobs.ts]"]
  node_database[("Lead database<br/>[client.ts]")]
end

node_user(("Platform user"))
node_google(("Google OAuth"))
node_ollama["Ollama service"]
node_tavily["Tavily search"]
node_websites(("Target websites"))

node_user -->|"submits URLs"| node_dashboard
node_dashboard -->|"creates job"| node_api_client
node_user -.->|"requests scraping"| node_express_api
node_api_client -.->|"calls API"| node_express_api
node_express_api -.->|"routes requests"| node_scrape_routes
node_scrape_routes -.->|"checks quota"| node_quota
node_scrape_routes -.->|"enqueues jobs"| node_queue
node_queue -.->|"dispatches jobs"| node_worker
node_worker -->|"scrapes sites"| node_scraper
node_scraper -.->|"reads pages"| node_websites
node_worker -->|"writes leads"| node_database
node_worker -->|"updates job status"| node_database
node_user -.->|"signs in"| node_auth
node_auth -->|"verifies token"| node_google
node_auth -->|"stores sessions"| node_database
node_user -.->|"uses API key"| node_api_keys
node_lead_review -.->|"loads leads"| node_api_client
node_export_ui -.->|"requests export"| node_api_client
node_express_api -.->|"serves lead data"| node_database
node_ai_discovery -->|"optimizes query"| node_query_opt
node_ai_discovery -->|"searches query"| node_web_search
node_ai_discovery -->|"extracts URLs"| node_url_extract
node_query_opt -->|"requests generation"| node_ollama
node_web_search -.->|"searches web"| node_tavily

click node_dashboard "https://github.com/samex111/web-scrapper/blob/main/frontend/app/(dashboard)/jobs/new/page.tsx"
click node_lead_review "https://github.com/samex111/web-scrapper/blob/main/frontend/components/leads/LeadTable.tsx"
click node_export_ui "https://github.com/samex111/web-scrapper/blob/main/frontend/components/export/exportLead.tsx"
click node_api_client "https://github.com/samex111/web-scrapper/blob/main/frontend/lib/api.ts"
click node_express_api "https://github.com/samex111/web-scrapper/blob/main/backend/src/index.ts"
click node_auth "https://github.com/samex111/web-scrapper/blob/main/backend/src/routes/auth.routes.ts"
click node_api_keys "https://github.com/samex111/web-scrapper/blob/main/backend/src/routes/apiKey.routes.ts"
click node_quota "https://github.com/samex111/web-scrapper/blob/main/backend/src/middleware/quota.middleware.ts"
click node_scrape_routes "https://github.com/samex111/web-scrapper/blob/main/backend/src/routes/scrape.routes.ts"
click node_ai_discovery "https://github.com/samex111/web-scrapper/blob/main/backend/src/controllers/ai.controller.ts"
click node_query_opt "https://github.com/samex111/web-scrapper/blob/main/backend/src/services/queryOptimizer.ts"
click node_web_search "https://github.com/samex111/web-scrapper/blob/main/backend/src/services/googleCustomSearch.ts"
click node_url_extract "https://github.com/samex111/web-scrapper/blob/main/backend/src/services/urlExtractor.ts"
click node_scraper "https://github.com/samex111/web-scrapper/blob/main/backend/src/scrape/engine.ts"
click node_worker "https://github.com/samex111/web-scrapper/blob/main/backend/src/queue/worker.ts"
click node_queue "https://github.com/samex111/web-scrapper/blob/main/backend/src/queue/jobs.ts"
click node_database "https://github.com/samex111/web-scrapper/blob/main/backend/src/db/client.ts"

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_dashboard,node_lead_review,node_export_ui,node_api_client,node_user toneBlue
class node_express_api,node_auth,node_api_keys,node_quota,node_scrape_routes toneAmber
class node_ai_discovery,node_query_opt,node_web_search,node_url_extract,node_scraper,node_worker toneMint
class node_queue,node_database toneRose
class node_google,node_ollama,node_tavily,node_websites toneIndigo
```

## Components

### User experience

- [Dashboard](https://github.com/samex111/web-scrapper/blob/main/frontend/app/(dashboard)/jobs/new/page.tsx): `frontend/app/(dashboard)/jobs/new/page.tsx`
- [Lead review](https://github.com/samex111/web-scrapper/blob/main/frontend/components/leads/LeadTable.tsx): `frontend/components/leads/LeadTable.tsx`
- [Lead export UI](https://github.com/samex111/web-scrapper/blob/main/frontend/components/export/exportLead.tsx): `frontend/components/export/exportLead.tsx`
- [Frontend API client](https://github.com/samex111/web-scrapper/blob/main/frontend/lib/api.ts): `frontend/lib/api.ts`

### API and access

- [Express API](https://github.com/samex111/web-scrapper/blob/main/backend/src/index.ts): `backend/src/index.ts`
- [Authentication](https://github.com/samex111/web-scrapper/blob/main/backend/src/routes/auth.routes.ts): `backend/src/routes/auth.routes.ts`
- [API key access](https://github.com/samex111/web-scrapper/blob/main/backend/src/routes/apiKey.routes.ts): `backend/src/routes/apiKey.routes.ts`
- [Quota controls](https://github.com/samex111/web-scrapper/blob/main/backend/src/middleware/quota.middleware.ts): `backend/src/middleware/quota.middleware.ts`
- [Scrape submission](https://github.com/samex111/web-scrapper/blob/main/backend/src/routes/scrape.routes.ts): `backend/src/routes/scrape.routes.ts`

### Scraping and enrichment

- [Search discovery](https://github.com/samex111/web-scrapper/blob/main/backend/src/controllers/ai.controller.ts): `backend/src/controllers/ai.controller.ts`
- [Query optimization](https://github.com/samex111/web-scrapper/blob/main/backend/src/services/queryOptimizer.ts): `backend/src/services/queryOptimizer.ts`
- [Web search](https://github.com/samex111/web-scrapper/blob/main/backend/src/services/googleCustomSearch.ts): `backend/src/services/googleCustomSearch.ts`
- [URL extraction](https://github.com/samex111/web-scrapper/blob/main/backend/src/services/urlExtractor.ts): `backend/src/services/urlExtractor.ts`
- [Site analysis](https://github.com/samex111/web-scrapper/blob/main/backend/src/scrape/engine.ts): `backend/src/scrape/engine.ts`
- [Scrape worker](https://github.com/samex111/web-scrapper/blob/main/backend/src/queue/worker.ts): `backend/src/queue/worker.ts`

### Queue and persistence

- [Job queue](https://github.com/samex111/web-scrapper/blob/main/backend/src/queue/jobs.ts): `backend/src/queue/jobs.ts`
- [Lead database](https://github.com/samex111/web-scrapper/blob/main/backend/src/db/client.ts): `backend/src/db/client.ts`

### Other components

- **Platform user**
- **Google OAuth**
- **Ollama service**
- **Tavily search**
- **Target websites**

## Connections

- Platform user → Dashboard: submits URLs (evidence: `frontend/app/(dashboard)/jobs/new/page.tsx`)
- Dashboard → Frontend API client: creates job (evidence: `frontend/app/(dashboard)/jobs/new/page.tsx`)
- Platform user → Express API: requests scraping (evidence: `README.md`)
- Frontend API client → Express API: calls API (evidence: `README.md`)
- Express API → Scrape submission: routes requests (evidence: `README.md`)
- Scrape submission → Quota controls: checks quota (evidence: `README.md`)
- Scrape submission → Job queue: enqueues jobs (evidence: `README.md`)
- Job queue → Scrape worker: dispatches jobs (evidence: `README.md`)
- Scrape worker → Site analysis: scrapes sites (evidence: `backend/src/queue/worker.ts`)
- Site analysis → Target websites: reads pages (evidence: `README.md`)
- Scrape worker → Lead database: writes leads (evidence: `backend/src/queue/worker.ts`)
- Scrape worker → Lead database: updates job status (evidence: `backend/src/queue/worker.ts`)
- Platform user → Authentication: signs in (evidence: `README.md`)
- Authentication → Google OAuth: verifies token (evidence: `backend/src/routes/auth.routes.ts`)
- Authentication → Lead database: stores sessions (evidence: `backend/src/routes/auth.routes.ts`)
- Platform user → API key access: uses API key (evidence: `README.md`)
- Lead review → Frontend API client: loads leads
- Lead export UI → Frontend API client: requests export
- Express API → Lead database: serves lead data (evidence: `README.md`)
- Search discovery → Query optimization: optimizes query (evidence: `backend/src/controllers/ai.controller.ts`)
- Search discovery → Web search: searches query (evidence: `backend/src/controllers/ai.controller.ts`)
- Search discovery → URL extraction: extracts URLs (evidence: `backend/src/controllers/ai.controller.ts`)
- Query optimization → Ollama service: requests generation (evidence: `backend/src/services/queryOptimizer.ts`)
- Web search → Tavily search: searches web (evidence: `README.md`)
