AI Builder - System Architecture
This skill creates/updates the system architecture documentation defining the system structure, major components, data flow, and deployment boundaries without specifying specific frameworks or technologies.
When to Use This Skill
- User asks to "design architecture" or "create system design"
- User requests to start Stage 6 or the next stage after UX design
- User wants to define system components and their relationships
- User wants to understand data flow and system boundaries
- User needs to plan deployment architecture
Prerequisites
This skill requires 05-ux to be completed. The architecture will implement the UX design and functional requirements with a clear system structure.
Your Roles in This Skill
- Tech Manager (Architect): Lead architecture design with system overview and component definitions. Review PRD and UX design to understand requirements. Create architecture diagrams showing component relationships. Define data structures and data flow patterns. Establish architectural principles and patterns.
- Backend Architect: Design backend system components, API structure, and data models. Define service boundaries and responsibilities. Plan database architecture and data flow. Consider scalability and performance requirements.
- Frontend Architect: Design frontend architecture and component structure. Define state management approach. Plan client-side data flow and API integration patterns.
- AI Engineer: Design AI/ML model architecture and integration patterns. Define prompt engineering strategies and LLM integration. Plan vector database and embeddings architecture. Design model monitoring and evaluation pipelines. Consider AI costs, latency, and fallback strategies. Plan content generation and moderation systems.
- Content Moderator: Design content moderation architecture for AI-generated content. Define moderation workflows and automated filtering systems. Plan human-in-the-loop review processes. Design content safety and compliance systems. Consider scalability of moderation infrastructure.
- DevOps Engineer: Review architecture for deployment feasibility. Provide input on deployment boundaries and cloud architecture. Consider monitoring, logging, and operational aspects.
Role Communication
As an expert in your assigned roles, you must announce your actions before performing them using the following format:
As a {Role} [and {Role}, ...], I will {action description}
This communication pattern ensures transparency and allows for human-in-the-loop oversight at key decision points.
Instructions
Follow these steps in order:
Step 0: Verify Prerequisites and Gather Context
Check if 05-ux/ folder exists (mandatory):
- If NOT found: Inform user they need to create UX design first, then STOP
- If found: Read all files to understand:
- User flows and interactions
- Mockup structure (if UI-based app)
- Screen navigation patterns
Check if 04-prd/ folder exists (mandatory):
- If NOT found: Inform user they need PRD first, then STOP
- If found: Read to understand:
- Functional requirements
- Non-functional requirements (performance, security, scalability)
- Feature list and priorities
Check if 00-init-ideas/ folder exists (recommended):
- If found: Read to understand all files
Check if 03-mvp/ folder exists (recommended):
- If found: Read to understand:
- MVP scope (what to prioritize in architecture)
- Success metrics (inform performance targets)
Check if this stage should be skipped:
- Check if
06-architecture/SKIP.md exists
- If SKIP.md exists:
- Read SKIP.md to understand why this stage was skipped
- Inform the user: "Stage 6 (architecture) is marked as SKIP because [reason from SKIP.md]"
- Ask the user: "Would you like to proceed to the next stage (tech-specs)?"
- If user says yes:
- Exit this skill and inform them to run the next stage skill
- If user says no:
- Ask if they want to proceed with architecture anyway
- If yes, delete SKIP.md and continue with this skill
- If no, exit the skill
Check if 06-architecture/ folder exists:
- If exists: Read all existing files to understand current architecture state
- If NOT exists: Will create new structure
If README.md exists: Check whether it requires diagrams. If it does,
follow dev-swarm/docs/mermaid-diagram-guide.md and use the
dev-swarm-mermaid skill to render outputs.
Proceed to Step 1 with gathered context
Step 1: Refine Design Requirements in README and Get Approval
CRITICAL: Create/update README.md first based on previous stage results, get user approval, then create other docs.
Analyze information from previous stages:
- Read
05-ux/ to understand user flows and UI structure
- Read
04-prd/ to understand functional and non-functional requirements
- Read
03-mvp/ (if exists) to understand what to prioritize
- Consider cost-budget constraints for this stage
Create or update 06-architecture/README.md with refined requirements:
- List deliverables explicitly in README (typical: system-overview.md, architecture-diagram.md, data-flow.md, deployment-boundaries.md)
- Stage overview and objectives (based on previous stage context)
- Owners: Tech Manager (lead), Backend Architect, Frontend Architect, AI Engineer, Content Moderator, DevOps Engineer
- Diagrams (if required by project init):
- Reference
dev-swarm/docs/mermaid-diagram-guide.md
- Include
diagram/ deliverables when needed
- What architecture will include:
- System components and their responsibilities
- Architecture diagrams (high-level + detail)
- Data flow for critical user journeys
- Deployment boundaries and scaling strategy
- Methodology:
- How components will be defined (from PRD requirements)
- Diagram approach (Mermaid for all diagrams)
- Deliverables planned:
- List of files that will be created (system-overview.md, architecture-diagram.md, etc.)
- Budget allocation for this stage (from cost-budget.md)
- Status: In Progress (update to "Completed" after implementation)
Present README to user:
- Show the architecture approach and what will be designed
- Show what documentation files will be created
- Explain how it aligns with previous stages
- Ask: "Does this architecture plan look good? Should I proceed with designing system architecture?"
Wait for user approval:
- If user says yes: Proceed to Step 2
- If user says no:
- Ask what needs to be changed
- Update README based on feedback
- Ask for approval again
Step 2: Create/Update Architecture Structure
Only after user approves the README:
Create files as specified in the approved README.md:
IMPORTANT: The file structure below is a SAMPLE only. The actual files you create must follow what was approved in the README.md in Step 1.
Typical structure (example):
06-architecture/
├── README.md (already created and approved in Step 1)
├── system-overview.md (if specified in README)
├── architecture-diagram.md (if specified in README)
├── data-flow.md (if specified in README)
└── deployment-boundaries.md (if specified in README)
Create only the files listed in the README's "Deliverables planned" section.
Step 3: Create/Update Architecture Documentation
IMPORTANT: Only create architecture documentation after README is approved in Step 1.
NOTE: The content structure below provides GUIDELINES for typical architecture documentation. Adapt based on the approved README and project needs.
If files don't exist: Create new comprehensive architecture documents.
06-architecture/README.md:
- Stage overview and objectives
- Specify the owners: Tech Manager (lead), Backend Architect, Frontend Architect, DevOps Engineer
- Summary of architectural approach and principles
- Links to all architecture documentation files
- Key architectural decisions and rationale
system-overview.md:
Define the major system components and their responsibilities:
Architectural Principles:
- List the guiding principles for this architecture
- Examples:
- Separation of concerns
- Scalability and horizontal scaling
- Security by design
- Fail-fast and graceful degradation
- Stateless services where possible
- API-first approach
- Mobile-first or responsive design
System Components:
Format for each component:
### Component: [Component Name]
**Type:** Frontend / Backend / Database / External Service / Infrastructure
**Responsibility:**
- What this component does
- What problems it solves
- What it is NOT responsible for
**Key Capabilities:**
- Capability 1
- Capability 2
- Capability 3
**Interfaces:**
- Inputs: What data/requests it receives
- Outputs: What data/responses it produces
- APIs: What APIs it exposes (if any)
**Dependencies:**
- What other components does this depend on?
- What external services does this use?
**Data Storage:**
- What data does this component store?
- Where is it stored?
**Scalability:**
- Can this scale horizontally or vertically?
- What are the scaling constraints?
Component Categories:
Frontend Components:
- Web Application (if applicable)
- Mobile Application (if applicable)
- Desktop Application (if applicable)
- Admin Dashboard (if needed)
Backend Components:
- API Gateway / Backend for Frontend (BFF)
- Core Application Services
- Authentication Service
- Business Logic Services
- Background Job Processors
- Notification Service
- File Storage Service
Data Components:
- Primary Database
- Cache Layer
- Search Index (if needed)
- Object Storage (for files/media)
- Message Queue (if needed)
External Services:
- Third-party APIs (payment, email, SMS, etc.)
- Authentication providers (OAuth, SSO)
- CDN services
- Monitoring and logging services
Component Interaction Patterns:
- Request-Response (synchronous)
- Event-Driven (asynchronous)
- Pub-Sub messaging
- Polling vs. webhooks
- WebSocket connections (if real-time features)
architecture-diagram.md:
Create visual diagrams showing system architecture:
High-Level Architecture Diagram:
Use Mermaid to create a diagram showing all major components:
graph TB
subgraph "Client Layer"
WebApp[Web Application]
MobileApp[Mobile Application]
end
subgraph "API Layer"
APIGateway[API Gateway]
Auth[Auth Service]
end
subgraph "Application Layer"
CoreAPI[Core API Service]
BgJobs[Background Jobs]
Notifications[Notification Service]
end
subgraph "Data Layer"
DB[(Primary Database)]
Cache[(Cache)]
Storage[(Object Storage)]
end
subgraph "External Services"
Email[Email Service]
Payment[Payment Service]
end
WebApp --> APIGateway
MobileApp --> APIGateway
APIGateway --> Auth
APIGateway --> CoreAPI
CoreAPI --> DB
CoreAPI --> Cache
CoreAPI --> BgJobs
BgJobs --> Notifications
Notifications --> Email
CoreAPI --> Payment
CoreAPI --> Storage
Component Detail Diagrams:
Create additional diagrams for complex subsystems:
- Authentication flow diagram
- Payment processing flow
- File upload/download flow
- Real-time messaging flow (if applicable)
Database Schema Diagram (High-Level):
Show major entities and relationships:
erDiagram
User ||--o{ Post : creates
User ||--o{ Comment : writes
Post ||--o{ Comment : has
User {
uuid id
string email
string name
}
Post {
uuid id
uuid user_id
string title
text content
}
Comment {
uuid id
uuid user_id
uuid post_id
text content
}
data-flow.md:
Document how data flows through the system:
Request Flow (Frontend to Backend):
For each major user flow from UX design:
Format:
### Flow: [User Flow Name]
**Trigger:** User action that initiates the flow (from 05-ux/user-flows.md)
**Step-by-Step Data Flow:**
1. **User Action:** User clicks/submits/interacts
- Component: [Frontend Component]
- Data: [What data is involved]
2. **API Request:**
- Component: Frontend → API Gateway
- Method: GET/POST/PUT/DELETE
- Endpoint: /api/resource
- Request Data: { ... }
- Headers: [Authentication, Content-Type, etc.]
3. **Authentication/Authorization:**
- Component: API Gateway → Auth Service
- Validation: [What is checked]
- Result: [Pass/Fail action]
4. **Business Logic Processing:**
- Component: Core API Service
- Processing: [What happens to the data]
- Validation: [Business rules applied]
- Transformations: [Data transformations]
5. **Database Operations:**
- Component: Core API → Database
- Operation: SELECT/INSERT/UPDATE/DELETE
- Tables: [Which tables affected]
- Transactions: [If transaction needed]
6. **External Service Calls (if any):**
- Component: Core API → External Service
- Service: [Which external service]
- Purpose: [Why calling it]
- Fallback: [What if service fails]
7. **Response Construction:**
- Component: Core API
- Data: [Response data structure]
- Status: [HTTP status code]
8. **Response to Frontend:**
- Component: API Gateway → Frontend
- Data: { ... }
- Frontend Action: [How UI updates]
**Error Handling:**
- What happens if step X fails?
- Rollback strategy
- Error messages to user
**Caching Strategy:**
- What data is cached?
- Where is it cached?
- Cache invalidation rules
**Performance Considerations:**
- Expected latency
- Database query optimization
- N+1 query prevention
Data Flow Categories:
- Read Flows: Fetching and displaying data
- Write Flows: Creating and updating data
- Delete Flows: Removing data
- File Upload Flows: Handling file uploads
- Background Processing Flows: Async jobs and batch operations
- Real-time Flows: WebSocket or server-sent events (if applicable)
Data Transformation Pipeline:
- Input validation and sanitization
- Data normalization
- Business logic application
- Response formatting
- Error formatting
deployment-boundaries.md:
Define what runs where and security/trust boundaries:
Deployment Environments:
Development Environment:
- Where: Local machine / Dev cloud
- Purpose: Development and testing
- Data: Fake/seed data
- Access: Developers only
Staging Environment:
- Where: Cloud (same region as production)
- Purpose: Pre-production testing and QA
- Data: Production-like data (anonymized)
- Access: Internal team + selected beta testers
Production Environment:
- Where: Cloud (specify regions if multi-region)
- Purpose: Live user-facing environment
- Data: Real user data
- Access: Public users (authenticated)
What Runs Where:
Client-Side (User's Device):
- Web application (browser)
- Mobile application (iOS/Android)
- Desktop application (if applicable)
- Client-side validation
- UI rendering and interaction
Edge/CDN:
- Static assets (HTML, CSS, JS, images)
- Cached API responses (if applicable)
- DDoS protection
- SSL/TLS termination
Cloud - Application Layer:
- API Gateway
- Application servers
- Authentication services
- Background job workers
- Notification services
Cloud - Data Layer:
- Primary database
- Cache servers (Redis/Memcached)
- Search indexes (if applicable)
- Object storage (S3/CloudStorage)
- Message queues (if applicable)
Third-Party Services:
- Email delivery (SendGrid, AWS SES, etc.)
- Payment processing (Stripe, PayPal, etc.)
- SMS delivery (Twilio, etc.)
- Analytics (Google Analytics, Mixpanel, etc.)
- Error tracking (Sentry, etc.)
- Monitoring (Datadog, New Relic, etc.)
Trust Boundaries:
Boundary 1: User Device ↔ Cloud:
- Trust Level: Untrusted to Trusted
- Security:
- HTTPS/TLS encryption
- Authentication required
- Input validation and sanitization
- CSRF protection
- Rate limiting
- Data Flow: User actions → API requests
Boundary 2: Public API ↔ Internal Services:
- Trust Level: Partially Trusted to Trusted
- Security:
- API authentication (JWT, OAuth)
- Authorization checks
- Service-to-service authentication
- Network segmentation (VPC, private subnets)
- Data Flow: API Gateway → Internal services
Boundary 3: Application ↔ Database:
- Trust Level: Trusted to Highly Trusted
- Security:
- Database credentials in secrets manager
- Encrypted connections (SSL/TLS)
- Principle of least privilege
- Network isolation
- Data Flow: Application services → Database
Boundary 4: Application ↔ External Services:
- Trust Level: Trusted to Untrusted
- Security:
- API keys in secrets manager
- HTTPS only
- Timeout and retry logic
- Fallback mechanisms
- Circuit breaker pattern
- Data Flow: Application → Third-party APIs
Scaling Assumptions:
Vertical Scaling (Scale Up):
- Which components scale vertically?
- Maximum instance size limits
- When to switch to horizontal scaling
Horizontal Scaling (Scale Out):
- Which components scale horizontally?
- Load balancing strategy
- Stateless service requirements
- Session management approach
Auto-Scaling Triggers:
- CPU utilization thresholds
- Memory utilization thresholds
- Request rate thresholds
- Queue depth thresholds
Database Scaling:
- Read replicas for read-heavy workloads
- Sharding strategy (if applicable)
- Caching to reduce database load
- Connection pooling
CDN and Caching:
- Static asset caching
- API response caching
- Cache invalidation strategy
- Edge caching locations
High Availability & Fault Tolerance:
- Multi-AZ deployment (if cloud)
- Database failover strategy
- Service redundancy
- Load balancer health checks
- Circuit breaker for external services
- Graceful degradation strategies
Geographic Distribution (if applicable):
- Multi-region deployment
- Data residency requirements
- Latency optimization
- CDN edge locations
Step 4: Ensure Alignment
Make sure architecture aligns with:
- Non-functional requirements from 04-prd/non-functional-requirements.md
- Functional requirements from 04-prd/functional-requirements.md
- User flows from 05-ux/user-flows.md
- MVP scope from 03-mvp/ (architecture should support MVP first, then scale)
Verify that:
- All functional requirements can be implemented in this architecture
- Performance targets are achievable
- Security requirements are addressed
- Scalability needs are met
- Deployment is feasible
Step 5: Final User Review
Inform user that architecture is complete
Update README.md:
- Change Status from "In Progress" to "Completed"
- Add a Summary section with key insights (2-3 paragraphs)
- Add a Created Files section listing all created files
Present completed work to user:
- Walk through the architecture diagrams
- Explain major components and their responsibilities
- Show data flow for critical user journeys
- Explain deployment boundaries and security
Highlight key insights:
- Number of major components
- Key architectural patterns used
- Scalability approach
- Security boundaries
- Cloud vs. local deployment split
Ask questions:
- Does the architecture make sense?
- Are there any components missing?
- Any concerns about scalability or security?
- Ready to proceed to next stage (tech specs)?
Make adjustments based on user feedback if needed
Step 6: Commit to Git (if user confirms)
- If user confirms architecture is complete:
- Ask if they want to commit to git
- If user wants to commit:
- Stage all changes in
06-architecture/
- Commit with message: "Design system architecture and deployment (Stage 6)"
Expected Project Structure
project-root/
├── 00-init-ideas/
│ └── [existing files]
├── 01-market-research/ (optional)
│ └── [existing files if present]
├── 02-personas/
│ └── [existing files]
├── 03-mvp/
│ └── [existing files]
├── 04-prd/
│ └── [existing files]
├── 05-ux/
│ └── [existing files]
└── 06-architecture/
├── README.md (with owners and summary)
├── system-overview.md (components + responsibilities)
├── architecture-diagram.md (Mermaid diagrams)
├── data-flow.md (request/data flow details)
└── deployment-boundaries.md (what runs where, trust boundaries, scaling)
Key Architecture Principles
- Structure, Not Frameworks: Define system shape without specifying technologies
- Component Clarity: Each component has clear, single responsibility
- Separation of Concerns: Frontend, backend, data, external services clearly separated
- Scalability by Design: Consider scaling from the start
- Security Boundaries: Clear trust boundaries and security controls
- Fail Gracefully: Plan for failures and degradation
- Data Flow Transparency: Clear understanding of how data moves
- Deployment Feasibility: Can actually be deployed and operated
Architecture Best Practices
- Start Simple: MVP architecture should be simple, add complexity later
- Use Diagrams: Mermaid diagrams make architecture visual and clear
- Document Decisions: Explain why you chose this architecture
- Consider Trade-offs: No architecture is perfect, document trade-offs
- Plan for Change: Make architecture flexible for future needs
- Security First: Build security into architecture, not bolt on later
- Performance Aware: Consider performance implications of design decisions
- Operational Thinking: Consider monitoring, logging, debugging
Deliverables
By the end of this stage, you should have:
- Complete system overview with component definitions (5-15 major components)
- Architecture diagrams using Mermaid (high-level + detail diagrams)
- Detailed data flow documentation for critical user journeys
- Deployment boundaries and security trust zones defined
- Scaling strategy and assumptions documented
- Foundation for tech stack selection (next stage)
- Clear understanding of how system will be structured
1---2name: dev-swarm-architecture3description: Design system architecture including components, data flow, and deployment boundaries. Use when user asks to design architecture, create architecture diagrams, or start Stage 6 after UX design.4---5
6# AI Builder - System Architecture
7
8This skill creates/updates the system architecture documentation defining the system structure, major components, data flow, and deployment boundaries without specifying specific frameworks or technologies.
9
10## When to Use This Skill
11
12- User asks to "design architecture" or "create system design"
13- User requests to start Stage 6 or the next stage after UX design
14- User wants to define system components and their relationships
15- User wants to understand data flow and system boundaries
16- User needs to plan deployment architecture
17
18## Prerequisites
19
20This skill requires **05-ux** to be completed. The architecture will implement the UX design and functional requirements with a clear system structure.
21
22## Your Roles in This Skill
23
24- **Tech Manager (Architect)**: Lead architecture design with system overview and component definitions. Review PRD and UX design to understand requirements. Create architecture diagrams showing component relationships. Define data structures and data flow patterns. Establish architectural principles and patterns.
25- **Backend Architect**: Design backend system components, API structure, and data models. Define service boundaries and responsibilities. Plan database architecture and data flow. Consider scalability and performance requirements.
26- **Frontend Architect**: Design frontend architecture and component structure. Define state management approach. Plan client-side data flow and API integration patterns.
27- **AI Engineer**: Design AI/ML model architecture and integration patterns. Define prompt engineering strategies and LLM integration. Plan vector database and embeddings architecture. Design model monitoring and evaluation pipelines. Consider AI costs, latency, and fallback strategies. Plan content generation and moderation systems.
28- **Content Moderator**: Design content moderation architecture for AI-generated content. Define moderation workflows and automated filtering systems. Plan human-in-the-loop review processes. Design content safety and compliance systems. Consider scalability of moderation infrastructure.
29- **DevOps Engineer**: Review architecture for deployment feasibility. Provide input on deployment boundaries and cloud architecture. Consider monitoring, logging, and operational aspects.
30
31## Role Communication
32
33As an expert in your assigned roles, you must announce your actions before performing them using the following format:
34
35As a {Role} [and {Role}, ...], I will {action description}
36
37This communication pattern ensures transparency and allows for human-in-the-loop oversight at key decision points.
38## Instructions
39
40Follow these steps in order:
41
42### Step 0: Verify Prerequisites and Gather Context
43
441. **Check if `05-ux/` folder exists (mandatory):**
45 - If NOT found: Inform user they need to create UX design first, then STOP
46 - If found: Read all files to understand:
47 - User flows and interactions
48 - Mockup structure (if UI-based app)
49 - Screen navigation patterns
50
512. **Check if `04-prd/` folder exists (mandatory):**
52 - If NOT found: Inform user they need PRD first, then STOP
53 - If found: Read to understand:
54 - Functional requirements
55 - Non-functional requirements (performance, security, scalability)
56 - Feature list and priorities
57
583. **Check if `00-init-ideas/` folder exists (recommended):**
59 - If found: Read to understand all files
60
614. **Check if `03-mvp/` folder exists (recommended):**
62 - If found: Read to understand:
63 - MVP scope (what to prioritize in architecture)
64 - Success metrics (inform performance targets)
65
665. **Check if this stage should be skipped:**
67 - Check if `06-architecture/SKIP.md` exists
68 - **If SKIP.md exists:**
69 - Read SKIP.md to understand why this stage was skipped
70 - Inform the user: "Stage 6 (architecture) is marked as SKIP because [reason from SKIP.md]"
71 - Ask the user: "Would you like to proceed to the next stage (tech-specs)?"
72 - **If user says yes:**
73 - Exit this skill and inform them to run the next stage skill
74 - **If user says no:**
75 - Ask if they want to proceed with architecture anyway
76 - If yes, delete SKIP.md and continue with this skill
77 - If no, exit the skill
78
796. **Check if `06-architecture/` folder exists:**
80 - If exists: Read all existing files to understand current architecture state
81 - If NOT exists: Will create new structure
82
837. **If README.md exists:** Check whether it requires diagrams. If it does,
84 follow `dev-swarm/docs/mermaid-diagram-guide.md` and use the
85 `dev-swarm-mermaid` skill to render outputs.
86
878. Proceed to Step 1 with gathered context
88
89### Step 1: Refine Design Requirements in README and Get Approval
90
91**CRITICAL: Create/update README.md first based on previous stage results, get user approval, then create other docs.**
92
931. **Analyze information from previous stages:**
94 - Read `05-ux/` to understand user flows and UI structure
95 - Read `04-prd/` to understand functional and non-functional requirements
96 - Read `03-mvp/` (if exists) to understand what to prioritize
97 - Consider cost-budget constraints for this stage
98
992. **Create or update 06-architecture/README.md with refined requirements:**
100 - List deliverables explicitly in README (typical: system-overview.md, architecture-diagram.md, data-flow.md, deployment-boundaries.md)
101 - **Stage overview and objectives** (based on previous stage context)
102 - **Owners:** Tech Manager (lead), Backend Architect, Frontend Architect, AI Engineer, Content Moderator, DevOps Engineer
103 - **Diagrams (if required by project init):**
104 - Reference `dev-swarm/docs/mermaid-diagram-guide.md`
105 - Include `diagram/` deliverables when needed
106 - **What architecture will include:**
107 - System components and their responsibilities
108 - Architecture diagrams (high-level + detail)
109 - Data flow for critical user journeys
110 - Deployment boundaries and scaling strategy
111 - **Methodology:**
112 - How components will be defined (from PRD requirements)
113 - Diagram approach (Mermaid for all diagrams)
114 - **Deliverables planned:**
115 - List of files that will be created (system-overview.md, architecture-diagram.md, etc.)
116 - **Budget allocation for this stage** (from cost-budget.md)
117 - **Status:** In Progress (update to "Completed" after implementation)
118
1193. **Present README to user:**
120 - Show the architecture approach and what will be designed
121 - Show what documentation files will be created
122 - Explain how it aligns with previous stages
123 - Ask: "Does this architecture plan look good? Should I proceed with designing system architecture?"
124
1254. **Wait for user approval:**
126 - **If user says yes:** Proceed to Step 2
127 - **If user says no:**
128 - Ask what needs to be changed
129 - Update README based on feedback
130 - Ask for approval again
131
132### Step 2: Create/Update Architecture Structure
133
134**Only after user approves the README:**
135
1361. **Create files as specified in the approved README.md:**
137
138 **IMPORTANT:** The file structure below is a SAMPLE only. The actual files you create must follow what was approved in the README.md in Step 1.
139
140 **Typical structure (example):**
141 ```
142 06-architecture/
143 ├── README.md (already created and approved in Step 1)
144 ├── system-overview.md (if specified in README)
145 ├── architecture-diagram.md (if specified in README)
146 ├── data-flow.md (if specified in README)
147 └── deployment-boundaries.md (if specified in README)
148 ```
149
150 **Create only the files listed in the README's "Deliverables planned" section.**
151
152### Step 3: Create/Update Architecture Documentation
153
154**IMPORTANT: Only create architecture documentation after README is approved in Step 1.**
155
156**NOTE:** The content structure below provides GUIDELINES for typical architecture documentation. Adapt based on the approved README and project needs.
157
158**If files don't exist:** Create new comprehensive architecture documents.
159
160**06-architecture/README.md:**
161- Stage overview and objectives
162- Specify the owners: Tech Manager (lead), Backend Architect, Frontend Architect, DevOps Engineer
163- Summary of architectural approach and principles
164- Links to all architecture documentation files
165- Key architectural decisions and rationale
166
167**system-overview.md:**
168
169Define the major system components and their responsibilities:
170
1711. **Architectural Principles:**
172 - List the guiding principles for this architecture
173 - Examples:
174 - Separation of concerns
175 - Scalability and horizontal scaling
176 - Security by design
177 - Fail-fast and graceful degradation
178 - Stateless services where possible
179 - API-first approach
180 - Mobile-first or responsive design
181
1822. **System Components:**
183
184 **Format for each component:**
185 ```
186 ### Component: [Component Name]
187
188 **Type:** Frontend / Backend / Database / External Service / Infrastructure
189
190 **Responsibility:**
191 - What this component does
192 - What problems it solves
193 - What it is NOT responsible for
194
195 **Key Capabilities:**
196 - Capability 1
197 - Capability 2
198 - Capability 3
199
200 **Interfaces:**
201 - Inputs: What data/requests it receives
202 - Outputs: What data/responses it produces
203 - APIs: What APIs it exposes (if any)
204
205 **Dependencies:**
206 - What other components does this depend on?
207 - What external services does this use?
208
209 **Data Storage:**
210 - What data does this component store?
211 - Where is it stored?
212
213 **Scalability:**
214 - Can this scale horizontally or vertically?
215 - What are the scaling constraints?
216 ```
217
2183. **Component Categories:**
219
220 **Frontend Components:**
221 - Web Application (if applicable)
222 - Mobile Application (if applicable)
223 - Desktop Application (if applicable)
224 - Admin Dashboard (if needed)
225
226 **Backend Components:**
227 - API Gateway / Backend for Frontend (BFF)
228 - Core Application Services
229 - Authentication Service
230 - Business Logic Services
231 - Background Job Processors
232 - Notification Service
233 - File Storage Service
234
235 **Data Components:**
236 - Primary Database
237 - Cache Layer
238 - Search Index (if needed)
239 - Object Storage (for files/media)
240 - Message Queue (if needed)
241
242 **External Services:**
243 - Third-party APIs (payment, email, SMS, etc.)
244 - Authentication providers (OAuth, SSO)
245 - CDN services
246 - Monitoring and logging services
247
2484. **Component Interaction Patterns:**
249 - Request-Response (synchronous)
250 - Event-Driven (asynchronous)
251 - Pub-Sub messaging
252 - Polling vs. webhooks
253 - WebSocket connections (if real-time features)
254
255**architecture-diagram.md:**
256
257Create visual diagrams showing system architecture:
258
2591. **High-Level Architecture Diagram:**
260
261 Use Mermaid to create a diagram showing all major components:
262
263 ```mermaid
264 graph TB
265 subgraph "Client Layer"
266 WebApp[Web Application]
267 MobileApp[Mobile Application]
268 end
269
270 subgraph "API Layer"
271 APIGateway[API Gateway]
272 Auth[Auth Service]
273 end
274
275 subgraph "Application Layer"
276 CoreAPI[Core API Service]
277 BgJobs[Background Jobs]
278 Notifications[Notification Service]
279 end
280
281 subgraph "Data Layer"
282 DB[(Primary Database)]
283 Cache[(Cache)]
284 Storage[(Object Storage)]
285 end
286
287 subgraph "External Services"
288 Email[Email Service]
289 Payment[Payment Service]
290 end
291
292 WebApp --> APIGateway
293 MobileApp --> APIGateway
294 APIGateway --> Auth
295 APIGateway --> CoreAPI
296 CoreAPI --> DB
297 CoreAPI --> Cache
298 CoreAPI --> BgJobs
299 BgJobs --> Notifications
300 Notifications --> Email
301 CoreAPI --> Payment
302 CoreAPI --> Storage
303 ```
304
3052. **Component Detail Diagrams:**
306
307 Create additional diagrams for complex subsystems:
308 - Authentication flow diagram
309 - Payment processing flow
310 - File upload/download flow
311 - Real-time messaging flow (if applicable)
312
3133. **Database Schema Diagram (High-Level):**
314
315 Show major entities and relationships:
316 ```mermaid
317 erDiagram
318 User ||--o{ Post : creates
319 User ||--o{ Comment : writes
320 Post ||--o{ Comment : has
321 User {
322 uuid id
323 string email
324 string name
325 }
326 Post {
327 uuid id
328 uuid user_id
329 string title
330 text content
331 }
332 Comment {
333 uuid id
334 uuid user_id
335 uuid post_id
336 text content
337 }
338 ```
339
340**data-flow.md:**
341
342Document how data flows through the system:
343
3441. **Request Flow (Frontend to Backend):**
345
346 For each major user flow from UX design:
347
348 **Format:**
349 ```
350 ### Flow: [User Flow Name]
351
352 **Trigger:** User action that initiates the flow (from 05-ux/user-flows.md)
353
354 **Step-by-Step Data Flow:**
355
356 1. **User Action:** User clicks/submits/interacts
357 - Component: [Frontend Component]
358 - Data: [What data is involved]
359
360 2. **API Request:**
361 - Component: Frontend → API Gateway
362 - Method: GET/POST/PUT/DELETE
363 - Endpoint: /api/resource
364 - Request Data: { ... }
365 - Headers: [Authentication, Content-Type, etc.]
366
367 3. **Authentication/Authorization:**
368 - Component: API Gateway → Auth Service
369 - Validation: [What is checked]
370 - Result: [Pass/Fail action]
371
372 4. **Business Logic Processing:**
373 - Component: Core API Service
374 - Processing: [What happens to the data]
375 - Validation: [Business rules applied]
376 - Transformations: [Data transformations]
377
378 5. **Database Operations:**
379 - Component: Core API → Database
380 - Operation: SELECT/INSERT/UPDATE/DELETE
381 - Tables: [Which tables affected]
382 - Transactions: [If transaction needed]
383
384 6. **External Service Calls (if any):**
385 - Component: Core API → External Service
386 - Service: [Which external service]
387 - Purpose: [Why calling it]
388 - Fallback: [What if service fails]
389
390 7. **Response Construction:**
391 - Component: Core API
392 - Data: [Response data structure]
393 - Status: [HTTP status code]
394
395 8. **Response to Frontend:**
396 - Component: API Gateway → Frontend
397 - Data: { ... }
398 - Frontend Action: [How UI updates]
399
400 **Error Handling:**
401 - What happens if step X fails?
402 - Rollback strategy
403 - Error messages to user
404
405 **Caching Strategy:**
406 - What data is cached?
407 - Where is it cached?
408 - Cache invalidation rules
409
410 **Performance Considerations:**
411 - Expected latency
412 - Database query optimization
413 - N+1 query prevention
414 ```
415
4162. **Data Flow Categories:**
417 - **Read Flows**: Fetching and displaying data
418 - **Write Flows**: Creating and updating data
419 - **Delete Flows**: Removing data
420 - **File Upload Flows**: Handling file uploads
421 - **Background Processing Flows**: Async jobs and batch operations
422 - **Real-time Flows**: WebSocket or server-sent events (if applicable)
423
4243. **Data Transformation Pipeline:**
425 - Input validation and sanitization
426 - Data normalization
427 - Business logic application
428 - Response formatting
429 - Error formatting
430
431**deployment-boundaries.md:**
432
433Define what runs where and security/trust boundaries:
434
4351. **Deployment Environments:**
436
437 **Development Environment:**
438 - Where: Local machine / Dev cloud
439 - Purpose: Development and testing
440 - Data: Fake/seed data
441 - Access: Developers only
442
443 **Staging Environment:**
444 - Where: Cloud (same region as production)
445 - Purpose: Pre-production testing and QA
446 - Data: Production-like data (anonymized)
447 - Access: Internal team + selected beta testers
448
449 **Production Environment:**
450 - Where: Cloud (specify regions if multi-region)
451 - Purpose: Live user-facing environment
452 - Data: Real user data
453 - Access: Public users (authenticated)
454
4552. **What Runs Where:**
456
457 **Client-Side (User's Device):**
458 - Web application (browser)
459 - Mobile application (iOS/Android)
460 - Desktop application (if applicable)
461 - Client-side validation
462 - UI rendering and interaction
463
464 **Edge/CDN:**
465 - Static assets (HTML, CSS, JS, images)
466 - Cached API responses (if applicable)
467 - DDoS protection
468 - SSL/TLS termination
469
470 **Cloud - Application Layer:**
471 - API Gateway
472 - Application servers
473 - Authentication services
474 - Background job workers
475 - Notification services
476
477 **Cloud - Data Layer:**
478 - Primary database
479 - Cache servers (Redis/Memcached)
480 - Search indexes (if applicable)
481 - Object storage (S3/CloudStorage)
482 - Message queues (if applicable)
483
484 **Third-Party Services:**
485 - Email delivery (SendGrid, AWS SES, etc.)
486 - Payment processing (Stripe, PayPal, etc.)
487 - SMS delivery (Twilio, etc.)
488 - Analytics (Google Analytics, Mixpanel, etc.)
489 - Error tracking (Sentry, etc.)
490 - Monitoring (Datadog, New Relic, etc.)
491
4923. **Trust Boundaries:**
493
494 **Boundary 1: User Device ↔ Cloud:**
495 - Trust Level: Untrusted to Trusted
496 - Security:
497 - HTTPS/TLS encryption
498 - Authentication required
499 - Input validation and sanitization
500 - CSRF protection
501 - Rate limiting
502 - Data Flow: User actions → API requests
503
504 **Boundary 2: Public API ↔ Internal Services:**
505 - Trust Level: Partially Trusted to Trusted
506 - Security:
507 - API authentication (JWT, OAuth)
508 - Authorization checks
509 - Service-to-service authentication
510 - Network segmentation (VPC, private subnets)
511 - Data Flow: API Gateway → Internal services
512
513 **Boundary 3: Application ↔ Database:**
514 - Trust Level: Trusted to Highly Trusted
515 - Security:
516 - Database credentials in secrets manager
517 - Encrypted connections (SSL/TLS)
518 - Principle of least privilege
519 - Network isolation
520 - Data Flow: Application services → Database
521
522 **Boundary 4: Application ↔ External Services:**
523 - Trust Level: Trusted to Untrusted
524 - Security:
525 - API keys in secrets manager
526 - HTTPS only
527 - Timeout and retry logic
528 - Fallback mechanisms
529 - Circuit breaker pattern
530 - Data Flow: Application → Third-party APIs
531
5324. **Scaling Assumptions:**
533
534 **Vertical Scaling (Scale Up):**
535 - Which components scale vertically?
536 - Maximum instance size limits
537 - When to switch to horizontal scaling
538
539 **Horizontal Scaling (Scale Out):**
540 - Which components scale horizontally?
541 - Load balancing strategy
542 - Stateless service requirements
543 - Session management approach
544
545 **Auto-Scaling Triggers:**
546 - CPU utilization thresholds
547 - Memory utilization thresholds
548 - Request rate thresholds
549 - Queue depth thresholds
550
551 **Database Scaling:**
552 - Read replicas for read-heavy workloads
553 - Sharding strategy (if applicable)
554 - Caching to reduce database load
555 - Connection pooling
556
557 **CDN and Caching:**
558 - Static asset caching
559 - API response caching
560 - Cache invalidation strategy
561 - Edge caching locations
562
5635. **High Availability & Fault Tolerance:**
564 - Multi-AZ deployment (if cloud)
565 - Database failover strategy
566 - Service redundancy
567 - Load balancer health checks
568 - Circuit breaker for external services
569 - Graceful degradation strategies
570
5716. **Geographic Distribution (if applicable):**
572 - Multi-region deployment
573 - Data residency requirements
574 - Latency optimization
575 - CDN edge locations
576
577### Step 4: Ensure Alignment
578
579Make sure architecture aligns with:
580- Non-functional requirements from 04-prd/non-functional-requirements.md
581- Functional requirements from 04-prd/functional-requirements.md
582- User flows from 05-ux/user-flows.md
583- MVP scope from 03-mvp/ (architecture should support MVP first, then scale)
584
585Verify that:
586- All functional requirements can be implemented in this architecture
587- Performance targets are achievable
588- Security requirements are addressed
589- Scalability needs are met
590- Deployment is feasible
591
592### Step 5: Final User Review
593
5941. **Inform user that architecture is complete**
5952. **Update README.md:**
596 - Change **Status** from "In Progress" to "Completed"
597 - Add a **Summary** section with key insights (2-3 paragraphs)
598 - Add a **Created Files** section listing all created files
599
6003. **Present completed work to user:**
601 - Walk through the architecture diagrams
602 - Explain major components and their responsibilities
603 - Show data flow for critical user journeys
604 - Explain deployment boundaries and security
605
6064. **Highlight key insights:**
607 - Number of major components
608 - Key architectural patterns used
609 - Scalability approach
610 - Security boundaries
611 - Cloud vs. local deployment split
612
6135. **Ask questions:**
614 - Does the architecture make sense?
615 - Are there any components missing?
616 - Any concerns about scalability or security?
617 - Ready to proceed to next stage (tech specs)?
618
6196. Make adjustments based on user feedback if needed
620
621### Step 6: Commit to Git (if user confirms)
622
6231. **If user confirms architecture is complete:**
624 - Ask if they want to commit to git
6252. **If user wants to commit:**
626 - Stage all changes in `06-architecture/`
627 - Commit with message: "Design system architecture and deployment (Stage 6)"
628
629## Expected Project Structure
630
631```
632project-root/
633├── 00-init-ideas/
634│ └── [existing files]
635├── 01-market-research/ (optional)
636│ └── [existing files if present]
637├── 02-personas/
638│ └── [existing files]
639├── 03-mvp/
640│ └── [existing files]
641├── 04-prd/
642│ └── [existing files]
643├── 05-ux/
644│ └── [existing files]
645└── 06-architecture/
646 ├── README.md (with owners and summary)
647 ├── system-overview.md (components + responsibilities)
648 ├── architecture-diagram.md (Mermaid diagrams)
649 ├── data-flow.md (request/data flow details)
650 └── deployment-boundaries.md (what runs where, trust boundaries, scaling)
651```
652
653## Key Architecture Principles
654
6551. **Structure, Not Frameworks**: Define system shape without specifying technologies
6562. **Component Clarity**: Each component has clear, single responsibility
6573. **Separation of Concerns**: Frontend, backend, data, external services clearly separated
6584. **Scalability by Design**: Consider scaling from the start
6595. **Security Boundaries**: Clear trust boundaries and security controls
6606. **Fail Gracefully**: Plan for failures and degradation
6617. **Data Flow Transparency**: Clear understanding of how data moves
6628. **Deployment Feasibility**: Can actually be deployed and operated
663
664## Architecture Best Practices
665
6661. **Start Simple**: MVP architecture should be simple, add complexity later
6672. **Use Diagrams**: Mermaid diagrams make architecture visual and clear
6683. **Document Decisions**: Explain why you chose this architecture
6694. **Consider Trade-offs**: No architecture is perfect, document trade-offs
6705. **Plan for Change**: Make architecture flexible for future needs
6716. **Security First**: Build security into architecture, not bolt on later
6727. **Performance Aware**: Consider performance implications of design decisions
6738. **Operational Thinking**: Consider monitoring, logging, debugging
674
675## Deliverables
676
677By the end of this stage, you should have:
678- Complete system overview with component definitions (5-15 major components)
679- Architecture diagrams using Mermaid (high-level + detail diagrams)
680- Detailed data flow documentation for critical user journeys
681- Deployment boundaries and security trust zones defined
682- Scaling strategy and assumptions documented
683- Foundation for tech stack selection (next stage)
684- Clear understanding of how system will be structured