prd-to-spec

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

prd-to-spec — PRD to Technical Specification

prd-to-spec — 将PRD转化为技术规格文档

Transform a Product Requirements Document (PRD) into a detailed technical SPEC that an engineer or AI agent can implement against. The PRD says what to build; the SPEC says how to build it.

将产品需求文档(PRD)转化为工程师或AI Agent可据此实现的详细技术SPEC文档。PRD定义要做什么,而SPEC定义如何做

When to Use

适用场景

  • A
    /prd
    has been generated and you need to bridge the gap to implementation
  • You want architecture decisions documented before coding starts
  • Multiple developers/agents will implement the feature and need a shared contract
  • You need to validate technical feasibility before committing to a PRD
  • You want to catch design issues early — before code is written

  • 已生成
    /prd
    文档,需要填补从需求到实现的缺口
  • 希望在编码开始前记录架构决策
  • 多名开发者/Agent将共同实现该功能,需要一份共享约定
  • 需要在确定PRD前验证技术可行性
  • 希望在编写代码前尽早发现设计问题

The Job

工作流程

  1. Locate PRD — find or receive the PRD document
  2. Analyze context (optional) — if a codebase exists, scan it to understand current architecture, patterns, and constraints
  3. Ask clarifying questions — resolve technical ambiguities (max 3-5 questions)
  4. Generate SPEC — produce a structured technical specification
  5. Review — present to user for feedback and iteration
  6. Save — write final SPEC to agreed location

  1. 定位PRD — 查找或接收PRD文档
  2. 分析上下文(可选) — 如果已有代码库,扫描代码以了解当前架构、模式和约束
  3. 提出澄清问题 — 解决技术歧义(最多3-5个问题)
  4. 生成SPEC — 生成结构化的技术规格文档
  5. 评审 — 提交给用户获取反馈并迭代
  6. 保存 — 将最终SPEC写入约定位置

Step 1: Locate PRD

步骤1:定位PRD

Find the input PRD in one of these ways:
Provide the PRD to convert:

A. File path (e.g., tasks/prd-priority-system.md)
B. GitHub Issue URL
C. Paste PRD content directly
D. Auto-detect: scan tasks/ directory for recent PRDs
If auto-detecting, list available PRDs and let the user choose:
Found PRDs in tasks/:
  1. tasks/prd-priority-system.md (2024-03-15)
  2. tasks/prd-user-auth.md (2024-03-10)

Which PRD should I convert? [1/2]

通过以下方式之一找到输入的PRD:
提供待转换的PRD:

A. 文件路径(例如:tasks/prd-priority-system.md)
B. GitHub Issue链接
C. 直接粘贴PRD内容
D. 自动检测:扫描tasks/目录查找最新PRD
如果使用自动检测,列出可用PRD并让用户选择:
在tasks/目录中找到以下PRD:
  1. tasks/prd-priority-system.md(2024-03-15)
  2. tasks/prd-user-auth.md(2024-03-10)

应转换哪份PRD?[1/2]

Step 2: Analyze Context (Optional)

步骤2:分析上下文(可选)

Skip this step if no codebase exists yet (greenfield project). In that case, the SPEC will propose architecture from scratch based on the PRD requirements and clarifying questions.
If a codebase exists, scan it to understand:
  • Existing architecture — how the current system is structured
  • Tech stack — languages, frameworks, libraries already in use
  • Patterns — naming conventions, file organization, error handling approach
  • Database — current schema, migration tool, ORM
  • API style — REST/GraphQL/gRPC, authentication method, response format
  • Testing — test framework, coverage patterns, test utilities
This ensures the SPEC aligns with the existing system rather than proposing incompatible solutions.

如果还没有代码库(全新项目),跳过此步骤。这种情况下,SPEC将基于PRD需求和澄清问题从头提出架构方案。
如果已有代码库,扫描代码以了解:
  • 现有架构 — 当前系统的结构
  • 技术栈 — 已使用的语言、框架、库
  • 模式 — 命名规范、文件组织、错误处理方式
  • 数据库 — 当前 schema、迁移工具、ORM
  • API风格 — REST/GraphQL/gRPC、认证方式、响应格式
  • 测试 — 测试框架、覆盖模式、测试工具
这确保SPEC与现有系统保持一致,而非提出不兼容的解决方案。

