README
TrendDraw
A lottery trend analysis app. It ingests real Mega Millions and Powerball draw results on schedule, computes hot/cold/overdue statistics, and uses Claude to suggest number sets — always disclaimed as entertainment only, never as predictions.
What's Inside
Trend Analytics
Hot/cold/overdue frequency stats and frequent-pair detection, computed per game and time window.
AI Picks (Claude)
claude-sonnet-4-5 blends the computed trends into suggested sets with a one-sentence rationale each, always disclaimed as non-predictive.
Backtesting
Every strategy (hot, overdue, cold) is compared against a random baseline, so the app can't quietly overstate its own accuracy.
Draw Alerts
Subscribers opt into email alerts (SES or Resend) fired by the scheduled ingest pipeline, with working unsubscribe tokens.
Architecture Overview
API Lambda (FastAPI + Mangum)
Handles every read/write endpoint behind API Gateway's HTTP API: games, draws, analytics, AI picks, saved picks, subscriptions, backtests.
Ingest Lambda (Scheduled)
Triggered by EventBridge cron rules matched to real draw days. Fetches new results, writes to DynamoDB, and fires subscriber alerts on genuinely new draws.
AWS Resources (Terraform)
- Four DynamoDB tables:
trend-draw-draws,trend-draw-subscribers,trend-draw-saved-picks,trend-draw-meta - Two Lambda functions (
trend-draw-api,trend-draw-ingest) on Python 3.12, each with its own least-privilege IAM role - API Gateway HTTP API with a Lambda proxy integration
- Two EventBridge cron rules, matched to actual Mega Millions (Wed/Sat) and Powerball (Tue/Thu/Sun) draw schedules
- CloudWatch log groups for both Lambdas and API Gateway
- CloudFront distribution shared with the main portfolio (static frontend served at
/trend-draw)
Security & Repository Hygiene
- The Anthropic API key lives in SSM Parameter Store as a SecureString, fetched by the API Lambda at cold start — never in Terraform state, a Lambda console env var, or source control. Email provider keys (Resend/SES) that aren't secrets by nature stay as plain Lambda environment variables.
- The API Lambda and the ingest Lambda each get a separate IAM role, scoped only to the DynamoDB tables, SES actions, and (API Lambda only) the one SSM parameter + KMS key they actually use — neither can do the other's job.
- No secrets are baked into the deployed frontend bundle.
Testing
- 24 unit tests (
backend/tests/test_analytics.py,test_backtest.py) pin down the trend and backtest math — frequency/pct/heat, overdue-gap tie-breaking, pair co-occurrence, sample-size capping, the random-baseline formula — against hand-built fixtures with no network or DB dependency. - Written to verify the inherited analytics/backtest modules were understood correctly before anything downstream depended on them, not to hit a coverage number.
Local Development
Backend:
cd backend
pip install -r requirements.txt
uvicorn server:app --reload
Frontend:
cd frontend
yarn install
yarn start
Deployment
Infrastructure:
cd infra/terraform
terraform init
terraform apply
Frontend (builds and syncs to the portfolio's S3 bucket, then invalidates CloudFront):
cd frontend
yarn build
./deploy.sh