architecture-design
Purpose
Guide the design of a system or feature from requirements to a documented architecture. Produces C4-model diagrams (Context → Container → Component), service boundary definitions, API contracts, data flow diagrams, failure mode analysis, and an ADR for the key decisions made. Works standalone or as the /abd-design agent in the ABD workflow.
Quick mode (/architecture-design --quick): for single-feature or small-scope designs. Skip Step 5 (C4 Level 3), make the Step 8 failure-mode table optional (include only externally-dependent paths), and keep Steps 1–2 to a single confirmation exchange.
Emit as you go: output each step's section immediately as you complete it rather than composing the whole document at the end. Step 10 assembles the already-emitted sections into the saved file. This keeps quality even across sections.
Instructions
Step 1 — Gather inputs
Ask the user for (or read from existing artifacts):
- What are we building? (description or link to requirements doc / Jira epic)
- What are the key constraints? (team size, existing systems to integrate with, cloud provider, language preference, compliance requirements)
- What is the expected scale? (users/day, requests/second, data volume)
- What is the timeline? (affects how complex a solution is appropriate)
- Are there existing systems this must integrate with or replace?
If docs/requirements/ exists, use Glob and Read to load relevant requirements documents.
Step 2 — Propose architecture style
Based on the inputs, recommend and justify one of these patterns. Explain the tradeoffs in the context of the stated constraints:
| Pattern |
Best For |
Avoid When |
| Monolith (Modular) |
Small teams, early stage, unclear domain boundaries |
Team > 10, independent scaling needed |
| Microservices |
Large teams, independent scaling, polyglot |
Small team, immature domain model |
| Event-Driven |
Async workflows, loose coupling, audit trail needed |
Simple CRUD, low latency required |
| Hexagonal (Ports & Adapters) |
Complex domain logic, testability, multiple I/O adapters |
Simple CRUD apps |
| CQRS + Event Sourcing |
Complex queries, audit history, high write/read ratio difference |
Simple domains, small teams |
| Serverless |
Unpredictable traffic, low ops overhead, event-driven |
Long-running jobs, high cold-start sensitivity |
| BFF (Backend for Frontend) |
Multiple client types with different data needs |
Single client type |
Ask the user to confirm the pattern before proceeding.
Step 3 — C4 Model — Level 1: System Context
Produce a Mermaid diagram showing the system in context:
- The system being built (center)
- External users/actors
- External systems it integrates with
- Data flows between them
C4Context
title System Context — <System Name>
Person(user, "End User", "Uses the system via web/mobile")
System(system, "<System Name>", "The system being designed")
System_Ext(auth, "Auth Provider", "OAuth2/OIDC — e.g. Auth0")
System_Ext(email, "Email Service", "Transactional email — e.g. SendGrid")
Rel(user, system, "Uses", "HTTPS")
Rel(system, auth, "Authenticates via", "HTTPS/OIDC")
Rel(system, email, "Sends email via", "HTTPS/API")
If C4 Mermaid syntax is not supported, use graph LR with clear labels.
Step 4 — C4 Model — Level 2: Container Diagram
Decompose the system into containers (deployable units):
- Web frontend (SPA, SSR, mobile app)
- API server(s)
- Background workers / queues
- Databases (type: relational, document, cache, search)
- Message broker (if event-driven)
- CDN / static assets
For each container specify: technology choice, responsibility, and communication protocol with other containers.
Step 5 — C4 Model — Level 3: Component Diagram (key containers only)
For the most complex container (usually the API server), decompose into components:
- Router / Controller layer
- Service / Use Case layer
- Repository / Data Access layer
- Domain Model
- External adapters (email, payment, auth)
- Shared utilities (logging, validation, config)
Step 6 — Data Design
- Identify the core entities and their relationships (ER diagram in Mermaid)
- Recommend database type for each store: relational (normalized, ACID), document (flexible schema), key-value (cache/session), time-series (metrics/events), search (full-text)
- Flag any PII/sensitive data and where encryption at rest is required
- Identify high-read vs high-write data and caching strategy
Step 7 — API Contract Sketch
For each major API surface, define:
- Protocol: REST, GraphQL, gRPC, WebSocket, or event/message
- Key endpoints/operations (resource name, method, brief description)
- Authentication mechanism (JWT, API key, OAuth2 scopes)
- Pagination strategy (cursor vs offset)
- Error response format
Step 8 — Failure Mode Analysis
For each external dependency and critical path, define:
- What happens if this fails?
- Mitigation: retry with backoff, circuit breaker, graceful degradation, fallback, queue
- Recovery time objective (RTO) — how quickly must this recover?
Step 9 — Cross-Cutting Concerns
Address explicitly:
- Authentication & Authorization: where auth is enforced, which framework/library
- Observability: structured logging, distributed tracing (trace IDs), metrics, alerting
- Configuration: how env vars / secrets are managed per environment
- Deployment: container/serverless, CI/CD pipeline shape, blue/green vs rolling
- Testing strategy: unit (domain logic), integration (adapters), contract (API), E2E (critical flows)
Step 10 — Write Design Artifact
Use Write to save the full design to docs/architecture/<feature-or-system-name>-design.md.
If handoffs/designs/ exists (ABD workflow), also write a JSON artifact to handoffs/designs/{taskId}_design_{unixTimestamp}.json using the ABD envelope schema.
Offer to run /adr to capture the key architectural decisions as ADRs.
Output Format
The design document should contain all diagrams inline as Mermaid fenced code blocks, all tables, and a "Key Decisions" section summarising the choices made and why. End with "Open Questions" — any decisions that need stakeholder input before implementation begins.
1---2name: architecture-design3description: Designs new systems from requirements: C4 model diagrams, service boundaries, API contracts, data design, failure modes, and cross-cutting concerns.4---56# architecture-design78## Purpose910Guide the design of a system or feature from requirements to a documented architecture. Produces C4-model diagrams (Context → Container → Component), service boundary definitions, API contracts, data flow diagrams, failure mode analysis, and an ADR for the key decisions made. Works standalone or as the `/abd-design` agent in the ABD workflow.1112**Quick mode** (`/architecture-design --quick`): for single-feature or small-scope designs. Skip Step 5 (C4 Level 3), make the Step 8 failure-mode table optional (include only externally-dependent paths), and keep Steps 1–2 to a single confirmation exchange.1314**Emit as you go:** output each step's section immediately as you complete it rather than composing the whole document at the end. Step 10 assembles the already-emitted sections into the saved file. This keeps quality even across sections.1516---1718## Instructions1920### Step 1 — Gather inputs2122Ask the user for (or read from existing artifacts):23- What are we building? (description or link to requirements doc / Jira epic)24- What are the key constraints? (team size, existing systems to integrate with, cloud provider, language preference, compliance requirements)25- What is the expected scale? (users/day, requests/second, data volume)26- What is the timeline? (affects how complex a solution is appropriate)27- Are there existing systems this must integrate with or replace?2829If `docs/requirements/` exists, use Glob and Read to load relevant requirements documents.3031---3233### Step 2 — Propose architecture style3435Based on the inputs, recommend and justify one of these patterns. Explain the tradeoffs in the context of the stated constraints:3637| Pattern | Best For | Avoid When |38|---------|----------|------------|39| Monolith (Modular) | Small teams, early stage, unclear domain boundaries | Team > 10, independent scaling needed |40| Microservices | Large teams, independent scaling, polyglot | Small team, immature domain model |41| Event-Driven | Async workflows, loose coupling, audit trail needed | Simple CRUD, low latency required |42| Hexagonal (Ports & Adapters) | Complex domain logic, testability, multiple I/O adapters | Simple CRUD apps |43| CQRS + Event Sourcing | Complex queries, audit history, high write/read ratio difference | Simple domains, small teams |44| Serverless | Unpredictable traffic, low ops overhead, event-driven | Long-running jobs, high cold-start sensitivity |45| BFF (Backend for Frontend) | Multiple client types with different data needs | Single client type |4647Ask the user to confirm the pattern before proceeding.4849---5051### Step 3 — C4 Model — Level 1: System Context5253Produce a Mermaid diagram showing the system in context:54- The system being built (center)55- External users/actors56- External systems it integrates with57- Data flows between them5859```mermaid60C4Context61 title System Context — <System Name>62 Person(user, "End User", "Uses the system via web/mobile")63 System(system, "<System Name>", "The system being designed")64 System_Ext(auth, "Auth Provider", "OAuth2/OIDC — e.g. Auth0")65 System_Ext(email, "Email Service", "Transactional email — e.g. SendGrid")66 Rel(user, system, "Uses", "HTTPS")67 Rel(system, auth, "Authenticates via", "HTTPS/OIDC")68 Rel(system, email, "Sends email via", "HTTPS/API")69```7071If C4 Mermaid syntax is not supported, use `graph LR` with clear labels.7273---7475### Step 4 — C4 Model — Level 2: Container Diagram7677Decompose the system into containers (deployable units):78- Web frontend (SPA, SSR, mobile app)79- API server(s)80- Background workers / queues81- Databases (type: relational, document, cache, search)82- Message broker (if event-driven)83- CDN / static assets8485For each container specify: technology choice, responsibility, and communication protocol with other containers.8687---8889### Step 5 — C4 Model — Level 3: Component Diagram (key containers only)9091For the most complex container (usually the API server), decompose into components:92- Router / Controller layer93- Service / Use Case layer94- Repository / Data Access layer95- Domain Model96- External adapters (email, payment, auth)97- Shared utilities (logging, validation, config)9899---100101### Step 6 — Data Design102103- Identify the core entities and their relationships (ER diagram in Mermaid)104- Recommend database type for each store: relational (normalized, ACID), document (flexible schema), key-value (cache/session), time-series (metrics/events), search (full-text)105- Flag any PII/sensitive data and where encryption at rest is required106- Identify high-read vs high-write data and caching strategy107108---109110### Step 7 — API Contract Sketch111112For each major API surface, define:113- Protocol: REST, GraphQL, gRPC, WebSocket, or event/message114- Key endpoints/operations (resource name, method, brief description)115- Authentication mechanism (JWT, API key, OAuth2 scopes)116- Pagination strategy (cursor vs offset)117- Error response format118119---120121### Step 8 — Failure Mode Analysis122123For each external dependency and critical path, define:124- What happens if this fails?125- Mitigation: retry with backoff, circuit breaker, graceful degradation, fallback, queue126- Recovery time objective (RTO) — how quickly must this recover?127128---129130### Step 9 — Cross-Cutting Concerns131132Address explicitly:133- **Authentication & Authorization**: where auth is enforced, which framework/library134- **Observability**: structured logging, distributed tracing (trace IDs), metrics, alerting135- **Configuration**: how env vars / secrets are managed per environment136- **Deployment**: container/serverless, CI/CD pipeline shape, blue/green vs rolling137- **Testing strategy**: unit (domain logic), integration (adapters), contract (API), E2E (critical flows)138139---140141### Step 10 — Write Design Artifact142143Use Write to save the full design to `docs/architecture/<feature-or-system-name>-design.md`.144145If `handoffs/designs/` exists (ABD workflow), also write a JSON artifact to `handoffs/designs/{taskId}_design_{unixTimestamp}.json` using the ABD envelope schema.146147Offer to run `/adr` to capture the key architectural decisions as ADRs.148149---150151## Output Format152153The design document should contain all diagrams inline as Mermaid fenced code blocks, all tables, and a "Key Decisions" section summarising the choices made and why. End with "Open Questions" — any decisions that need stakeholder input before implementation begins.