Step 3: Clarifying Questions

步骤3:提出澄清问题

Ask only when the PRD leaves technical decisions ambiguous. Focus on:
  • Architecture choices — where does this feature live? New service or extend existing?
  • Data storage — new table? Extend existing? Cache strategy?
  • API design — new endpoints? Extend existing? Breaking changes?
  • Dependencies — any new libraries needed? Version constraints?
  • Performance — expected load? Latency requirements? Batch size limits?
Format:
Technical questions before I generate the SPEC:

1. Where should the priority logic live?
   A. Extend existing TaskService
   B. New PriorityService
   C. Inline in controller
   D. Let me decide based on the codebase

2. Database migration approach?
   A. Add column to existing tasks table
   B. New priority table with FK
   C. JSON field on tasks
   D. Let me decide based on current schema

3. API versioning concern?
   A. Add to existing v1 endpoints
   B. New v2 endpoints
   C. No versioning needed
If user selects "let me decide" options, make the best choice based on codebase analysis and document the rationale in the SPEC.

仅当PRD未明确技术决策时才提问。重点关注:
  • 架构选择 — 该功能应部署在哪里?新增服务还是扩展现有服务?
  • 数据存储 — 新增表?扩展现有表?缓存策略?
  • API设计 — 新增端点?扩展现有端点?是否有破坏性变更?
  • 依赖项 — 是否需要新增库?版本约束?
  • 性能 — 预期负载?延迟要求?批量大小限制?
格式示例:
生成SPEC前的技术问题:

1. 优先级逻辑应部署在哪里?
   A. 扩展现有TaskService
   B. 新增PriorityService
   C. 内联在控制器中
   D. 根据代码库由我决定

2. 数据库迁移方式?
   A. 向现有tasks表添加列
   B. 新增带外键的priority表
   C. tasks表中的JSON字段
   D. 根据当前schema由我决定

3. API版本考虑?
   A. 添加到现有v1端点
   B. 新增v2端点
   C. 无需版本控制
如果用户选择“由我决定”选项,基于代码库分析做出最优选择,并在SPEC中记录理由。

Step 4: SPEC Document Structure

步骤4:SPEC文档结构

markdown
undefined
markdown
undefined

SPEC: [Feature Name]

SPEC: [功能名称]

Technical specification derived from: [PRD filename/link] Generated: [date] | Target branch: [branch] | Commit: [short-hash]
技术规格文档源自:[PRD文件名/链接] 生成时间:[日期] | 目标分支:[分支] | 提交记录:[短哈希值]

1. Summary

1. 概述

1.1 What This SPEC Covers

1.1 本SPEC涵盖范围

[One paragraph: what feature this specifies and the scope of implementation]
[一段文字:说明本SPEC定义的功能及实现范围]

1.2 PRD Reference

1.2 PRD参考

  • Source: [path or URL to PRD]
  • User Stories covered: [US-001, US-002, ...]
  • Functional Requirements covered: [FR-1, FR-2, ...]
  • 来源:[PRD路径或链接]
  • 覆盖的用户故事:[US-001, US-002, ...]
  • 覆盖的功能需求:[FR-1, FR-2, ...]

1.3 Design Decisions Summary

1.3 设计决策摘要

DecisionChoiceRationale
.........

决策项选择方案理由
.........

2. Architecture

2. 架构

2.1 System Context

2.1 系统上下文

[Where this feature fits in the overall system — diagram or description]
[该功能在整体系统中的位置——示意图或文字描述]

2.2 Component Design

2.2 组件设计

[New components/modules introduced, their responsibilities, and boundaries]
[新增组件/模块的职责及边界]

2.3 Module Interactions

2.3 模块交互

[How new components interact with existing ones — sequence or data flow]
[新增组件与现有组件的交互方式——序列图或数据流描述]

2.4 File Structure

2.4 文件结构

[New files to create and existing files to modify]
src/
├── services/
│   └── priority.service.ts  [NEW]
├── controllers/
│   └── task.controller.ts   [MODIFY: add priority endpoints]
├── models/
│   └── priority.model.ts    [NEW]
└── migrations/
    └── 20240315_add_priority.ts [NEW]

