TrendDraw - Story
Project Story

Challenge

An AI app builder (Emergent) can scaffold a working full-stack app in minutes. "Runs on my machine" and "safe to expose on a real domain" are different bars entirely — the actual challenge was closing that gap.

Approach

Three concrete swaps, not a rewrite: MongoDB (Motor) for draws, subscribers, saved picks, and ingest metadata became four DynamoDB tables with GSIs for the two lookups Mongo did with a plain query; the in-process APScheduler cron running inside the FastAPI process became EventBridge rules invoking a separate ingest Lambda; and a single implicitly-trusted process became two Lambdas with two least-privilege IAM roles, each scoped only to the tables and actions it actually touches. Also deleted a proprietary, unshippable LLM SDK (litellm/openai/google-genai/pandas/numpy, ~1.2GB) for the public Anthropic SDK — which is also what let the deploy shrink from a Docker/ECR image to a plain Lambda zip. analytics.py and backtest.py were left untouched: pure functions over in-memory data, no persistence coupling, nothing to fix.

Security

The Anthropic key started in a scaffolded app's plaintext .env. It now lives in SSM Parameter Store as a SecureString, with the API Lambda's IAM role scoped to ssm:GetParameter and kms:Decrypt on that one parameter — the value never enters Terraform state, a Lambda console env var, or source control, and rotating it is one CLI call, not a redeploy.

Outcome

A serverless Python backend behind API Gateway, real scheduled data ingestion, and Claude-powered trend analysis, all Terraform-managed and served through the portfolio's existing CloudFront distribution.

Runtime Sequence
1. Scheduled Ingest
EventBridge fires on a cron matched to real draw days (Mega Millions Wed/Sat, Powerball Tue/Thu/Sun), invoking the ingest Lambda.
2. Store & Detect
New draws are written to DynamoDB; if a draw is genuinely new, subscriber email alerts are queued via SES or Resend.
3. Analyze & Suggest
The API Lambda computes hot/cold/overdue statistics and asks Claude to blend them into suggested number sets, always disclaimed as entertainment only.
4. Backtest for Honesty
A backtest endpoint compares every strategy against a random baseline, so the app can't quietly overstate its own accuracy.