﻿# INVESTIGATION: Lead Capture Feature Implementation
Date: 2025-09-11
Feature: Lead_Capture (NEW FEATURE - Direct to Slack, No Database)

## INVESTIGATION FINDINGS

### 1. CURRENT INFRASTRUCTURE STATUS
- **forms.py**: DOES NOT EXIST (need to create)
- **Flask-WTF**: NOT INSTALLED (but CSRF is configured in config.py)
- **WTForms**: NOT INSTALLED (need to add to requirements)
- **requests library**: INSTALLED (v2.32.4) ✓
- **Slack integration**: NONE EXISTS (need to create)
- **Lead/Subscriber models**: NONE (not needed per request)
- **Utils directory**: EXISTS at app/utils/ ✓

### 2. LANDING PAGE ANALYSIS
- **File**: app/templates/index.html
- **Size**: 405 lines total
- **Structure**: Static HTML, no forms currently
- **JavaScript**: Inline script for calculator only
- **No modals/popups**: Clean insertion point available
- **Footer location**: Line 373 (perfect for form insertion)
- **Hero section**: Has CTA potential for link to form

### 3. ROUTING PATTERNS FOUND
- **POST handling**: Uses request.form.get() pattern
- **JSON responses**: jsonify imported and used
- **Error handling**: try/except blocks with flash messages
- **No CSRF tokens**: Currently not generating tokens (despite config)
- **Pattern example**: /jobs/post handles forms without Flask-WTF

### 4. CONFIGURATION STATUS
- **SECRET_KEY**: Set (required for sessions)
- **WTF_CSRF_ENABLED**: True (but Flask-WTF not installed)
- **WTF_CSRF_TIME_LIMIT**: None
- **Mail config**: Present but unused
- **Environment pattern**: Using .env file

### 5. EXISTING PATTERNS TO FOLLOW
- **Webhook pattern**: stripe_webhooks.py shows webhook handling
- **Form processing**: Manual with request.form.get()
- **Response pattern**: JSON responses for API endpoints
- **Error pattern**: try/except with flash messages

### 6. FILES THAT NEED CREATION
1. app/forms.py (NEW)
2. app/utils/slack.py (NEW)

### 7. FILES THAT NEED MODIFICATION
1. app/routes.py (add capture route)
2. app/templates/index.html (add form section)
3. requirements.txt (add Flask-WTF, WTForms)
4. .env (add SLACK_WEBHOOK_URL)

## RISK ASSESSMENT
- **Low Risk**: Isolated feature, no database changes
- **CSRF Issue**: Config expects Flask-WTF but not installed
- **Solution**: Install Flask-WTF to match config expectations
- **No Breaking Changes**: Adding new route, not modifying existing

## CRITICAL FINDINGS
1. System expects Flask-WTF (config has WTF_CSRF_ENABLED=True)
2. Must install Flask-WTF to avoid CSRF errors
3. Can insert form before footer (line 372)
4. Use existing request.form.get() pattern
5. Follow stripe_webhooks.py pattern for Slack webhook