[需创建的新文件及需修改的现有文件]
src/
├── services/
│   └── priority.service.ts  [新增]
├── controllers/
│   └── task.controller.ts   [修改:添加优先级相关端点]
├── models/
│   └── priority.model.ts    [新增]
└── migrations/
    └── 20240315_add_priority.ts [新增]

3. Data Model

3. 数据模型

3.1 Schema Changes

3.1 Schema变更

[New tables, columns, indexes — with SQL or ORM notation]
[新增表、列、索引——使用SQL或ORM表示法]

3.2 Entity Definitions

3.2 实体定义

[TypeScript interfaces / Go structs / Python dataclasses for new entities]
[新增实体的TypeScript接口/Go结构体/Python数据类]

3.3 Relationships

3.3 关系

[How new entities relate to existing ones — FK, embedded, reference]
[新增实体与现有实体的关系——外键、嵌入、引用]

3.4 Migration Plan

3.4 迁移计划

[Migration steps, backward compatibility, rollback strategy]

[迁移步骤、向后兼容性、回滚策略]

4. API Design

4. API设计

4.1 Endpoints

4.1 端点

MethodPathDescriptionAuthRequestResponse
..................
方法路径描述认证请求响应
..................

4.2 Request/Response Schemas

4.2 请求/响应Schema

[Detailed shapes with field types, validation rules, and examples]
[详细结构,包含字段类型、验证规则及示例]

4.3 Error Responses

4.3 错误响应

[Error codes, messages, and HTTP status codes for each failure mode]
[每种失败模式对应的错误码、消息及HTTP状态码]

4.4 Breaking Changes

4.4 破坏性变更

[Any backward-incompatible changes and migration path for consumers]

[任何向后不兼容的变更及面向消费者的迁移路径]

5. Business Logic

5. 业务逻辑

5.1 Core Algorithms

5.1 核心算法

[Step-by-step logic for key operations — pseudocode or structured description]
[关键操作的分步逻辑——伪代码或结构化描述]

5.2 Validation Rules

5.2 验证规则

[Input validation, business rule validation, with specific constraints]
[输入验证、业务规则验证及具体约束]

5.3 State Machine

5.3 状态机

[If applicable: states, transitions, guards, and side effects]
[如适用:状态、转换、守卫及副作用]

5.4 Edge Cases

5.4 边缘场景

[Known edge cases and how they should be handled]

[已知边缘场景及处理方式]

6. Error Handling

6. 错误处理

6.1 Error Taxonomy

6.1 错误分类

Error CodeHTTP StatusConditionUser Message
............
错误码HTTP状态码触发条件用户提示
............

6.2 Retry Strategy

6.2 重试策略

[Which operations are retryable, backoff policy, max attempts]
[哪些操作可重试、退避策略、最大尝试次数]

6.3 Failure Modes

6.3 故障模式

[What happens when dependencies fail — graceful degradation plan]

[依赖项故障时的处理——优雅降级方案]

7. Security

7. 安全

7.1 Authentication & Authorization

7.1 认证与授权

[Who can access what, permission model, role checks]
[访问权限、权限模型、角色校验]

7.2 Input Validation

7.2 输入验证

[Sanitization rules, injection prevention, size limits]
[ sanitization规则、注入防护、大小限制]

7.3 Data Protection

7.3 数据保护

[Sensitive fields, encryption at rest/transit, audit logging]

[敏感字段、静态/传输加密、审计日志]

8. Performance

8. 性能

8.1 Expected Load

8.1 预期负载

[Estimated QPS, data volume, growth projection]
[预估QPS、数据量、增长预测]

8.2 Optimization Strategy

8.2 优化策略

[Caching, pagination, lazy loading, batch processing]
[缓存、分页、懒加载、批量处理]

8.3 Database Considerations

8.3 数据库考量

[Index strategy, query patterns, N+1 prevention]

[索引策略、查询模式、避免N+1问题]

9. Testing Strategy

9. 测试策略

9.1 Unit Tests

9.1 单元测试

[What to test, test boundaries, mock strategy]
[测试内容、测试边界、Mock策略]

9.2 Integration Tests

9.2 集成测试

[API tests, database tests, service interaction tests]
[API测试、数据库测试、服务交互测试]

9.3 Edge Case Tests

9.3 边缘场景测试

[Specific scenarios to cover based on Section 5.4]
[基于5.4节的特定场景覆盖]

