# shre-yes/leadflow-ai architecture

> Architecture diagram of the GitHub repository shre-yes/leadflow-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shre-yes/leadflow-ai
- Repository: https://github.com/shre-yes/leadflow-ai

## Overview

1. **Repository shape**
   - This repo is not a traditional application codebase; it is primarily an **n8n workflow export** (`lead_processing_system.json`) plus documentation and screenshots in `assets/`.
   - The architecture lives inside the workflow definition, so the main “system boundary” is the n8n automation runtime.

2. **Primary runtime boundary: n8n**
   - n8n is the orchestration layer that connects all services.
   - It receives lead records, moves them through scoring/enrichment steps, and then fans out into notification and logging paths.

3. **Lead ingestion path**
   - Leads originate in **Google Forms**, land in **Google Sheets**, and are then picked up by the n8n workflow.
   - In architectural terms, Google Sheets acts as the intake surface for form submissions, not just a datastore.

4. **Processing core: rule-based scoring**
   - A **Code node** in the workflow runs custom **Python-based logic** to score leads.
   - The scoring uses three main signals from the lead data:
     - estimated monthly order volume
     - job authority / designation
     - number of requested needs/services
   - This is the first decisioning layer and produces a numeric priority score.

5. **LLM enrichment layer**
   - After scoring, the workflow calls **Groq** for LLM-based summarization/enrichment.
   - This step turns raw lead fields into a concise narrative summary suitable for sales triage.
   - The LLM is an external service boundary; the workflow depends on it for human-readable context, not for the core priority calculation.

6. **Priority classification**
   - The workflow categorizes leads into **HOT / WARM / COLD** based on score thresholds.
   - This creates the key routing boundary in the system:
     - high-priority leads trigger immediate alerting
     - all leads are still persisted for tracking

7. **Notification path**
   - **HOT** leads are pushed to **Slack**, specifically to a high-priority channel (`hot_leads` per README).
   - Slack is the real-time operational output for the sales team, used only for urgent visibility rather than long-term storage.

8. **Persistence path**
   - Every lead is logged to **Google Sheets** with fields like date, priority, score, contact info, services, and summary.
   - This sheet functions as the system of record for lead tracking and auditing.

9. **Data flow summary**
   - The end-to-end flow is:
     - Google Forms → Google Sheets → n8n workflow → Python scoring → Groq summarization → priority decision → Slack for HOT leads → Google Sheets logging for all leads
   - The workflow is effectively a split path after classification: one branch for notification and one for persistence.

10. **Operational dependencies**
   - The system depends on external credentials and integrations:
     - Google Sheets OAuth2 / Google Cloud access
     - Groq API key
     - Slack app credentials or webhook
   - These integrations are part of the deployment boundary, not the repo itself.

11. **What is and isn’t in the repo**
   - There is **no standalone backend service, frontend, database schema, or container setup** in this repository.
   - The architecture is mostly declarative automation plus configuration, with the workflow JSON as the executable artifact.

12. **Diagramming takeaway**
   - When drawing the architecture, center the diagram on **n8n** and show it orchestrating three external systems: **Google Sheets**, **Groq**, and **Slack**.
   - Treat Google Forms as the upstream source feeding Sheets, and Sheets as both ingestion buffer and persistent log.

