# albirgit/lead_generation_pipeline architecture

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

- Interactive diagram: https://gitdiagram.com/albirgit/lead_generation_pipeline
- Repository: https://github.com/albirgit/lead_generation_pipeline

## Overview

#### Purpose and execution model
This repository is a file-oriented lead-generation pipeline. It turns campaign source data into enriched, ranked, and batchable Excel lead lists. The main reusable entry points are stage pipeline modules rather than a web service or CLI: `lead_pipeline/modules/step1_document_intelligence/pipeline.py` and `lead_pipeline/modules/step2_thomasnet_scraper/pipeline.py`.

#### Campaign workspace and artifacts
Campaigns are organized as input/output directories, exemplified by `lead_pipeline/campaigns/electrical_Illinois/`. The current campaign consumes `Input/raw.xlsx` and persists intermediate and final workbook artifacts under `Output/`, including ranked leads, domain-upload files, scraper result batches, merged batches, and final batches. This filesystem boundary is the primary integration contract between stages and manual/external enrichment processes.

#### Stage 1: document intelligence
`lead_pipeline/modules/step1_document_intelligence/pipeline.py` orchestrates document ingestion, interpretation, and output persistence. `document_parser.py` extracts source-document content, while `llm_analyzer.py` applies LLM-based analysis to produce structured lead-relevant information. `models.py` defines the stage’s domain/result structures; `output_io.py` materializes results for subsequent processing. Configuration and failure behavior are isolated in `config.py` and `exceptions.py`.

#### Stage 2: Thomasnet discovery and scraping
`lead_pipeline/modules/step2_thomasnet_scraper/pipeline.py` drives supplier/company discovery against Thomasnet. Browser lifecycle and automation are separated in `browser.py`; request/page collection is handled by `scraper.py`; and extracted page content is transformed in `parser.py`. Structured records and Excel/file exchange are owned by `models.py` and `output_io.py`. This stage is the principal external-service boundary and likely requires a browser-capable runtime plus network access.

#### Lead enrichment, scoring, and reviews
The post-discovery layer is implemented in `lead_pipeline/modules/preprocessorANDscorer.py` and `lead_pipeline/modules/maps_reviews.py`. These modules normalize/enrich candidate lead data, derive ranking signals, and incorporate map/review information before leads are written to `leads_ranked.xlsx`. Maps/reviews represent another external data boundary, separate from Thomasnet scraping.

#### Batch assembly and downstream handoff
`lead_pipeline/modules/files_merger.py` combines enrichment outputs into campaign-ready batches. The artifact sequence in `Output/` indicates an iterative handoff: scraper results (`snov_results_batch_*.xlsx`) are merged (`merged_batch_*.xlsx`) and finalized (`final_batch_*.xlsx`), with `domains_upload.xlsx` supporting domain-based external enrichment/upload workflows. The repository therefore supports both automated processing and spreadsheet-mediated operational steps.

#### Runtime and dependencies
The project is Python-based (`lead_pipeline/__init__.py`) with dependencies declared in `requirements.txt`. Material infrastructure is local filesystem storage for campaign artifacts, browser automation for Thomasnet, an LLM provider/runtime for document intelligence, and external maps/review plus likely email/domain enrichment systems implied by Snov-named output files. There is no evidence in the tree of a deployed API, database, queue, or frontend.

Main entry points: [`lead_pipeline/modules/step1_document_intelligence/llm_analyzer.py`](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step1_document_intelligence/llm_analyzer.py) (LLM analyzer), [`lead_pipeline/modules/step2_thomasnet_scraper/scraper.py`](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/scraper.py) (Thomasnet scraper), [`lead_pipeline/modules/preprocessorANDscorer.py`](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/preprocessorANDscorer.py) (Lead enrichment and scoring), [`lead_pipeline/modules/maps_reviews.py`](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/maps_reviews.py) (Maps and reviews)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_campaign["Campaign workspace"]
  node_raw_input["Raw campaign workbook<br/>Excel input<br/>[raw.xlsx]"]
  node_campaign_output[("Campaign Output<br/>artifact directory")]
  node_ranked_leads["Ranked leads workbook<br/>Excel artifact"]
  node_domains_upload["Domain upload workbook<br/>Excel handoff"]
  node_final_batches["Final batch workbooks<br/>Excel artifact"]
