# Terraform and AI UI

## Terraform strategy
Terraform is used to make infrastructure changes repeatable, reviewable, and fast. The goal is to eliminate manual AWS console drift.

### What Terraform manages
- Amplify SSR hosting for the web app
- API Gateway for /api/token
- Lambda for /api/token and /api/chat
- Lambda URL for streaming /api/chat
- CloudFront distribution routing /api/chat to Lambda URL
- Route53 records
- S3 content bucket
- DynamoDB table for quotas (scaffold)
- WAF rules for the API

### Why this matters
- Consistency across environments
- Clear diffs for code review
- Reproducible deploys
- Easier rollback planning

## AI UI design decisions
The UI is intentionally minimal. It should feel like a focused assistant, not a feature-heavy product.

### Chat UX
- Start with a compact input centered on the page.
- After the first send, the input anchors to the bottom and content scrolls above it.
- The latest messages stay closest to the input, similar to ChatGPT.

### Rendering
- Assistant responses are rendered as Markdown for clarity.
- Code, lists, and structure are preserved to keep answers scannable.

### Sources
- Sources are displayed near the clicked message, not fixed at the top, to preserve context.

## Operational notes
- Streaming requires CloudFront + Lambda URL; API Gateway does not stream for this stack.
- CORS must be strict to prevent token misuse.

## Terraform tips
- Keep variables minimal and well-documented.
- Use outputs to publish the API edge URL and content bucket.
- Apply after building Lambda packages.
