| name | system-design-doc |
| description | Generate a system-level design document via `tx doc add design`. Covers cross-cutting architecture, service boundaries, data flows, scalability, and deployment topology. References plan via file path instead of embedding. Plan lives in ~/.claude/plans/<name>.md. Use for system-wide or multi-domain designs (vs /design-doc for feature-scoped). |
| argument-hint | <system-or-initiative-name> |
Generate System Design Document
Create a system-level design document using the tx doc primitive. System design docs cover cross-cutting architecture spanning multiple domains. For single-feature designs, use /design-doc.
Workflow State Machine
START
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 0: PLAN GATE โ
โ โ
โ Is there an active plan in this conversation? โ
โ โ
โ โโ YES โ Save plan to `~/.claude/plans/<name>.md` if not โ
โ โ already saved. Set `plan: ~/.claude/plans/<name>.md` โ
โ โ in frontmatter. โ
โ โ โ Continue to Step 1 โ
โ โ โ
โ โโ NO โ Tell user to run /plan first. โ
โ If enough detail, generate plan, save to โ
โ `~/.claude/plans/<name>.md`. โ
โ โ Continue to Step 1 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 1: SCAFFOLD via tx โ
โ โ
โ tx doc add design <name> --title "<title>" โ
โ โโ SUCCESS โ Continue to Step 2 โ
โ โโ FAIL (exists) โ Edit existing doc โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 2: DEEP CONTEXT GATHERING โ
โ โ
โ Read: ARCHITECTURE.md, QUALITY.md, DEPLOYMENT.md, โ
โ ROLLBACK.md, RUNBOOKS.md, CLAUDE.md, โ
โ schema.ts, workflows.ts, all infra packages, โ
โ all existing specs (tx doc list) โ
โ โ Continue to Step 3 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 3: FILL DOCUMENT โ
โ โ
โ Write `# Plan` first (reference to plan file from โ
โ Step 0). โ
โ Then fill all sections from plan + codebase. โ
โ โ
โ MINIMUM THRESHOLDS: โ
โ - Invariants: โฅ 7 โ
โ - Failure modes: โฅ 3 โ
โ - Verification entries: โฅ 5 โ
โ - Design decisions: โฅ 2 โ
โ - Service boundaries: โฅ 3 โ
โ - Data flow diagrams: โฅ 2 โ
โ โ
โ RULE: No section may be left as a template/stub. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 4: SELF-AUDIT โ
โ โ
โ Every plan item captured? No stubs? Minimums met? โ
โ All diagrams complete? Cross-cutting addressed? โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 5: VALIDATE โ
โ โ
โ tx spec lint โ
โ โโ PASS โ Continue to Step 6 โ
โ โโ WARN/FAIL โ Fix, re-validate โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 6: DISCOVER + LINK + REPORT โ
โ โ
โ tx spec discover --doc <name> โ
โ tx doc link <overview> <design> โ
โ tx doc show <name> โ
โ Print summary โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 6.5: SYNC PLAN FILE โ
โ โ
โ Read the plan file from frontmatter `plan:` path. โ
โ UPDATE the plan file to incorporate everything โ
โ the doc surfaced: service boundaries, data flows, โ
โ design decisions, invariants, failure modes, โ
โ deployment topology, scalability strategy. โ
โ The plan file must reflect the FULL current state. โ
โ This is a MANDATORY step, not optional. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
DONE
Step 0 โ Plan Gate
The plan is the primary input. Check for plan content in the conversation:
- If the user ran
/plan or was in plan mode, the plan is saved as a standalone file at ~/.claude/plans/<name>.md (relative to repo root).
- If a plan already exists in the conversation, write it to that file.
- If a plan file already exists at that path, read it instead.
- If no plan but detailed user request, generate a plan yourself (research the codebase, think through topology/services/constraints) and save it to
~/.claude/plans/<name>.md.
- If no plan and vague request, ask user to run
/plan first.
The doc's frontmatter gets plan: ~/.claude/plans/<name>.md and the # Plan section contains a reference link + brief summary, not the full verbatim content.
Step 1 โ Scaffold via tx
tx doc add design $ARGUMENTS --title "<Human-Readable Title>"
Creates specs/design/<name>.md. If exists, edit instead.
Step 2 โ Deep Context Gathering
Read ALL of these:
docs/ARCHITECTURE.md, docs/QUALITY.md, docs/DEPLOYMENT.md, docs/ROLLBACK.md, docs/RUNBOOKS.md
CLAUDE.md
- All existing specs:
tx doc list
packages/infra/db/src/schema.ts
apps/worker/src/workflows.ts
apps/api/src/
packages/infra/*/
Step 3 โ Fill the Document
Required Frontmatter (already generated by tx)
---
kind: spec
spec_type: design
name: <name>
title: "<title>"
status: draft
version: 1
owners:
- <team-or-person>
summary: System-level design for <title>
domain: platform
tags:
- design
- system
depends_on: []
supersedes: []
implements: null
last_reviewed_at: <YYYY-MM-DD>
plan: ~/.claude/plans/<name>.md
---
Body Structure โ ALL sections MUST have real content
# Plan comes first (as a reference to the plan file). Every subsequent section draws from the plan file content. No section may be a stub.
# Plan
> Full plan: [~/.claude/plans/<name>.md](../~/.claude/plans/<name>.md)
<2-3 sentence summary of what the plan covers. The full plan lives in the file referenced above.>
# Summary
2-3 sentences on system-level design scope and key decisions.
# Architecture
## Current State
What exists today. What works, what doesn't. Reference `docs/ARCHITECTURE.md`.
## Proposed Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ External Traffic โ
โ (Cloudflare Tunnel) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Ingress Layer โ
โ (k3s Ingress / GKE LB) โ
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ API Service โ โ Web Service โ
โ (Effect HttpApi) โ โ (Next.js SPA) โ
โ [NEW/MOD] โ โ [NEW/MOD] โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Core Domain Layer โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โ
โ โ Auth โ โ Org โ โ Team โ โ โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Infrastructure Layer โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โPostgreSQL โ โ Temporal โ โ Redis โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Worker Layer โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Temporal Worker โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Mark: `[NEW]` / `[MOD]` / `[REMOVE]`.
## Service Boundaries
**MINIMUM: โฅ 3 services.**
| Service | Deployment | Scaling Strategy | Communication |
|---------|-----------|-----------------|---------------|
## Data Flows
**MINIMUM: โฅ 2 data flow diagrams.**
### Flow 1: <Name>
[Source] โ Protocol โ [Service A] โ Protocol โ [Service B] โ [Store]
## Design Decisions
**MINIMUM: โฅ 2 decisions with ADR-lite format.**
### Decision 1: <Title>
**Context:** Why needed.
**Options:**
| Option | Pros | Cons |
|--------|------|------|
**Decision:** Option X because <reasoning>.
**Consequences:** What follows.
# Interfaces
```yaml
interfaces:
- name: <ServiceInterface>
type: api_endpoint | message_contract | event_payload
definition: |
// definition
Inter-Service Contracts
API Surface Changes
| Method | Path | Change | Breaking? |
|---|
Data Model
Schema Overview
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โ Table A โโโโโ<โ Table B โโโโโ<โ Table C โ
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
New Tables + Migration Plan
| Order | Migration | Description | Backwards-Compatible |
|---|
Invariants
MINIMUM: โฅ 7 system-level invariants.
invariants:
- id: INV-SYS-001
statement: <what must be true across the system>
enforcement: <mechanism>
Failure Modes
MINIMUM: โฅ 3 failure modes.
failure_modes:
- id: FM-SYS-001
trigger: <cause>
impact: <effect>
detection: <how detected>
mitigation: <automatic>
recovery: <human>
Verification
MINIMUM: โฅ 5 entries. Every invariant MUST have a verification entry.
verification:
- invariant: INV-SYS-001
test_file: <path>
test_name: "description [INV-SYS-001]"
type: lint | integration | pgtap
Testing Strategy
Unit Tests
Integration Tests
Database Contract Tests
Quality Gate Sequence
pnpm lint && pnpm type-check && pnpm test && pnpm test:integration
pnpm test:db:pgtap
tx spec discover --doc <name>
tx spec fci --doc <name>
tx spec lint
Scalability
Current Capacity
Scaling Strategy
| Component | Horizontal | Vertical | Notes |
|---|
Deployment & Operations
Deployment Topology
| Environment | Infrastructure | Deploy Command |
|---|
Rollback
Reference docs/ROLLBACK.md.
Monitoring
| Signal | Source | Alert Threshold |
|---|
Security
Open Questions
## Step 4 โ Self-Audit
Re-read and verify:
1. Every plan item captured somewhere.
2. Minimums met: โฅ7 invariants, โฅ3 failure modes, โฅ5 verifications, โฅ2 decisions, โฅ3 services, โฅ2 data flows.
3. No stubs, no empty tables.
4. All diagrams complete.
5. Cross-cutting concerns addressed (security, monitoring, deployment, rollback).
6. Verify plan file exists at the path in frontmatter and its content is consistent with the doc.
## Step 5 โ Validate
```bash
tx spec lint
Step 6 โ Discover, Link & Report
tx spec discover --doc <name>
tx doc link <overview> <design>
tx doc show <name>
Step 6.5 โ Sync Plan File (MANDATORY)
After filling and validating the doc, update the plan file at the plan: frontmatter path to reflect everything the doc surfaced. The plan file must be the living source of truth โ not a stale initial draft.
What to add to the plan file:
- Service boundaries and deployment topology
- Data flow details and inter-service contracts
- Design decisions and their rationale
- Invariants, failure modes, scaling strategy
- Security considerations and monitoring signals
Read the current plan file, merge in the new information, and write it back.
After Generation
- Print output path (
specs/design/<name>.md).
- Summarize: invariant count, failure mode count, service count, decision count.
- List open questions.
- Run
tx spec lint.
- If the plan file is modified later, update the
# Plan summary and derived sections in this doc. If this doc's scope changes, update the plan file to stay consistent.