Main entry points: [`lead_processing_system.json`](https://github.com/shre-yes/leadflow-ai/blob/main/lead_processing_system.json) (Workflow export), [`README.md`](https://github.com/shre-yes/leadflow-ai/blob/main/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Repository"]
  node_readme["README<br/>documentation<br/>[README.md]"]
  node_workflow_json["Workflow export<br/>n8n export"]
  node_assets["Assets<br/>screenshots"]
end

subgraph group_workflow["n8n Workflow"]
  node_n8n{{"n8n<br/>orchestrator"}}
  node_trigger(("Lead trigger<br/>ingest trigger"))
  node_normalize["Lead prep<br/>transform"]
  node_score["Lead score<br/>python logic"]
  node_signals["Scoring signals<br/>ruleset"]
  node_summarize["Lead summary<br/>enrichment"]
  node_classify{{"Priority gate<br/>classifier"}}
  node_log[("Lead log<br/>persistence")]
end

subgraph group_external["External Systems"]
  node_forms(("Google Forms<br/>lead source"))
  node_sheets_in[("Intake Sheet<br/>staging sheet")]
  node_groq(("Groq<br/>llm service"))
  node_slack(("Slack<br/>alert sink"))
  node_sheets_out[("Tracking Sheet<br/>system of record")]
end

node_forms -->|"submit"| node_sheets_in
node_sheets_in -->|"pickup"| node_trigger
node_trigger -->|"start"| node_n8n
node_n8n -->|"prepare"| node_normalize
node_normalize -->|"features"| node_signals
node_signals -->|"drive"| node_score
node_score -->|"context"| node_groq
node_groq -->|"return"| node_summarize
node_score -->|"score"| node_classify
node_summarize -->|"enrich"| node_classify
node_classify -->|"HOT"| node_slack
node_classify -->|"all leads"| node_log
node_log -->|"write"| node_sheets_out
node_workflow_json -.->|"defines"| node_n8n
node_readme -.->|"documents"| node_workflow_json

click node_readme "https://github.com/shre-yes/leadflow-ai/blob/main/README.md"
click node_workflow_json "https://github.com/shre-yes/leadflow-ai/blob/main/lead_processing_system.json"
click node_assets "https://github.com/shre-yes/leadflow-ai/tree/main/assets"

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_readme,node_workflow_json,node_assets toneBlue
class node_n8n,node_trigger,node_normalize,node_score,node_signals,node_summarize,node_classify,node_log toneAmber
class node_forms,node_sheets_in,node_groq,node_slack,node_sheets_out toneMint
```

## Components

### Repository

Source materials and exported workflow artifact

- [README](https://github.com/shre-yes/leadflow-ai/blob/main/README.md): documentation · Human-facing overview and usage notes · `README.md`
- [Workflow export](https://github.com/shre-yes/leadflow-ai/blob/main/lead_processing_system.json): n8n export · Executable lead processing definition · `lead_processing_system.json`
- [Assets](https://github.com/shre-yes/leadflow-ai/tree/main/assets): screenshots · Reference images and visual documentation · `assets`

### n8n Workflow

Automation runtime and processing stages

- **n8n**: orchestrator · Workflow runtime that coordinates ingestion, enrichment, and routing
- **Lead trigger**: ingest trigger · Starts the workflow when new lead records are available
- **Lead prep**: transform · Normalizes incoming lead fields for downstream processing
- **Lead score**: python logic · Code node that computes numeric priority from lead signals
- **Scoring signals**: ruleset · Monthly volume, authority, and requested services
- **Lead summary**: enrichment · Produces human-readable narrative context for sales triage
- **Priority gate**: classifier · Maps scores to HOT, WARM, and COLD routing bands
- **Lead log**: persistence · Writes all lead records and tracking fields back to Sheets

### External Systems

Upstream and downstream integrations

- **Google Forms**: lead source · Upstream form submissions that originate leads
- **Intake Sheet**: staging sheet · Sheets surface where form submissions are picked up
- **Groq**: llm service · LLM boundary used for concise lead summarization
- **Slack**: alert sink · Real-time notification channel for urgent leads
- **Tracking Sheet**: system of record · Persistent audit and tracking store for all processed leads

## Connections

- Google Forms → Intake Sheet: submit · Form submissions land in Sheets
- Intake Sheet → Lead trigger: pickup · n8n reads new lead records from the intake sheet
- Lead trigger → n8n: start · Workflow runtime begins processing
- n8n → Lead prep: prepare · Incoming data is shaped for scoring and enrichment
- Lead prep → Scoring signals: features · Lead fields are reduced to scoring inputs
- Scoring signals → Lead score: drive · Scoring logic evaluates the lead signals
- Lead score → Groq: context · Lead context is passed for LLM enrichment
- Groq → Lead summary: return · Groq produces concise narrative output
- Lead score → Priority gate: score · Numeric priority score is compared to thresholds
- Lead summary → Priority gate: enrich · Summary is attached before routing decisions
- Priority gate → Slack: HOT · High-priority leads trigger immediate Slack alerts
- Priority gate → Lead log: all leads · Every classified lead is persisted for tracking
- Lead log → Tracking Sheet: write · Processed lead data is appended to the tracking sheet
- Workflow export → n8n: defines · Exported workflow is the executable artifact for the runtime
- README → Workflow export: documents · Documentation explains the workflow behavior
