# lokeshdeore412-ctrl/lead-engine architecture

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

- Interactive diagram: https://gitdiagram.com/lokeshdeore412-ctrl/lead-engine
- Repository: https://github.com/lokeshdeore412-ctrl/lead-engine

## Overview

Lead Engine captures website signals in a client-side SDK, sends them to an n8n webhook, processes leads through documented classification and qualification stages, then persists results and notifies Slack. The README also documents configurable enrichment, AI sales context, idempotency, and error handling. The workflow JSON and SQL schema are present in the tree but were not excerpted, so internal workflow relationships rely on README documentation; no error-workflow file appears in the supplied tree.

Main entry points: [`lead-engine-workflow-v1.json`](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json) (n8n Webhook), [`lead-engine-sdk.js`](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-sdk.js) (Tracking SDK), [`client-config.json`](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/client-config.json) (Client Configuration), [`schema.sql`](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/schema.sql) (PostgreSQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Signal Capture"]
  node_sdk["Tracking SDK<br/>[lead-engine-sdk.js]"]
  node_webhook["n8n Webhook"]
end

subgraph group_processing["Lead Processing"]
  node_identity["Lead Identity"]
  node_classification["Lead Classification"]
  node_scoring["Deterministic Scoring"]
  node_qualification["Keyword Qualification"]
  node_enrichment["Lead Enrichment"]
  node_ai["AI Sales Context"]
  node_configuration["Client Configuration<br/>[client-config.json]"]
end

subgraph group_data["Storage and Context"]
  node_postgres[("PostgreSQL<br/>[schema.sql]")]
  node_idempotency["Event Idempotency<br/>[schema.sql]"]
end

subgraph group_delivery["Notifications"]
  node_slack["Slack Notifications"]
end

node_website(("Website"))
node_provider["Enrichment Provider"]
node_ai_provider["AI Provider"]
node_slack_service["Slack"]

node_website -->|"provides signals"| node_sdk
node_sdk -->|"POSTs events"| node_webhook
node_configuration -->|"configures capture"| node_sdk
node_webhook -->|"identifies leads"| node_identity
node_webhook -->|"classifies leads"| node_classification
node_webhook -->|"scores leads"| node_scoring
node_webhook -->|"qualifies leads"| node_qualification
node_webhook -->|"enriches leads"| node_enrichment
node_enrichment -.->|"HTTP enrichment"| node_provider
node_webhook -->|"generates context"| node_ai
node_ai -.->|"requests AI context"| node_ai_provider
node_webhook -->|"stores lead data"| node_postgres
node_webhook -->|"prevents duplicates"| node_idempotency
node_webhook -->|"triggers notifications"| node_slack
node_slack -->|"sends notifications"| node_slack_service

click node_sdk "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-sdk.js"
click node_webhook "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json"
click node_identity "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json"
click node_classification "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json"
click node_scoring "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json"
click node_qualification "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json"
click node_enrichment "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json"
click node_ai "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json"
click node_postgres "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/schema.sql"
click node_idempotency "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/schema.sql"
click node_slack "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json"
click node_configuration "https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/client-config.json"

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_sdk,node_webhook toneBlue
class node_identity,node_classification,node_scoring,node_qualification,node_enrichment,node_ai,node_configuration toneAmber
class node_postgres,node_idempotency toneMint
class node_slack toneRose
class node_website,node_provider,node_ai_provider,node_slack_service toneIndigo
```

## Components

### Signal Capture

- [Tracking SDK](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-sdk.js): `lead-engine-sdk.js`
- [n8n Webhook](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json): `lead-engine-workflow-v1.json`

### Lead Processing

- [Lead Identity](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json): `lead-engine-workflow-v1.json`
- [Lead Classification](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json): `lead-engine-workflow-v1.json`
- [Deterministic Scoring](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json): `lead-engine-workflow-v1.json`
- [Keyword Qualification](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json): `lead-engine-workflow-v1.json`
- [Lead Enrichment](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json): `lead-engine-workflow-v1.json`
- [AI Sales Context](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json): `lead-engine-workflow-v1.json`
- [Client Configuration](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/client-config.json): `client-config.json`

### Storage and Context

- [PostgreSQL](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/schema.sql): `schema.sql`
- [Event Idempotency](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/schema.sql): `schema.sql`

### Notifications

- [Slack Notifications](https://github.com/lokeshdeore412-ctrl/lead-engine/blob/main/lead-engine-workflow-v1.json): `lead-engine-workflow-v1.json`

### Other components

- **Website**
- **Enrichment Provider**
- **AI Provider**
- **Slack**

## Connections

- Website → Tracking SDK: provides signals (evidence: `readme.md`)
- Tracking SDK → n8n Webhook: POSTs events (evidence: `lead-engine-sdk.js`)
- Client Configuration → Tracking SDK: configures capture (evidence: `readme.md`)
- n8n Webhook → Lead Identity: identifies leads (evidence: `readme.md`)
- n8n Webhook → Lead Classification: classifies leads (evidence: `readme.md`)
- n8n Webhook → Deterministic Scoring: scores leads (evidence: `readme.md`)
- n8n Webhook → Keyword Qualification: qualifies leads (evidence: `readme.md`)
- n8n Webhook → Lead Enrichment: enriches leads (evidence: `readme.md`)
- Lead Enrichment → Enrichment Provider: HTTP enrichment (evidence: `readme.md`)
- n8n Webhook → AI Sales Context: generates context (evidence: `readme.md`)
- AI Sales Context → AI Provider: requests AI context (evidence: `readme.md`)
- n8n Webhook → PostgreSQL: stores lead data (evidence: `readme.md`)
- n8n Webhook → Event Idempotency: prevents duplicates (evidence: `readme.md`)
- n8n Webhook → Slack Notifications: triggers notifications (evidence: `readme.md`)
- Slack Notifications → Slack: sends notifications (evidence: `readme.md`)
