docs/architecture/overview.md
Architecture Overview
This document provides a high-level overview of the portfolio application architecture.
System Diagram

Core Components
Frontend (Next.js 15)
- App Router - File-based routing with React Server Components
- React 19 - Latest React features including Server Actions
- TailwindCSS - Utility-first styling
- Framer Motion - Animations and transitions
Backend (AWS Lambda)
- Lambda@Edge - Next.js SSR at edge locations
- Regional Lambda - Chat streaming with Function URLs
- API Routes - RESTful endpoints for data access
Data Layer
- DynamoDB - Blog posts, ISR cache, chat cost tracking
- S3 - Static assets, blog content, media files
- Secrets Manager - Runtime secrets (API keys, OAuth secrets)
- Upstash Redis - Rate limiting
Observability
- CloudWatch Metrics - OpenAI cost tracking
- CloudWatch Alarms - Budget alerts via SNS
- Structured Logging - Lambda log groups
Request Flow
Page Request
- User requests
/blog/my-post - CloudFront receives request
- Lambda@Edge executes SSR
- DynamoDB queried for post data
- React components render
- HTML returned through CloudFront
Chat Request
- User sends chat message
- CloudFront routes to chat Lambda
- Lambda validates request
- OpenAI API called with streaming
- Response streamed back through Function URL
Static Asset
- User requests
/_next/static/chunk.js - CloudFront checks cache
- If miss, fetches from S3
- Cached at edge for future requests
Monorepo Structure
/
├── src/ # Next.js application
│ ├── app/ # App Router routes
│ ├── components/ # React components
│ └── lib/ # Utilities
├── packages/ # Shared packages
│ ├── chat-* # Chat system packages
│ ├── github-data/ # GitHub integration
│ └── test-support/ # Testing utilities
├── infra/cdk/ # AWS infrastructure
└── generated/ # Preprocessed data
Key Design Decisions
OpenNext for AWS
Uses OpenNext to compile Next.js for AWS Lambda instead of Vercel:
- Full control over infrastructure
- Cost optimization
- Custom Lambda configurations
- ISR with DynamoDB/S3 cache
Lambda@Edge vs Regional
- Lambda@Edge: SSR pages for low latency
- Regional Lambda: Chat streaming (requires Function URL streaming)
Monorepo with pnpm
- Shared code between packages
- TypeScript source imports (no build step for most packages)
- Workspace protocol for internal dependencies
Related Documentation
- Infrastructure - AWS resources in detail
- OpenNext Configuration - OpenNext setup
- Packages - Monorepo package structure
