Tech Stack Architect
Purpose
Generate comprehensive technology stack selection and system architecture design from project requirements. Creates two foundational documents that guide implementation.
When to Use
- Starting a new project after PROJECT-OVERVIEW.md is created
- Re-architecting existing systems
- Technology evaluation and selection
- Architecture documentation needed
- User mentions "tech stack", "architecture", "system design"
Behavior
Phase 1: Technology Stack Selection
Read PROJECT-OVERVIEW.md for:
- Project goals and constraints
- Scale requirements (users, data, traffic)
- Team skills and preferences
- Budget and timeline
- Compliance requirements
Analyze requirements across 4 categories:
- Frontend (framework, state management, UI library)
- Backend (language, framework, API style)
- Database (RDBMS, NoSQL, caching, search)
- DevOps (hosting, CI/CD, monitoring, security)
Generate TECH-STACK.md with:
- Category tables: Technology | Rationale | Alternatives Considered
- Integration notes: How technologies work together
- Trade-offs: What you gain/lose with this stack
- Migration path: How to evolve the stack
- Team considerations: Learning curve, hiring, support
Phase 2: System Architecture Design
Design components:
- Client-side architecture
- API layer and services
- Data storage and caching
- Background jobs and queues
- External integrations
Define data flow:
- Request/response paths
- Authentication flow
- Data persistence patterns
- Event-driven flows (if applicable)
Generate ARCHITECTURE.md with:
- System Overview: High-level component diagram (C4 Context)
- Component Details: Responsibilities, interfaces, dependencies
- Data Flow Diagrams: Key user journeys with sequence diagrams
- Scalability Strategy: Horizontal scaling, caching, load balancing
- Security Architecture: Auth, encryption, OWASP considerations
- Mermaid Diagrams: C4, sequence, data flow, deployment
Output Style
- Use
table-based for technology comparisons
- Use
markdown-focused with mermaid diagrams for architecture
- Keep rationales concise (1-2 sentences per choice)
- Include visual diagrams for clarity
Output Files
1. project-management/TECH-STACK.md
# Technology Stack
## Summary
[2-3 sentence overview of the stack philosophy]
## Frontend Stack
| Technology | Choice | Rationale | Alternatives Considered |
|------------|--------|-----------|------------------------|
| Framework | React 18 | ... | Vue, Svelte, Angular |
| State | Zustand | ... | Redux, Jotai, Context |
| UI Library | Tailwind + shadcn/ui | ... | MUI, Chakra, custom |
| Build | Vite | ... | Webpack, Turbopack |
## Backend Stack
| Technology | Choice | Rationale | Alternatives Considered |
|------------|--------|-----------|------------------------|
| Language | Python 3.11 | ... | Node.js, Go, Rust |
| Framework | FastAPI | ... | Django, Flask, Express |
| API Style | REST + OpenAPI | ... | GraphQL, gRPC, tRPC |
## Database & Storage
| Technology | Choice | Rationale | Alternatives Considered |
|------------|--------|-----------|------------------------|
| Primary DB | PostgreSQL 15 | ... | MySQL, MongoDB, SQLite |
| Caching | Redis | ... | Memcached, Valkey |
| Search | ElasticSearch | ... | Algolia, Meilisearch |
| Object Storage | S3 | ... | MinIO, CloudFlare R2 |
## DevOps & Infrastructure
| Technology | Choice | Rationale | Alternatives Considered |
|------------|--------|-----------|------------------------|
| Hosting | AWS ECS Fargate | ... | k8s, VM, serverless |
| CI/CD | GitHub Actions | ... | GitLab CI, CircleCI |
| Monitoring | DataDog | ... | Grafana, New Relic |
| Secrets | AWS Secrets Manager | ... | Vault, Doppler |
## Integration Notes
- [How frontend talks to backend]
- [Database connection pooling strategy]
- [Caching layer integration]
- [CI/CD pipeline flow]
## Trade-offs
**Gains**: [What this stack provides]
**Costs**: [Complexity, vendor lock-in, learning curve]
## Migration Path
- Phase 1: [Initial minimal stack]
- Phase 2: [Add caching, search]
- Phase 3: [Scale horizontally]
## Team Considerations
- **Learning Curve**: [Estimate for team]
- **Hiring**: [Availability of talent]
- **Support**: [Community, docs, enterprise support]
2. project-management/ARCHITECTURE.md
# System Architecture
## Overview
[2-3 sentence description of the system]
## C4 Context Diagram
```mermaid
C4Context
title System Context for [Project Name]
Person(user, "User", "End user of the system")
System(app, "Application", "Main system")
System_Ext(auth, "Auth Provider", "OAuth2 provider")
System_Ext(payment, "Payment Gateway", "Stripe")
Rel(user, app, "Uses", "HTTPS")
Rel(app, auth, "Authenticates", "OAuth2")
Rel(app, payment, "Processes payments", "API")
Component Architecture
graph TB
Client[React Client]
API[FastAPI Backend]
DB[(PostgreSQL)]
Cache[(Redis)]
Queue[Job Queue]
Worker[Background Workers]
Client -->|HTTPS/JSON| API
API -->|SQL| DB
API -->|GET/SET| Cache
API -->|Enqueue| Queue
Queue -->|Process| Worker
Worker -->|Update| DB
Component Details
Client (React)
- Responsibilities: UI rendering, state management, client-side validation
- Key Libraries: React Router, Zustand, React Query
- Interfaces: REST API via fetch/axios
API (FastAPI)
- Responsibilities: Business logic, validation, auth, rate limiting
- Key Modules: auth, users, payments, notifications
- Interfaces: REST endpoints (OpenAPI), WebSocket (notifications)
Database (PostgreSQL)
- Responsibilities: Persistent data storage, relational integrity
- Schema: Users, sessions, transactions, audit logs
- Patterns: Repository pattern, connection pooling
Cache (Redis)
- Responsibilities: Session storage, rate limiting, job queue
- TTL Strategy: Sessions (24h), API cache (5m), rate limits (1h)
Background Workers
- Responsibilities: Email sending, report generation, cleanup jobs
- Queue: Redis-backed Celery/ARQ
- Monitoring: Dead letter queue, retry logic
Authentication Flow
sequenceDiagram
participant User
participant Client
participant API
participant Auth0
participant DB
User->>Client: Click "Login"
Client->>Auth0: Redirect to OAuth2
Auth0->>Client: Return auth code
Client->>API: Exchange code for token
API->>Auth0: Validate code
Auth0->>API: User profile
API->>DB: Create/update user
API->>Client: Return JWT token
Client->>Client: Store token (httpOnly cookie)
Data Flow: User Registration
sequenceDiagram
participant Client
participant API
participant DB
participant Queue
participant Worker
participant Email
Client->>API: POST /api/register
API->>API: Validate input
API->>DB: Create user (inactive)
API->>Queue: Enqueue welcome email
API->>Client: 201 Created
Queue->>Worker: Process email job
Worker->>Email: Send welcome email
Worker->>DB: Log email sent
Scalability Strategy
Horizontal Scaling
- API: Stateless containers (2-10 instances behind ALB)
- Database: Read replicas for reporting queries
- Cache: Redis Cluster (3+ nodes)
- Workers: Auto-scale based on queue depth
Caching Strategy
- API Responses: Cache GET endpoints (5m TTL)
- Database Queries: Query result cache in Redis
- Static Assets: CDN (CloudFront) with edge caching
Load Balancing
- Application: AWS ALB with health checks
- Database: pgpool for read/write splitting
- Geographic: Multi-region deployment (future)
Security Architecture
Authentication & Authorization
- Strategy: OAuth2 + JWT tokens (15m access, 7d refresh)
- Storage: httpOnly cookies for web, secure storage for mobile
- Rotation: Automatic token refresh
Data Protection
- At Rest: PostgreSQL encryption (AWS RDS)
- In Transit: TLS 1.3 for all connections
- Secrets: AWS Secrets Manager, rotated monthly
OWASP Top 10 Mitigations
- Injection: Parameterized queries (SQLAlchemy ORM)
- Auth: JWT validation, session management
- XSS: Content Security Policy, input sanitization
- CSRF: SameSite cookies, CSRF tokens
- Rate Limiting: Redis-backed (100 req/min per IP)
Network Security
- VPC: Private subnets for DB/workers
- Security Groups: Least privilege access
- WAF: CloudFront WAF rules
Deployment Architecture
graph TB
subgraph "Public Subnet"
ALB[Application Load Balancer]
end
subgraph "Private Subnet - App Tier"
API1[API Container 1]
API2[API Container 2]
Worker1[Worker Container]
end
subgraph "Private Subnet - Data Tier"
DB[(RDS PostgreSQL)]
Cache[(ElastiCache Redis)]
end
Internet((Internet)) --> ALB
ALB --> API1
ALB --> API2
API1 --> DB
API2 --> DB
API1 --> Cache
API2 --> Cache
Worker1 --> DB
Worker1 --> Cache
Monitoring & Observability
Metrics:
- API latency (p50, p95, p99)
- Error rates by endpoint
- Database connection pool usage
- Cache hit/miss ratios
Logging:
- Structured JSON logs (ECS logs to CloudWatch)
- Request ID tracing across services
- Error tracking (Sentry)
Alerting:
- API error rate >1%
- Database connections >80%
- Job queue depth >1000
Future Considerations
Phase 2 Enhancements:
- GraphQL API option
- WebSocket real-time updates
- ElasticSearch for full-text search
Phase 3 Scale:
- Multi-region deployment
- Event-driven microservices
- CQRS for read-heavy workloads
## Guardrails
- Keep technology choices pragmatic (avoid hype-driven development)
- Consider team skills when selecting stack
- Prefer managed services over self-hosted for DevOps
- Include alternatives to show deliberate choice
- Use mermaid for all diagrams (portable, version-controllable)
- Keep each document under 400 lines
- Link to official docs for each technology
## Integration
- Run after PROJECT-OVERVIEW.md is created
- Feed into `/lazy plan` for user story creation
- Reference during `/lazy code` for implementation consistency
- Update during `/lazy review` if architecture evolves
## Example Prompt
> Design the tech stack and architecture for this project
## Validation Checklist
- [ ] TECH-STACK.md has all 4 categories (Frontend, Backend, Database, DevOps)
- [ ] Each technology has rationale and alternatives
- [ ] ARCHITECTURE.md has system overview + 3+ mermaid diagrams
- [ ] Authentication and data flow are documented
- [ ] Scalability and security sections are complete
- [ ] Trade-offs and migration path are clear
1---2name: tech-stack-architect3description: Design complete technology stack and system architecture from project requirements - generates TECH-STACK.md with frontend/backend/database/DevOps choices plus rationale, and ARCHITECTURE.md with components, data flow, and mermaid diagrams4---5
6# Tech Stack Architect
7
8## Purpose
9Generate comprehensive technology stack selection and system architecture design from project requirements. Creates two foundational documents that guide implementation.
10
11## When to Use
12- Starting a new project after PROJECT-OVERVIEW.md is created
13- Re-architecting existing systems
14- Technology evaluation and selection
15- Architecture documentation needed
16- User mentions "tech stack", "architecture", "system design"
17
18## Behavior
19
20### Phase 1: Technology Stack Selection
21
221. **Read PROJECT-OVERVIEW.md** for:
23 - Project goals and constraints
24 - Scale requirements (users, data, traffic)
25 - Team skills and preferences
26 - Budget and timeline
27 - Compliance requirements
28
292. **Analyze requirements** across 4 categories:
30 - Frontend (framework, state management, UI library)
31 - Backend (language, framework, API style)
32 - Database (RDBMS, NoSQL, caching, search)
33 - DevOps (hosting, CI/CD, monitoring, security)
34
353. **Generate TECH-STACK.md** with:
36 - **Category tables**: Technology | Rationale | Alternatives Considered
37 - **Integration notes**: How technologies work together
38 - **Trade-offs**: What you gain/lose with this stack
39 - **Migration path**: How to evolve the stack
40 - **Team considerations**: Learning curve, hiring, support
41
42### Phase 2: System Architecture Design
43
441. **Design components**:
45 - Client-side architecture
46 - API layer and services
47 - Data storage and caching
48 - Background jobs and queues
49 - External integrations
50
512. **Define data flow**:
52 - Request/response paths
53 - Authentication flow
54 - Data persistence patterns
55 - Event-driven flows (if applicable)
56
573. **Generate ARCHITECTURE.md** with:
58 - **System Overview**: High-level component diagram (C4 Context)
59 - **Component Details**: Responsibilities, interfaces, dependencies
60 - **Data Flow Diagrams**: Key user journeys with sequence diagrams
61 - **Scalability Strategy**: Horizontal scaling, caching, load balancing
62 - **Security Architecture**: Auth, encryption, OWASP considerations
63 - **Mermaid Diagrams**: C4, sequence, data flow, deployment
64
65## Output Style
66- Use `table-based` for technology comparisons
67- Use `markdown-focused` with mermaid diagrams for architecture
68- Keep rationales concise (1-2 sentences per choice)
69- Include visual diagrams for clarity
70
71## Output Files
72
73### 1. project-management/TECH-STACK.md
74```markdown
75# Technology Stack
76
77## Summary
78[2-3 sentence overview of the stack philosophy]
79
80## Frontend Stack
81
82| Technology | Choice | Rationale | Alternatives Considered |
83|------------|--------|-----------|------------------------|
84| Framework | React 18 | ... | Vue, Svelte, Angular |
85| State | Zustand | ... | Redux, Jotai, Context |
86| UI Library | Tailwind + shadcn/ui | ... | MUI, Chakra, custom |
87| Build | Vite | ... | Webpack, Turbopack |
88
89## Backend Stack
90
91| Technology | Choice | Rationale | Alternatives Considered |
92|------------|--------|-----------|------------------------|
93| Language | Python 3.11 | ... | Node.js, Go, Rust |
94| Framework | FastAPI | ... | Django, Flask, Express |
95| API Style | REST + OpenAPI | ... | GraphQL, gRPC, tRPC |
96
97## Database & Storage
98
99| Technology | Choice | Rationale | Alternatives Considered |
100|------------|--------|-----------|------------------------|
101| Primary DB | PostgreSQL 15 | ... | MySQL, MongoDB, SQLite |
102| Caching | Redis | ... | Memcached, Valkey |
103| Search | ElasticSearch | ... | Algolia, Meilisearch |
104| Object Storage | S3 | ... | MinIO, CloudFlare R2 |
105
106## DevOps & Infrastructure
107
108| Technology | Choice | Rationale | Alternatives Considered |
109|------------|--------|-----------|------------------------|
110| Hosting | AWS ECS Fargate | ... | k8s, VM, serverless |
111| CI/CD | GitHub Actions | ... | GitLab CI, CircleCI |
112| Monitoring | DataDog | ... | Grafana, New Relic |
113| Secrets | AWS Secrets Manager | ... | Vault, Doppler |
114
115## Integration Notes
116- [How frontend talks to backend]
117- [Database connection pooling strategy]
118- [Caching layer integration]
119- [CI/CD pipeline flow]
120
121## Trade-offs
122**Gains**: [What this stack provides]
123**Costs**: [Complexity, vendor lock-in, learning curve]
124
125## Migration Path
126- Phase 1: [Initial minimal stack]
127- Phase 2: [Add caching, search]
128- Phase 3: [Scale horizontally]
129
130## Team Considerations
131- **Learning Curve**: [Estimate for team]
132- **Hiring**: [Availability of talent]
133- **Support**: [Community, docs, enterprise support]
134```
135
136### 2. project-management/ARCHITECTURE.md
137```markdown
138# System Architecture
139
140## Overview
141[2-3 sentence description of the system]
142
143## C4 Context Diagram
144```mermaid
145C4Context
146 title System Context for [Project Name]
147
148 Person(user, "User", "End user of the system")
149 System(app, "Application", "Main system")
150 System_Ext(auth, "Auth Provider", "OAuth2 provider")
151 System_Ext(payment, "Payment Gateway", "Stripe")
152
153 Rel(user, app, "Uses", "HTTPS")
154 Rel(app, auth, "Authenticates", "OAuth2")
155 Rel(app, payment, "Processes payments", "API")
156```
157
158## Component Architecture
159```mermaid
160graph TB
161 Client[React Client]
162 API[FastAPI Backend]
163 DB[(PostgreSQL)]
164 Cache[(Redis)]
165 Queue[Job Queue]
166 Worker[Background Workers]
167
168 Client -->|HTTPS/JSON| API
169 API -->|SQL| DB
170 API -->|GET/SET| Cache
171 API -->|Enqueue| Queue
172 Queue -->|Process| Worker
173 Worker -->|Update| DB
174```
175
176### Component Details
177
178**Client (React)**
179- **Responsibilities**: UI rendering, state management, client-side validation
180- **Key Libraries**: React Router, Zustand, React Query
181- **Interfaces**: REST API via fetch/axios
182
183**API (FastAPI)**
184- **Responsibilities**: Business logic, validation, auth, rate limiting
185- **Key Modules**: auth, users, payments, notifications
186- **Interfaces**: REST endpoints (OpenAPI), WebSocket (notifications)
187
188**Database (PostgreSQL)**
189- **Responsibilities**: Persistent data storage, relational integrity
190- **Schema**: Users, sessions, transactions, audit logs
191- **Patterns**: Repository pattern, connection pooling
192
193**Cache (Redis)**
194- **Responsibilities**: Session storage, rate limiting, job queue
195- **TTL Strategy**: Sessions (24h), API cache (5m), rate limits (1h)
196
197**Background Workers**
198- **Responsibilities**: Email sending, report generation, cleanup jobs
199- **Queue**: Redis-backed Celery/ARQ
200- **Monitoring**: Dead letter queue, retry logic
201
202## Authentication Flow
203```mermaid
204sequenceDiagram
205 participant User
206 participant Client
207 participant API
208 participant Auth0
209 participant DB
210
211 User->>Client: Click "Login"
212 Client->>Auth0: Redirect to OAuth2
213 Auth0->>Client: Return auth code
214 Client->>API: Exchange code for token
215 API->>Auth0: Validate code
216 Auth0->>API: User profile
217 API->>DB: Create/update user
218 API->>Client: Return JWT token
219 Client->>Client: Store token (httpOnly cookie)
220```
221
222## Data Flow: User Registration
223```mermaid
224sequenceDiagram
225 participant Client
226 participant API
227 participant DB
228 participant Queue
229 participant Worker
230 participant Email
231
232 Client->>API: POST /api/register
233 API->>API: Validate input
234 API->>DB: Create user (inactive)
235 API->>Queue: Enqueue welcome email
236 API->>Client: 201 Created
237 Queue->>Worker: Process email job
238 Worker->>Email: Send welcome email
239 Worker->>DB: Log email sent
240```
241
242## Scalability Strategy
243
244### Horizontal Scaling
245- **API**: Stateless containers (2-10 instances behind ALB)
246- **Database**: Read replicas for reporting queries
247- **Cache**: Redis Cluster (3+ nodes)
248- **Workers**: Auto-scale based on queue depth
249
250### Caching Strategy
251- **API Responses**: Cache GET endpoints (5m TTL)
252- **Database Queries**: Query result cache in Redis
253- **Static Assets**: CDN (CloudFront) with edge caching
254
255### Load Balancing
256- **Application**: AWS ALB with health checks
257- **Database**: pgpool for read/write splitting
258- **Geographic**: Multi-region deployment (future)
259
260## Security Architecture
261
262### Authentication & Authorization
263- **Strategy**: OAuth2 + JWT tokens (15m access, 7d refresh)
264- **Storage**: httpOnly cookies for web, secure storage for mobile
265- **Rotation**: Automatic token refresh
266
267### Data Protection
268- **At Rest**: PostgreSQL encryption (AWS RDS)
269- **In Transit**: TLS 1.3 for all connections
270- **Secrets**: AWS Secrets Manager, rotated monthly
271
272### OWASP Top 10 Mitigations
273- **Injection**: Parameterized queries (SQLAlchemy ORM)
274- **Auth**: JWT validation, session management
275- **XSS**: Content Security Policy, input sanitization
276- **CSRF**: SameSite cookies, CSRF tokens
277- **Rate Limiting**: Redis-backed (100 req/min per IP)
278
279### Network Security
280- **VPC**: Private subnets for DB/workers
281- **Security Groups**: Least privilege access
282- **WAF**: CloudFront WAF rules
283
284## Deployment Architecture
285```mermaid
286graph TB
287 subgraph "Public Subnet"
288 ALB[Application Load Balancer]
289 end
290
291 subgraph "Private Subnet - App Tier"
292 API1[API Container 1]
293 API2[API Container 2]
294 Worker1[Worker Container]
295 end
296
297 subgraph "Private Subnet - Data Tier"
298 DB[(RDS PostgreSQL)]
299 Cache[(ElastiCache Redis)]
300 end
301
302 Internet((Internet)) --> ALB
303 ALB --> API1
304 ALB --> API2
305 API1 --> DB
306 API2 --> DB
307 API1 --> Cache
308 API2 --> Cache
309 Worker1 --> DB
310 Worker1 --> Cache
311```
312
313## Monitoring & Observability
314
315**Metrics**:
316- API latency (p50, p95, p99)
317- Error rates by endpoint
318- Database connection pool usage
319- Cache hit/miss ratios
320
321**Logging**:
322- Structured JSON logs (ECS logs to CloudWatch)
323- Request ID tracing across services
324- Error tracking (Sentry)
325
326**Alerting**:
327- API error rate >1%
328- Database connections >80%
329- Job queue depth >1000
330
331## Future Considerations
332
333**Phase 2 Enhancements**:
334- GraphQL API option
335- WebSocket real-time updates
336- ElasticSearch for full-text search
337
338**Phase 3 Scale**:
339- Multi-region deployment
340- Event-driven microservices
341- CQRS for read-heavy workloads
342```
343
344## Guardrails
345- Keep technology choices pragmatic (avoid hype-driven development)
346- Consider team skills when selecting stack
347- Prefer managed services over self-hosted for DevOps
348- Include alternatives to show deliberate choice
349- Use mermaid for all diagrams (portable, version-controllable)
350- Keep each document under 400 lines
351- Link to official docs for each technology
352
353## Integration
354- Run after PROJECT-OVERVIEW.md is created
355- Feed into `/lazy plan` for user story creation
356- Reference during `/lazy code` for implementation consistency
357- Update during `/lazy review` if architecture evolves
358
359## Example Prompt
360> Design the tech stack and architecture for this project
361
362## Validation Checklist
363- [ ] TECH-STACK.md has all 4 categories (Frontend, Backend, Database, DevOps)
364- [ ] Each technology has rationale and alternatives
365- [ ] ARCHITECTURE.md has system overview + 3+ mermaid diagrams
366- [ ] Authentication and data flow are documented
367- [ ] Scalability and security sections are complete
368- [ ] Trade-offs and migration path are clear