end

subgraph group_document["Document intelligence"]
  node_doc_pipeline["Stage 1 pipeline<br/>Python orchestrator<br/>[pipeline.py]"]
  node_document_parser["Document parser<br/>content extraction<br/>[document_parser.py]"]
  node_llm_analyzer["LLM analyzer<br/>structured analysis<br/>[llm_analyzer.py]"]
  node_llm_provider{{"LLM provider/runtime<br/>external AI service"}}
end

subgraph group_discovery["Thomasnet discovery"]
  node_thomas_pipeline["Stage 2 pipeline<br/>Python orchestrator<br/>[pipeline.py]"]
  node_browser["Browser automation<br/>browser lifecycle<br/>[browser.py]"]
  node_scraper["Thomasnet scraper<br/>page collection<br/>[scraper.py]"]
  node_thomasnet{{"Thomasnet<br/>external supplier source"}}
  node_page_parser["Page parser<br/>record extraction<br/>[parser.py]"]
end

subgraph group_enrichment["Enrichment and handoff"]
  node_preprocessor_scorer["Lead enrichment and scoring<br/>Python processing module"]
  node_maps_reviews["Maps and reviews<br/>external-data enrichment<br/>[maps_reviews.py]"]
  node_maps_service{{"Maps/review sources<br/>external service"}}
  node_files_merger["Batch merger<br/>Python assembly module<br/>[files_merger.py]"]
  node_domain_enrichment{{"Domain/email enrichment<br/>external operational workflow"}}
end

node_raw_input -->|"ingests"| node_doc_pipeline
node_doc_pipeline -->|"extracts content"| node_document_parser
node_document_parser -->|"source content"| node_llm_analyzer
node_llm_analyzer -->|"analysis request"| node_llm_provider
node_llm_analyzer -->|"structured artifacts"| node_campaign_output
node_campaign_output -->|"campaign inputs"| node_thomas_pipeline
node_thomas_pipeline -->|"controls"| node_browser
node_browser -->|"browser session"| node_scraper
node_scraper -->|"collects pages"| node_thomasnet
node_scraper -->|"page content"| node_page_parser
node_page_parser -->|"scraper result batches"| node_campaign_output
node_campaign_output -->|"candidate leads"| node_preprocessor_scorer
node_preprocessor_scorer -->|"enrichment requests"| node_maps_reviews
node_maps_reviews -->|"retrieves signals"| node_maps_service
node_maps_reviews -->|"review-enriched leads"| node_ranked_leads
node_preprocessor_scorer -->|"domains for handoff"| node_domains_upload
node_domains_upload -.->|"upload/download workflow"| node_domain_enrichment
node_domain_enrichment -.->|"Snov result batches"| node_campaign_output
node_campaign_output -->|"merged batch inputs"| node_files_merger
node_files_merger -->|"finalizes batches"| node_final_batches

