# sapatil2212/leadgenpilot architecture

> Architecture diagram of the GitHub repository sapatil2212/leadgenpilot, 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/sapatil2212/leadgenpilot
- Repository: https://github.com/sapatil2212/leadgenpilot

## Overview

LeadGenPilot combines a Maps-based lead-finding workflow with a broader multi-tenant lead-generation workspace. The documented core flow is to scrape local businesses, score and deduplicate leads, then deliver them to Google Sheets; the application also exposes CRM, targeting, campaign, AI, knowledge-base, and compliance capabilities. The graph includes both documented and indexed application branches. Evidence is limited to the README, SOURCE INDEX references, and sampled excerpts; unsampled internals and some wiring are therefore omitted.

Main entry points: [`server.ts`](https://github.com/sapatil2212/leadgenpilot/blob/master/server.ts) (Application server), [`src/main.ts`](https://github.com/sapatil2212/leadgenpilot/blob/master/src/main.ts) (CLI runner), [`src/knowledge/knowledgeService.ts`](https://github.com/sapatil2212/leadgenpilot/blob/master/src/knowledge/knowledgeService.ts) (Knowledge base), [`crmRoutes.ts`](https://github.com/sapatil2212/leadgenpilot/blob/master/crmRoutes.ts) (Lead CRM)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Lead discovery"]
  node_runner["CLI runner<br/>[main.ts]"]
  node_maps["Maps scraper<br/>[mapsScraper.ts]"]
  node_scoring["Lead scoring<br/>[leadScoring.ts]"]
  node_dedupe["Lead deduplication"]
  node_sheets["Sheets delivery"]
end

subgraph group_workspace["Lead workspace"]
  node_webapp["Workspace UI<br/>[App.tsx]"]
  node_crm["Lead CRM<br/>[crmRoutes.ts]"]
  node_icp["Customer profiles<br/>[icpService.ts]"]
  node_scoring_config["Scoring rules<br/>[scoringService.ts]"]
  node_business["Business profile<br/>[businessService.ts]"]
end

subgraph group_engagement["Campaigns and outreach"]
  node_campaign["Campaign execution"]
  node_templates["Outreach templates<br/>[templateService.ts]"]
  node_suppression["Contact suppression"]
end

subgraph group_intelligence["AI and intelligence"]
  node_ai["AI orchestration<br/>[aiService.ts]"]
  node_knowledge["Knowledge base"]
  node_assistant["AI assistant"]
end

subgraph group_platform["Platform services"]
  node_server["Application server<br/>[server.ts]"]
  node_tenant_repo["Tenant data access<br/>[repository.ts]"]
  node_storage["JSON utilities<br/>[storage.ts]"]
end

node_operator(("Operator"))
node_maps_service(("Google Maps"))
node_sheets_service(("Google Sheets"))

node_operator -->|"starts search"| node_runner
node_runner -->|"runs scraper"| node_maps
node_maps -->|"queries listings"| node_maps_service
node_runner -->|"scores leads"| node_scoring
node_runner -->|"checks duplicates"| node_dedupe
node_runner -->|"submits leads"| node_sheets
node_sheets -->|"posts webhook"| node_sheets_service
node_operator -->|"uses workspace"| node_webapp
node_webapp -->|"imports CRM routes"| node_crm
node_crm -->|"queries tenant data"| node_tenant_repo
node_server -->|"imports CRM routes"| node_crm
node_server -->|"imports campaign executor"| node_campaign
node_server -->|"imports suppression service"| node_suppression
node_server -->|"imports knowledge service"| node_knowledge
node_server -->|"imports business service"| node_business
node_server -->|"imports ICP service"| node_icp
node_server -->|"imports scoring service"| node_scoring_config
node_server -->|"imports template service"| node_templates
node_server -->|"imports assistant service"| node_assistant
node_knowledge -->|"uses AI service"| node_ai
node_assistant -->|"uses AI service"| node_ai
node_knowledge -->|"extracts business knowledge"| node_business
node_business -.->|"uses file ingestion utilities"| node_storage
node_campaign -.->|"checks opt-outs"| node_suppression

click node_runner "https://github.com/sapatil2212/leadgenpilot/blob/master/src/main.ts"
click node_maps "https://github.com/sapatil2212/leadgenpilot/blob/master/src/mapsScraper.ts"
click node_scoring "https://github.com/sapatil2212/leadgenpilot/blob/master/src/leadScoring.ts"
click node_dedupe "https://github.com/sapatil2212/leadgenpilot/blob/master/src/duplicateChecker.ts"
click node_sheets "https://github.com/sapatil2212/leadgenpilot/blob/master/src/googleSheetsWebhook.ts"
click node_server "https://github.com/sapatil2212/leadgenpilot/blob/master/server.ts"
click node_webapp "https://github.com/sapatil2212/leadgenpilot/blob/master/src/App.tsx"
click node_crm "https://github.com/sapatil2212/leadgenpilot/blob/master/crmRoutes.ts"
click node_tenant_repo "https://github.com/sapatil2212/leadgenpilot/blob/master/src/tenancy/repository.ts"
click node_icp "https://github.com/sapatil2212/leadgenpilot/blob/master/src/icp/icpService.ts"
click node_scoring_config "https://github.com/sapatil2212/leadgenpilot/blob/master/src/scoring/scoringService.ts"
click node_campaign "https://github.com/sapatil2212/leadgenpilot/blob/master/src/campaign/campaignExecutor.ts"
click node_templates "https://github.com/sapatil2212/leadgenpilot/blob/master/src/templates/templateService.ts"
click node_suppression "https://github.com/sapatil2212/leadgenpilot/blob/master/src/compliance/suppressionService.ts"
click node_ai "https://github.com/sapatil2212/leadgenpilot/blob/master/src/ai/aiService.ts"
click node_knowledge "https://github.com/sapatil2212/leadgenpilot/blob/master/src/knowledge/knowledgeService.ts"
click node_business "https://github.com/sapatil2212/leadgenpilot/blob/master/src/business/businessService.ts"
click node_assistant "https://github.com/sapatil2212/leadgenpilot/blob/master/src/assistant/assistantService.ts"
click node_storage "https://github.com/sapatil2212/leadgenpilot/blob/master/src/storage.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_runner,node_maps,node_scoring,node_dedupe,node_sheets toneBlue
class node_webapp,node_crm,node_icp,node_scoring_config,node_business toneAmber
class node_campaign,node_templates,node_suppression toneMint
class node_ai,node_knowledge,node_assistant toneRose
class node_server,node_tenant_repo,node_storage,node_operator,node_maps_service,node_sheets_service toneIndigo
```

## Components

### Lead discovery

- [CLI runner](https://github.com/sapatil2212/leadgenpilot/blob/master/src/main.ts): `src/main.ts`
- [Maps scraper](https://github.com/sapatil2212/leadgenpilot/blob/master/src/mapsScraper.ts): `src/mapsScraper.ts`
- [Lead scoring](https://github.com/sapatil2212/leadgenpilot/blob/master/src/leadScoring.ts): `src/leadScoring.ts`
- [Lead deduplication](https://github.com/sapatil2212/leadgenpilot/blob/master/src/duplicateChecker.ts): `src/duplicateChecker.ts`
- [Sheets delivery](https://github.com/sapatil2212/leadgenpilot/blob/master/src/googleSheetsWebhook.ts): `src/googleSheetsWebhook.ts`

### Lead workspace

- [Workspace UI](https://github.com/sapatil2212/leadgenpilot/blob/master/src/App.tsx): `src/App.tsx`
- [Lead CRM](https://github.com/sapatil2212/leadgenpilot/blob/master/crmRoutes.ts): `crmRoutes.ts`
- [Customer profiles](https://github.com/sapatil2212/leadgenpilot/blob/master/src/icp/icpService.ts): `src/icp/icpService.ts`
- [Scoring rules](https://github.com/sapatil2212/leadgenpilot/blob/master/src/scoring/scoringService.ts): `src/scoring/scoringService.ts`
- [Business profile](https://github.com/sapatil2212/leadgenpilot/blob/master/src/business/businessService.ts): `src/business/businessService.ts`

### Campaigns and outreach

- [Campaign execution](https://github.com/sapatil2212/leadgenpilot/blob/master/src/campaign/campaignExecutor.ts): `src/campaign/campaignExecutor.ts`
- [Outreach templates](https://github.com/sapatil2212/leadgenpilot/blob/master/src/templates/templateService.ts): `src/templates/templateService.ts`
- [Contact suppression](https://github.com/sapatil2212/leadgenpilot/blob/master/src/compliance/suppressionService.ts): `src/compliance/suppressionService.ts`

### AI and intelligence

- [AI orchestration](https://github.com/sapatil2212/leadgenpilot/blob/master/src/ai/aiService.ts): `src/ai/aiService.ts`
- [Knowledge base](https://github.com/sapatil2212/leadgenpilot/blob/master/src/knowledge/knowledgeService.ts): `src/knowledge/knowledgeService.ts`
- [AI assistant](https://github.com/sapatil2212/leadgenpilot/blob/master/src/assistant/assistantService.ts): `src/assistant/assistantService.ts`

### Platform services

- [Application server](https://github.com/sapatil2212/leadgenpilot/blob/master/server.ts): `server.ts`
- [Tenant data access](https://github.com/sapatil2212/leadgenpilot/blob/master/src/tenancy/repository.ts): `src/tenancy/repository.ts`
- [JSON utilities](https://github.com/sapatil2212/leadgenpilot/blob/master/src/storage.ts): `src/storage.ts`

### Other components

- **Operator**
- **Google Maps**
- **Google Sheets**

## Connections

- Operator → CLI runner: starts search (evidence: `README.md`)
- CLI runner → Maps scraper: runs scraper (evidence: `README.md`)
- Maps scraper → Google Maps: queries listings (evidence: `README.md`)
- CLI runner → Lead scoring: scores leads (evidence: `README.md`)
- CLI runner → Lead deduplication: checks duplicates (evidence: `README.md`)
- CLI runner → Sheets delivery: submits leads (evidence: `README.md`)
- Sheets delivery → Google Sheets: posts webhook (evidence: `README.md`)
- Operator → Workspace UI: uses workspace (evidence: `src/App.tsx`)
- Workspace UI → Lead CRM: imports CRM routes (evidence: `src/App.tsx`)
- Lead CRM → Tenant data access: queries tenant data (evidence: `crmRoutes.ts`)
- Application server → Lead CRM: imports CRM routes (evidence: `server.ts`)
- Application server → Campaign execution: imports campaign executor (evidence: `server.ts`)
- Application server → Contact suppression: imports suppression service (evidence: `server.ts`)
- Application server → Knowledge base: imports knowledge service (evidence: `server.ts`)
- Application server → Business profile: imports business service (evidence: `server.ts`)
- Application server → Customer profiles: imports ICP service (evidence: `server.ts`)
- Application server → Scoring rules: imports scoring service (evidence: `server.ts`)
- Application server → Outreach templates: imports template service (evidence: `server.ts`)
- Application server → AI assistant: imports assistant service (evidence: `server.ts`)
- Knowledge base → AI orchestration: uses AI service (evidence: `src/knowledge/knowledgeService.ts`)
- AI assistant → AI orchestration: uses AI service (evidence: `src/assistant/assistantRoutes.ts`)
- Knowledge base → Business profile: extracts business knowledge (evidence: `src/knowledge/knowledgeRoutes.ts`)
- Business profile → JSON utilities: uses file ingestion utilities
- Campaign execution → Contact suppression: checks opt-outs