9.4 Acceptance Criteria Mapping

9.4 验收标准映射

US/FRTestTypeDescription
US-001...unit...
FR-2...integration...

用户故事/功能需求测试用例类型描述
US-001...单元测试...
FR-2...集成测试...

10. Implementation Plan

10. 实施计划

10.1 Phases

10.1 阶段划分

[Order of implementation — what to build first, dependencies between steps]
[实施顺序——先构建什么、步骤间的依赖关系]

10.2 Issue Mapping

10.2 Issue映射

[Map SPEC sections to PRD Issues for implementation tracking]
IssueSPEC SectionsPriorityDepends On
#13.1, 3.4high
#24.1, 4.2, 5.1high#1
............
[将SPEC章节映射到PRD Issues以跟踪实施进度]
IssueSPEC章节优先级依赖项
#13.1, 3.4
#24.1, 4.2, 5.1#1
............

10.3 Incremental Delivery

10.3 增量交付

[How to ship incrementally — feature flags, dark launches, gradual rollout]

[如何增量发布——功能开关、暗启动、逐步上线]

11. Open Questions & Risks

11. 未解决问题与风险

11.1 Unresolved Questions

11.1 未解决问题

  • [Questions that need product/engineering input before implementation]
  • [实施前需要产品/工程团队输入的问题]

11.2 Technical Risks

11.2 技术风险

RiskImpactMitigation
.........
风险影响缓解措施
.........

11.3 Assumptions

11.3 假设条件

  • [Technical assumptions made during SPEC creation — validate before implementing]

---
  • [生成SPEC时做出的技术假设——实施前需验证]

---

Step 5: Review & Iteration

步骤5:评审与迭代

After generating the SPEC, present it and ask:
SPEC generated from PRD. Please review:

- Are the architecture choices appropriate?
- Are there missing edge cases or error scenarios?
- Is the API design consistent with existing patterns?
- Should any section have more/less detail?

Reply OK to save, or provide feedback for iteration.

生成SPEC后,提交给用户并询问:
已从PRD生成SPEC,请评审:

- 架构选择是否合适?
- 是否遗漏边缘场景或错误场景?
- API设计是否与现有模式一致?
- 各章节是否需要增减细节?

回复OK以保存,或提供反馈进行迭代。

Step 6: Save

步骤6:保存

Ask user for save location:
Where should I save the SPEC?

A. tasks/spec-[feature-name].md (alongside PRD, recommended)
B. docs/spec-[feature-name].md
C. Custom path: [specify]

询问用户保存位置:
应将SPEC保存至何处?

A. tasks/spec-[feature-name].md(与PRD同目录,推荐)
B. docs/spec-[feature-name].md
C. 自定义路径:[指定路径]

Mapping Strategy: PRD → SPEC

映射策略:PRD → SPEC

How PRD elements translate to SPEC sections:
PRD SectionSPEC Section(s)Transformation
User Stories5. Business Logic, 9.4 Acceptance MappingStories → algorithms + test cases
Functional Requirements4. API Design, 5. Business LogicFRs → endpoints + logic
Acceptance Criteria9. Testing StrategyCriteria → specific test scenarios
Non-Goals11.1 Open QuestionsClarify what's explicitly excluded
Technical Considerations2. Architecture, 8. PerformanceConstraints → design decisions
Success Metrics8.1 Expected Load, 10.3 DeliveryMetrics → monitoring + rollout plan

PRD元素如何对应到SPEC章节:
PRD章节SPEC章节转换方式
用户故事5. 业务逻辑、9.4 验收标准映射故事 → 算法 + 测试用例
功能需求4. API设计、5. 业务逻辑功能需求 → 端点 + 逻辑
验收标准9. 测试策略标准 → 具体测试场景
非目标11.1 未解决问题明确排除的内容
技术考量2. 架构、8. 性能约束 → 设计决策
成功指标8.1 预期负载、10.3 交付指标 → 监控 + 上线计划

Quality Criteria

质量标准

A good SPEC should pass these checks:
  • Every PRD User Story has corresponding SPEC sections
  • Every Functional Requirement maps to an API endpoint or business logic rule
  • Every Acceptance Criterion maps to at least one test case
  • Architecture choices are justified with rationale
  • API schemas are specific enough to generate client code
  • Error handling covers all identified failure modes
  • Implementation order respects dependencies
  • No "TBD" or "TODO" items — resolve or move to Open Questions