click node_raw_input "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/campaigns/electrical_Illinois/Input/raw.xlsx"
click node_doc_pipeline "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step1_document_intelligence/pipeline.py"
click node_document_parser "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step1_document_intelligence/document_parser.py"
click node_llm_analyzer "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step1_document_intelligence/llm_analyzer.py"
click node_thomas_pipeline "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/pipeline.py"
click node_browser "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/browser.py"
click node_scraper "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/scraper.py"
click node_page_parser "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/parser.py"
click node_preprocessor_scorer "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/preprocessorANDscorer.py"
click node_maps_reviews "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/maps_reviews.py"
click node_files_merger "https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/files_merger.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_raw_input,node_campaign_output,node_ranked_leads,node_domains_upload,node_final_batches toneBlue
class node_doc_pipeline,node_document_parser,node_llm_analyzer,node_llm_provider toneAmber
class node_thomas_pipeline,node_browser,node_scraper,node_thomasnet,node_page_parser toneMint
class node_preprocessor_scorer,node_maps_reviews,node_maps_service,node_files_merger,node_domain_enrichment toneRose
```

## Components

### Campaign workspace

Spreadsheet artifacts are the inter-stage contract.

- [Raw campaign workbook](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/campaigns/electrical_Illinois/Input/raw.xlsx): Excel input · `lead_pipeline/campaigns/electrical_Illinois/Input/raw.xlsx`
- **Campaign Output**: artifact directory · Stores intermediate, ranked, and final workbooks.
- **Ranked leads workbook**: Excel artifact
- **Domain upload workbook**: Excel handoff · Supports external domain/email enrichment workflows.
- **Final batch workbooks**: Excel artifact · Snov results are merged into final campaign batches.

### Document intelligence

- [Stage 1 pipeline](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step1_document_intelligence/pipeline.py): Python orchestrator · `lead_pipeline/modules/step1_document_intelligence/pipeline.py`
- [Document parser](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step1_document_intelligence/document_parser.py): content extraction · `lead_pipeline/modules/step1_document_intelligence/document_parser.py`
- [LLM analyzer](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step1_document_intelligence/llm_analyzer.py): structured analysis · `lead_pipeline/modules/step1_document_intelligence/llm_analyzer.py`
- **LLM provider/runtime**: external AI service

### Thomasnet discovery

- [Stage 2 pipeline](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/pipeline.py): Python orchestrator · `lead_pipeline/modules/step2_thomasnet_scraper/pipeline.py`
- [Browser automation](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/browser.py): browser lifecycle · `lead_pipeline/modules/step2_thomasnet_scraper/browser.py`
- [Thomasnet scraper](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/scraper.py): page collection · `lead_pipeline/modules/step2_thomasnet_scraper/scraper.py`
- **Thomasnet**: external supplier source · Requires network and browser-capable execution.
- [Page parser](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/step2_thomasnet_scraper/parser.py): record extraction · `lead_pipeline/modules/step2_thomasnet_scraper/parser.py`

### Enrichment and handoff

- [Lead enrichment and scoring](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/preprocessorANDscorer.py): Python processing module · Normalizes candidates and derives ranking signals. · `lead_pipeline/modules/preprocessorANDscorer.py`
- [Maps and reviews](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/maps_reviews.py): external-data enrichment · `lead_pipeline/modules/maps_reviews.py`
- **Maps/review sources**: external service
- [Batch merger](https://github.com/albirgit/lead_generation_pipeline/blob/main/lead_pipeline/modules/files_merger.py): Python assembly module · `lead_pipeline/modules/files_merger.py`
- **Domain/email enrichment**: external operational workflow · Spreadsheet-mediated external handoff.

## Connections

- Raw campaign workbook → Stage 1 pipeline: ingests
- Stage 1 pipeline → Document parser: extracts content
- Document parser → LLM analyzer: source content
- LLM analyzer → LLM provider/runtime: analysis request
- LLM analyzer → Campaign Output: structured artifacts
- Campaign Output → Stage 2 pipeline: campaign inputs
- Stage 2 pipeline → Browser automation: controls
- Browser automation → Thomasnet scraper: browser session
- Thomasnet scraper → Thomasnet: collects pages
- Thomasnet scraper → Page parser: page content
- Page parser → Campaign Output: scraper result batches
- Campaign Output → Lead enrichment and scoring: candidate leads
- Lead enrichment and scoring → Maps and reviews: enrichment requests
- Maps and reviews → Maps/review sources: retrieves signals
- Maps and reviews → Ranked leads workbook: review-enriched leads
- Lead enrichment and scoring → Domain upload workbook: domains for handoff
- Domain upload workbook → Domain/email enrichment: upload/download workflow
- Domain/email enrichment → Campaign Output: Snov result batches
- Campaign Output → Batch merger: merged batch inputs
- Batch merger → Final batch workbooks: finalizes batches
