Assessment submission by Yash Vardhan Malik
A full-stack automated lead qualification and report delivery system. A prospect submits a form → the system researches their company, generates a personalized AI business intelligence report, and emails it as a PDF — zero human intervention.
Prospect submits form
↓
[Validate Input] — Pydantic + Zod (frontend + backend)
↓
[Data Enrichment] — Website scraping + Web search + Clearbit API
↓
[AI Report Generation] — Groq Llama 3.1-70B with engineered prompt
↓
[PDF Generation] — WeasyPrint renders a 4-page branded PDF
↓
[Email Delivery] — Resend API sends PDF to prospect
↓
[Sheets Logging] — BONUS: row appended to Google Sheet
↓
[Drive Archive] — BONUS: PDF saved to Google Drive folder
| Layer | Technology |
|---|---|
| Frontend | Next.js 15, TypeScript, Tailwind CSS, react-hook-form, Zod |
| Backend API | FastAPI, Python 3.11, Pydantic v2, uvicorn |
| Enrichment | httpx, BeautifulSoup4, Tavily / SerpAPI, Clearbit |
| AI | Groq SDK — Llama 3.1-70B Versatile |
| WeasyPrint + Jinja2 | |
| Resend Python SDK | |
| Bonus | gspread (Google Sheets), Google Drive API v3 |
LeadAutomation/
├── backend/
│ ├── main.py # FastAPI app, routes, rate limiting
│ ├── config.py # Pydantic-settings typed config
│ ├── models/
│ │ └── lead.py # LeadInput, EnrichedData, PipelineResult
│ ├── pipeline/
│ │ ├── orchestrator.py # Master pipeline controller
│ │ ├── enrichment.py # Scraping + search + Clearbit
│ │ ├── ai_generator.py # Groq report generation
│ │ ├── pdf_generator.py # WeasyPrint PDF renderer
│ │ └── email_sender.py # Resend email delivery
│ ├── services/
│ │ ├── sheets.py # Google Sheets logging (bonus)
│ │ └── drive.py # Google Drive archiving (bonus)
│ ├── templates/
│ │ └── report.html # Jinja2 report template (4 pages)
│ ├── utils/
│ │ ├── logger.py # Pipeline step logger
│ │ └── validators.py # Input sanitization helpers
│ ├── generated_pdfs/ # PDF output directory (git-ignored)
│ ├── requirements.txt
│ └── .env.example
└── frontend/
├── app/
│ ├── page.tsx # Homepage with lead form
│ └── layout.tsx # App layout + metadata
├── components/
│ ├── LeadForm.tsx # Main form (react-hook-form + Zod)
│ ├── FormField.tsx # Reusable labeled field wrapper
│ └── SuccessScreen.tsx # Post-submission success state
├── lib/
│ └── schema.ts # Zod validation schema
└── .env.local.example
- Python 3.11+
- Node.js 18+
- A Groq API key (free)
- A Resend API key (free, 100 emails/day)
- At least one search API: Tavily (recommended) or SerpAPI
cd backend
cp .env.example .env
# Fill in your API keys in .env
pip install -r requirements.txt
uvicorn main:app --reload --port 8000cd frontend
cp .env.local.example .env.local
# NEXT_PUBLIC_API_URL=http://localhost:8000
npm install
npm run devVisit http://localhost:3000, fill in the lead form, and check the email inbox.
See backend/.env.example for full documentation. Minimum required:
GROQ_API_KEY=... # Required — AI report generation
RESEND_API_KEY=... # Required — email delivery
TAVILY_API_KEY=... # Recommended — web search enrichmentOptional (enrichment quality):
SERPAPI_KEY=... # Alternative to Tavily
CLEARBIT_API_KEY=... # Company metadata, logo, size
HUNTER_API_KEY=... # Email/company dataBonus (Google integration):
GOOGLE_SERVICE_ACCOUNT_JSON=path/to/key.json
GOOGLE_SHEET_ID=...
GOOGLE_DRIVE_FOLDER_ID=...| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Health ping |
| GET | /health |
Detailed integration status |
| POST | /submit-lead |
Submit lead → triggers pipeline (202 async) |
| GET | /docs |
Swagger UI |
{
"name": "Arjun Mehta",
"email": "arjun@finflow.io",
"company_name": "FinFlow Technologies",
"industry": "FinTech / Finance",
"company_description": "We automate accounts payable for mid-market CFOs.",
"website": "https://finflow.io",
"role": "Founder",
"city": "Mumbai",
"company_size": "11-50"
}Returns 202 Accepted immediately. The pipeline runs in the background.
Async-first pipeline — every enrichment layer (scraping, search, Clearbit) runs concurrently via asyncio.gather. Total enrichment time is bounded by the slowest layer, not their sum.
Graceful degradation — each pipeline step has its own try/except. If scraping fails (bot detection, timeout), search still runs. If search fails, the AI uses form data only. The email always goes out.
Quality-aware AI prompting — the Groq prompt explicitly tells the model what data quality level it's working with (HIGH/MEDIUM/LOW) and adjusts instructions accordingly. LOW quality prompts the model to lean on industry expertise rather than fake specificity.
WeasyPrint over reportlab/fpdf — WeasyPrint takes HTML+CSS → PDF, which means the template is maintainable by anyone who knows HTML. No low-level coordinate math. The tradeoff is WeasyPrint needs system fonts and is slightly slower (~1-2s).
Resend over SMTP — zero configuration, no DNS setup beyond domain verification, and built-in deliverability optimization. The free tier covers the assessment use case entirely.
Background tasks over Celery — FastAPI's BackgroundTasks is sufficient for a single-server prototype. In production with horizontal scaling, this would move to Celery + Redis.
- Rate limited to 1 submission per IP per 60 seconds (configurable)
- Website scraping may be blocked by Cloudflare/anti-bot on some company sites
- Clearbit has a limited free tier — enrichment falls back gracefully
- WeasyPrint requires system libraries (libpango, libcairo) — see WeasyPrint docs for OS-specific install
- ✅ Google Sheets logging — every lead appended as a row with status
- ✅ Google Drive archiving — PDF saved to a configured Drive folder
- ✅ Rate limiting — per-IP in-memory limiter (production: replace with Redis)
- ✅ Multi-layer enrichment — scraping + search + API, concurrent
- ✅ Quality-adaptive AI — prompt adapts to available data depth
- ✅ 4-page branded PDF — cover + 3 content pages with WeasyPrint