一份优质的SPEC需满足以下检查项:
  • 每个PRD用户故事都有对应的SPEC章节
  • 每个功能需求都映射到API端点或业务逻辑规则
  • 每个验收标准都至少对应一个测试用例
  • 架构选择附有理由说明
  • API Schema足够详细,可用于生成客户端代码
  • 错误处理覆盖所有已识别的故障模式
  • 实施顺序遵循依赖关系
  • 无“TBD”或“TODO”项——要么解决,要么移至未解决问题

Edge Cases & Fallback

边缘场景与 fallback 方案

ScenarioHandling
PRD is vague or incompleteGenerate SPEC with best-effort choices, mark assumptions in Section 11.3
PRD conflicts with existing codeFlag conflicts explicitly, propose resolution in Section 11.1
Feature is too large for one SPECSplit into multiple SPECs (one per service boundary), link them
No existing codebase (greenfield)Skip Step 2, propose architecture from scratch based on PRD + clarifying questions
PRD has no User Stories (just bullet points)Infer structure, map bullets to SPEC sections, note in Summary
User wants SPEC without reading codebaseSkip Step 2, note that assumptions about existing code are unverified
Multiple PRDs need one SPECMerge PRD inputs, deduplicate requirements, note source for each

场景处理方式
PRD模糊或不完整基于最佳实践生成SPEC,在11.3节标记假设条件
PRD与现有代码冲突明确标记冲突,在11.1节提出解决方案
功能过大,无法放入单个SPEC拆分为多个SPEC(按服务边界划分),并建立链接
无现有代码库(全新项目)跳过步骤2,基于PRD和澄清问题从头提出架构
PRD无用户故事(仅要点列表)推断结构,将要点映射到SPEC章节,在概述中说明
用户希望不读取代码库生成SPEC跳过步骤2,注明关于现有代码的假设未经验证
多个PRD需生成一个SPEC合并PRD输入,去重需求,记录每个需求的来源

Anti-Patterns to Avoid

需避免的反模式

  • Don't restate the PRD. The SPEC adds technical depth, not a copy of requirements in different words.
  • Don't over-specify trivial operations. CRUD with no special logic doesn't need a full algorithm section.
  • Don't pick technologies without context. Always check what the project already uses before suggesting new tools.
  • Don't design in isolation. The SPEC must fit the existing system — same patterns, same conventions, same style.
  • Don't leave decisions implicit. If you made a choice (e.g., "add column to existing table"), state it and say why.
  • Don't write implementation code. The SPEC describes contracts and behavior, not code. Pseudocode is acceptable for complex algorithms.

  • 不要重复PRD内容。SPEC应增加技术深度,而非用不同语言复制需求。
  • 不要过度指定琐碎操作。无特殊逻辑的CRUD无需完整的算法章节。
  • 不要脱离上下文选择技术。建议新工具前务必检查项目已使用的技术栈。
  • 不要孤立设计。SPEC必须适配现有系统——遵循相同的模式、规范和风格。
  • 不要隐含决策。如果做出选择(例如“向现有表添加列”),需明确说明并解释理由。
  • 不要编写实现代码。SPEC描述的是约定和行为,而非代码。复杂算法可使用伪代码。

Relationship to Other Skills

与其他技能的关系

/prd  →  /prd-to-spec  →  /goal  →  /review-it  →  /ship-it
 │              │              │
 │  Requirements │  Technical   │  Implementation
 │  (what)       │  (how)       │  (code)
  • /prd produces the PRD (input to this skill)
  • /prd-to-spec produces the SPEC (this skill)
  • /goal implements Issues with SPEC as the technical reference
  • /code-to-spec reverse-engineers SPEC from existing code (complementary — forward vs. reverse)
/prd  →  /prd-to-spec  →  /goal  →  /review-it  →  /ship-it
 │              │              │
 │  需求(做什么) │  技术实现(怎么做) │  代码实现
  • /prd 生成PRD(本技能的输入)
  • /prd-to-spec 生成SPEC(本技能)
  • /goal 以SPEC为技术参考实现Issues
  • /code-to-spec 从现有代码反向生成SPEC(互补——正向vs反向)