
Lld Writer
- 25 installs
- 79 repo stars
- Updated May 6, 2026
- testany-io/testany-agent-skills
Helps with ai & agent building tasks.
About
lld-writer is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- lld-writer
- AI & Agent Building
- AI-coding skill
Lld Writer by the numbers
- 25 all-time installs (skills.sh)
- Ranked #9,800 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/testany-io/testany-agent-skills --skill lld-writerAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 25 |
|---|---|
| repo stars | ★ 79 |
| Last updated | May 6, 2026 |
| Repository | testany-io/testany-agent-skills ↗ |
What it does
Helps with ai & agent building tasks.
Files
LLD Writer
语言规则:默认跟随用户输入语言;用户显式指定时以用户指定为准;不要因为本SKILL.md是中文而强制输出中文;TRACEABILITY-METADATA的字段名、枚举值、ID、comment markers 始终保持英文。若本 skill 使用模板或派发子任务,继续传递同一个output_language。详见../../references/language-policy.md。
你是一个低层设计(LLD)写作助手。你的目标是把 HLD/Contract 的决策落地为可实现的设计细节,并通过模块化模板确保不漏关键工程约束。
核心原则
| 原则 | 说明 |
|---|---|
| 承接 PRD/HLD/Contract | LLD 只能细化,不得新增边界或改写契约 |
| Contract 是事实源 | LLD 只引用,不重定义接口 |
| 基于证据 | 技术现状/既有能力必须有依据;缺失就 AskUserQuestion |
| 模块化组合 | LLD = Core + Add-ons + Profile + Guardrails |
| Guardrails 最高优先级 | 项目约束文档优先于个人偏好 |
| 先做 Guardrails trigger check | 若本次 LLD 反向暴露项目级约束缺口,先判断是否必须更新 Guardrails |
| 复用优先 | 优先复用已有模块/共享服务/第三方方案 |
内容边界
LLD 应包含:模块结构、接口签名、关键流程/伪代码、错误处理、并发/事务/幂等、测试设计、追溯映射
LLD 不应包含:业务 Why(PRD)、系统级架构决策(HLD)、完整代码、与 Contract 冲突的接口
模块化模板机制
| 层级 | 说明 |
|---|---|
| Core | 必选,核心设计内容 |
| Add-ons | 按能力触发:API/Storage/Async/Infra/Observability 等 |
| Profile | 快速组合包(如 saas-serverless、web-app) |
| Guardrails | 项目约束,强制覆盖 |
必需产出:LLD 文档 + LLD Manifest + 追溯映射表
---
执行进度清单
执行时使用 TodoWrite 工具跟踪以下进度,完成一项后立即标记为 completed:
□ Phase 0: 基线与上下文
□ 0.1 Glob 扫描项目文档
□ 0.2 AskUserQuestion 确认基线
□ 0.3 读取 PRD/HLD/Contract
□ 0.4 确认 Guardrails
□ 0.5 执行 Guardrails trigger check
□ 0.6 输出「上下文收集报告」
□ Phase 1: Profile 与模块选择
□ 1.1 提取 Guardrails 强制模块
□ 1.2 AskUserQuestion 选择 Profile
□ 1.3 识别触发模块
□ 1.4 AskUserQuestion 确认 Add-ons
□ 1.5 生成 LLD Manifest 初稿
□ Phase 2: 组装 LLD 文档
□ 2.1 创建文档骨架
□ 2.2 填写文档信息与基线引用
□ 2.3 插入 LLD Manifest
□ 2.4 填写 Core 章节
□ 2.5 追加 Add-on 章节
□ 2.6 填写追溯映射表
□ 2.7 记录待确认问题
□ Phase 3: 一致性自检
□ 3.1 PRD 覆盖检查(100%)
□ 3.2 HLD 决策承接检查
□ 3.3 Contract 一致性检查
□ 3.4 Guardrails 强制项检查
□ 3.5 复用清单检查
□ 3.6 Traceability Metadata 生成与校验
□ 3.7 输出自检报告---
工作流程
Phase 0:基线与上下文
目标:收集上游文档,确认基线版本
1. 文档扫描:Glob 扫描 PRD/HLD/Contract/Guardrails/ADR 2. 基线确认:AskUserQuestion 确认最新批准基线(模板见 references/askuser-templates.md) 3. 读取文档:提取 PRD 需求、HLD 决策、Contract 接口 4. Guardrails 确认:AskUserQuestion 确认是否存在 5. Trigger check:基于 ../../references/guardrails-trigger-check.md 执行一次 Guardrails trigger check
no_trigger:继续阶段 1suggest_guardrails:记录影响域与推荐动作后继续require_guardrails_before_design:停止当前 LLD 写作,明确建议先运行guardrails-writer
6. 输出:「上下文收集报告」(格式见 references/output-templates.md)
---
Phase 1:Profile 与模块选择
目标:确定 LLD 模块组合,生成 Manifest 初稿
1. 提取 Guardrails 强制模块:若存在,提取强制/禁止项 2. 选择 Profile:AskUserQuestion 选择 Profile(详见 references/profiles.md) 3. 识别触发模块:基于 PRD/HLD/Contract 自动识别(触发条件见 references/modules.md) 4. 确认 Add-ons:AskUserQuestion 确认模块选择 5. 生成 Manifest:按 references/lld-manifest.md 模板生成
---
Phase 2:组装 LLD 文档
目标:按模块组合生成完整 LLD 文档
1. 创建骨架:以 references/lld-core-template.md 为基础 2. 填写文档信息:版本、作者、基线引用(格式见 references/output-templates.md) 3. 插入 Manifest:放在文档靠前位置 4. 填写 Core 章节:模块结构、接口、流程、错误处理、测试设计 5. 追加 Add-on 章节:按 Manifest 中 Included 的模块追加 6. 填写追溯映射表:PRD/HLD/Contract → LLD 7. 记录待确认问题
---
Phase 3:一致性自检
目标:确保 LLD 与上游一致,无遗漏无冲突
| 检查项 | 要求 | 阻塞级别 |
|---|---|---|
| PRD 需求覆盖 | = 100% | P0 |
| HLD 决策承接 | 技术选型/模块划分一致 | P1 |
| Contract 一致 | 禁止重定义接口 | P0 |
| Guardrails 覆盖 | 强制项全覆盖 | P0 |
| 复用检查 | 无重复造轮子 | P2 |
Traceability Metadata(强制):
LLD 必须内嵌 TRACEABILITY-METADATA block(lld-profile-v1)。要求:
artifact.type=LLD,source_documents包含 PRD/HLD/API Contract 的 artifact IDentities.decisions[]为模块级决策建模(DEC-*),entities.flows[]为模块交互建模(FLOW-*,kind=module_interaction)relations[]使用refines/derived_from将DEC-*/FLOW-*连回 HLD 的DEC-*/FLOW-*或 PRD 的REQ-*- LLD Manifest 模块选择/排除建议记录在
artifact.notes中 - 参考示例:
../../references/traceability-schema/lld-profile-v1.example.yaml
写入文件后执行:python3 plugins/testany-eng/scripts/trace_lint.py --format json <LLD 路径>。blocking issue 必须修正。
输出:「自检报告」(格式见 references/output-templates.md)
---
禁止行为
- 禁止新增边界:LLD 不得引入 HLD 未定义的新服务/接口
- 禁止改写 Contract:接口签名/错误码必须与 Contract 一致
- 禁止猜测:技术现状不明时必须 AskUserQuestion
---
使用示例
示例 1:
基于 PRD/HLD/Contract 写订单服务 LLD,包含 Storage、Async、Observability。
示例 2:
为前端模块写 LLD,强调路由/状态/错误态,引用现有 API Contract。
---
参考文档
| 文档 | 内容 |
|---|---|
references/lld-core-template.md | LLD 核心模板(14 章节) |
references/modules.md | 模块清单与触发条件 |
references/profiles.md | Profile 定义与默认模块 |
references/lld-manifest.md | Manifest 模板 |
references/guardrails-template.md | Guardrails 模板 |
references/askuser-templates.md | AskUserQuestion 模板 |
references/output-templates.md | 各阶段输出格式模板 |
../../references/guardrails-trigger-check.md | Guardrails 触发检查与分流规则 |
interface:
display_name: "LLD Writer"
short_description: "Draft low-level designs from HLD and contracts"
icon_small: "./assets/testany-logo-small.png"
icon_large: "./assets/testany-logo.svg"
default_prompt: "Use $lld-writer to draft an LLD from this PRD, HLD, and API contract."
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="958.3745509306195" height="958.3745509306195" viewBox="0 0 958.3745509306195 958.3745509306195">
<g transform="scale(8.11041548093341) translate(10, 10)">
<defs id="SvgjsDefs1360"></defs>
<g id="SvgjsG1361" featureKey="symbolFeature-0" transform="matrix(0.9816393857057392,0,0,0.9816393857057392,-3.0293391105859975,0.00098156823722121)" fill="#7cbb00">
<rect xmlns="http://www.w3.org/2000/svg" x="42.607" y="47.076" transform="matrix(0.7761 0.6306 -0.6306 0.7761 46.5672 -14.0771)" width="1" height="22.92">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="45.986" y="57.948" transform="matrix(0.6084 0.7937 -0.7937 0.6084 68.7434 -22.4141)" width="22.194" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="61.209" y="34.391" transform="matrix(0.285 0.9585 -0.9585 0.285 88.4619 -26.0748)" width="1" height="23.738">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="38.984" y="37.368" transform="matrix(0.0074 1 -1 0.0074 88.2466 -13.1692)" width="23.546" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="27.744" y="45.76" transform="matrix(0.9562 0.2928 -0.2928 0.9562 15.2685 -9.4777)" width="23.094" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="35.832" y="34.683" transform="matrix(0.9456 0.3253 -0.3253 0.9456 16.6429 -9.3663)" width="1" height="20.809">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="31.072" y="60.446" transform="matrix(0.8221 0.5694 -0.5694 0.8221 42.108 -12.8663)" width="21.141" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="58.047" y="51.212" transform="matrix(0.5722 0.8201 -0.8201 0.5722 75.2668 -21.8197)" width="1" height="20.036">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="53.541" y="45.129" transform="matrix(0.2845 0.9587 -0.9587 0.2845 89.4167 -28.5477)" width="20.584" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="39.708" y="35.004" transform="matrix(0.9997 0.0243 -0.0243 0.9997 0.8776 -1.2119)" width="21.201" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="36.331" y="59.987" transform="matrix(0.5784 0.8158 -0.8158 0.5784 77.9659 2.2244)" width="1" height="33.1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="55.959" y="70.302" transform="matrix(0.3351 0.9422 -0.9422 0.3351 114.7194 -20.9532)" width="32.492" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="76.946" y="19.044" transform="matrix(0.0107 0.9999 -0.9999 0.0107 112.198 -42.2379)" width="1" height="33.083">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="44.371" y="2.123" transform="matrix(0.9527 0.3039 -0.3039 0.9527 7.9224 -12.733)" width="0.999" height="33.928">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="3.101" y="44.487" transform="matrix(0.8004 0.5995 -0.5995 0.8004 30.9 -2.8183)" width="33.161" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="13.446" y="11.595" transform="matrix(0.9605 0.2782 -0.2782 0.9605 11.716 -2.2955)" width="1" height="57.08">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="1.626" y="81.812" transform="matrix(0.8375 0.5464 -0.5464 0.8375 49.6273 -2.2773)" width="54.033" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="71.659" y="52.69" transform="matrix(0.6376 0.7704 -0.7704 0.6376 87.6254 -26.6706)" width="1" height="54.215">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="55.738" y="36.926" transform="matrix(0.377 0.9262 -0.9262 0.377 86.266 -53.4047)" width="54.19" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="46.824" y="-12.954" transform="matrix(0.0146 0.9999 -0.9999 0.0146 58.9718 -35.1579)" width="1" height="50.592">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="6.016" y="66.991" width="29.866" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="9.472" y="27.565" transform="matrix(0.2024 0.9793 -0.9793 0.2024 47.599 -2.3107)" width="31.493" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="61.126" y="6.058" transform="matrix(0.5429 0.8398 -0.8398 0.5429 44.2475 -43)" width="1" height="26.18">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="69.065" y="52.2" transform="matrix(0.7128 0.7014 -0.7014 0.7128 60.8208 -43.1259)" width="28.006" height="1">
</rect>
<rect xmlns="http://www.w3.org/2000/svg" x="57.052" y="65.986" transform="matrix(0.9215 0.3885 -0.3885 0.9215 36.441 -15.9049)" width="1" height="32.356">
</rect>
<circle xmlns="http://www.w3.org/2000/svg" cx="6.41" cy="35.047" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="32.979" cy="55.017" r="4.79">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="93.05" cy="62.521" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="93.987" cy="35.41" r="2.927">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="51.269" cy="97.073" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="6.014" cy="67.55" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="50.332" cy="49.641" r="5.511">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="39.816" cy="35" r="4.789">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="60.904" cy="35.842" r="4.79">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="77.649" cy="86.109" r="2.927">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="50.635" cy="67.21" r="4.79">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="66.735" cy="55.478" r="4.79">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="28.249" cy="42.878" r="2.028">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="50.633" cy="26.257" r="1.929">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="35.881" cy="67.432" r="2.128">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="63.833" cy="67.256" r="2.053">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="50.031" cy="2.927" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="72.616" cy="12.331" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="73.085" cy="42.878" r="2.225">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="23.331" cy="86.109" r="2.928">
</circle>
<circle xmlns="http://www.w3.org/2000/svg" cx="22.03" cy="12.645" r="2.928">
</circle>
</g>
</g>
</svg>AskUserQuestion 模板
本文档定义 lld-writer 写作过程中需要向用户确认的问题模板。
---
基线确认
触发时机:Phase 0 - 确认上游文档基线
question: "请确认以下文档为最新批准基线:"
header: "基线确认"
multiSelect: true
options:
- label: "[PRD 路径]"
description: "PRD 版本 X.X"
- label: "[HLD 路径]"
description: "HLD 版本 X.X"
- label: "[Contract 路径]"
description: "API Contract"
- label: "以上均为最新"
description: "确认基线"---
Guardrails 确认
触发时机:Phase 0 - 确认 Guardrails 是否存在
question: "是否有 Project Guardrails/工程约束文档需要遵循?"
header: "Guardrails"
multiSelect: false
options:
- label: "有,请提供路径"
description: "已有项目约束文档"
- label: "无,需要我创建模板"
description: "创建 guardrails-template"
- label: "无,不需要"
description: "确认不存在"---
Guardrails Trigger 澄清
触发时机:Phase 0 - 无法判断本次 LLD 是否暴露项目级默认规则缺口
question: "这次 LLD 变更是否会改变项目里多个模块都要遵守的默认规则?"
header: "Guardrails Trigger"
multiSelect: false
options:
- label: "是,会改变项目默认规则"
description: "应优先判断是否需要更新 Guardrails"
- label: "否,只影响当前模块"
description: "通常无需触发 Guardrails"
- label: "不确定,需要结合现有 Guardrails 一起判断"
description: "先读取现有 Guardrails 与批准基线再决定"---
Profile 选择
触发时机:Phase 1 - 选择 LLD 模块组合
question: "请选择 LLD Profile(可作为默认模块组合):"
header: "LLD Profile"
multiSelect: false
options:
- label: "saas-serverless"
description: "多服务/云原生/事件驱动"
- label: "web-app"
description: "前后端 + API + 数据"
- label: "data-pipeline"
description: "数据流/任务/批处理"
- label: "desktop-app"
description: "桌面端/本地能力"
- label: "sdk-library"
description: "公共库/SDK"
- label: "custom"
description: "手工选择模块"Profile 详情见 profiles.md。
---
Add-ons 选择
触发时机:Phase 1 - 确认需要包含的模块
question: "以下能力模块是否需要包含?"
header: "LLD 模块"
multiSelect: true
options:
- label: "API Contract"
description: "有对外/跨团队接口"
- label: "Storage & Migration"
description: "涉及数据持久化/迁移/格式"
- label: "Async/Event"
description: "消息/队列/事件驱动"
- label: "Infra/IaC"
description: "资源变更/IaC"
- label: "Observability"
description: "日志/指标/告警"
- label: "Security/Compliance"
description: "权限/PII/合规"
- label: "Deployment/Release"
description: "发布/回滚/灰度"
- label: "Frontend UX"
description: "前端路由/状态/UI"
- label: "External Integration"
description: "第三方集成"
- label: "SDK/Library"
description: "公共库/SDK"模块详情见 modules.md。
Project Guardrails 模板
1. 技术栈与强制约束
- 前端技术栈:
- 后端技术栈:
- 基础设施/IaC:
- 共享组件/平台要求:
2. 强制模块清单
- 必须包含的 LLD 模块:
- 禁止使用/禁止变更的模块:
3. 交付与发布规则
- 分支策略:
- CI 要求/测试门槛:
- 发布/回滚策略:
4. 安全与合规
- 权限模型:
- 数据分级/加密:
5. 观测与稳定性
- 必要日志/指标/告警:
- SLA/SLO:
LLD Document Template (Core)
This template is the core chapter of LLD and all LLD must contain these contents. See modules.md for the Add-on module section.---
1. Document Information
| Properties | Values |
|---|---|
| Document Name | LLD - {Module/Function Name} |
| Version | v1.0 |
| Author | {Author} |
| Creation Date | {YYYY-MM-DD} |
| PRD baseline | {PRD file path} v{version} |
| HLD baseline | {HLD file path} v{version} |
| Contract baseline | {Contract file path} |
| Guardrails | {Guardrails path} / None |
| Status | Draft / Under Review / Approved |
---
2. LLD Manifest
Use the lld-manifest.md template to list the modules included in this LLD.| Module | Included | N/A Reason | Evidence Location | Guardrails Requirements |
|---|---|---|---|---|
| Core | Y | - | This document | Required |
| API Contract | {Y/N} | {Reason} | {§X.X} | {Is it mandatory} |
| Storage & Migration | {Y/N} | {Reason} | {§X.X} | {Is it mandatory} |
| ... |
---
3. Scope and Assumptions
3.1 In-Scope (covered by this LLD)
Clearly list the functions/modules covered by this LLD design:
- {Function/Module 1}
- {Function/Module 2}
- ...
3.2 Out-of-Scope (not covered by this LLD)
Explicitly list what is not within the scope of this LLD (to avoid ambiguity):
- {feature not covered 1} (reason: {covered by other LLD/subsequent iteration})
- ...
3.3 Key assumptions
List the assumptions that the design relies on. If the assumptions are not true, the design needs to be adjusted:
| # | Assumptions | Basis | Impact |
|---|---|---|---|
| 1 | {Assumption description} | {Source: HLD/PRD/User confirmation} | {Impact if not true} |
3.4 Dependencies
| Dependencies | Type | Status | Responsible Party |
|---|---|---|---|
| {Service/Module Name} | Internal Service / External API / Shared Library | Ready / Under Development | {Team} |
---
4. Module/package structure
4.1 Directory structure
{module-name}/
├── cmd/ # Entry/Startup
│ └── main.go
├── internal/ # Internal implementation (cannot be imported externally)
│ ├── handler/ # Request processing layer
│ ├── service/ # Business logic layer
│ ├── repository/ # Data access layer
│ └── model/ # Internal model
├── pkg/ # Exportable public package
│ └── dto/ # Data transfer object
├── config/ # Configuration
└── test/ # test
├── unit/
└── integration/Adjust the directory structure according to the actual technology stack (such assrc/main/javafor Java andsrc/for Python)
4.2 Dependency graph
flowchart TD
subgraph External[external dependency]
API[API Gateway]
DB[(Database)]
MQ[Message Queue]
end
subgraph Module[this module]
Handler[Handler Layer]
Service[Service Layer]
Repo[Repository Layer]
end
API --> Handler
Handler --> Service
Service --> Repo
Repo --> DB
Service --> MQ4.3 Package/Module Responsibilities
| Package/Module | Responsibilities | Dependencies |
|---|---|---|
handler | Request parsing, parameter verification, response encapsulation | service |
service | Business logic orchestration | repository, client |
repository | Data persistence | model |
---
5. Key interfaces and function signatures
5.1 Core interface definition
// OrderService order service interface
type OrderService interface {
// CreateOrder creates an order
// Parameters: ctx - context, req - create request
// Return: order entity, error
CreateOrder(ctx context.Context, req *CreateOrderRequest) (*Order, error)
// GetOrder query order
GetOrder(ctx context.Context, orderID string) (*Order, error)
// CancelOrder cancels the order
CancelOrder(ctx context.Context, orderID string, reason string) error
}Adjust the syntax to the actual language (TypeScript/Java/Python, etc.)
5.2 Key method signature
| method | input | output | description |
|---|---|---|---|
CreateOrder | CreateOrderRequest | Order, error | Create a new order |
GetOrder | orderID: string | Order, error | Query by ID |
CancelOrder | orderID, reason | error | Cancel order |
5.3 Contract Mapping
Reference the API Contract to explain the mapping relationship between interfaces and functions
| Contract interface | Function/method | Description |
|---|---|---|
POST /api/v1/orders | OrderService.CreateOrder | - |
GET /api/v1/orders/{id} | OrderService.GetOrder | - |
---
6. Data structure and DTO
6.1 Core data structure
// Order order entity (internal model)
type Order struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Items []OrderItem `json:"items"`
TotalAmount int64 `json:"total_amount"` // Unit: minutes
Status OrderStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// OrderStatus order status enumeration
type OrderStatus string
const (
OrderStatusPending OrderStatus = "pending"
OrderStatusPaid OrderStatus = "paid"
OrderStatusCancelled OrderStatus = "cancelled"
)6.2 DTO (Data Transfer Object)
// CreateOrderRequest creates an order request
type CreateOrderRequest struct {
UserID string `json:"user_id" validate:"required"`
Items []ItemInput `json:"items" validate:"required,min=1"`
}
// CreateOrderResponse creates an order response
type CreateOrderResponse struct {
OrderID string `json:"order_id"`
Status string `json:"status"`
}6.3 Data conversion
| Source | Target | Conversion Method |
|---|---|---|
CreateOrderRequest | Order | mapper.ToOrder() |
Order | CreateOrderResponse | mapper.ToResponse() |
---
7. Key process/pseudocode
7.1 Main process (Happy Path)
sequenceDiagram
participant C as Client
participant H as Handler
participant S as Service
participant R as Repository
participant DB as Database
C->>H: POST /orders
H->>H: Parameter verification
H->>S: CreateOrder(req)
S->>S: Business verification
S->>R: Save(order)
R->>DB: INSERT
DB-->>R: OK
R-->>S: order
S-->>H: order
H-->>C: 201 Created7.2 Key branch pseudocode
def create_order(request):
# 1. Parameter verification
if not validate(request):
raise ValidationError("invalid request")
# 2. Business verification
user = user_service.get_user(request.user_id)
if not user.is_active:
raise BusinessError("user not active")
# 3. Inventory Check
for item in request.items:
stock = inventory.check(item.product_id)
if stock < item.quantity:
raise BusinessError("insufficient stock")
# 4. Create order
order = Order(
id=generate_id(),
user_id=request.user_id,
items=request.items,
status=OrderStatus.PENDING
)
# 5. Persistence
repository.save(order)
# 6. Send event (if any)
event_bus.publish(OrderCreatedEvent(order))
return order7.3 State machine (if applicable)
stateDiagram-v2
[*] --> Pending: Create order
Pending --> Paid: Payment successful
Pending --> Canceled: User canceled
Paid --> Shipped: Shipped
Paid --> Refunding: Apply for a refund
Shipped --> Completed: Confirm receipt
Refunding --> Refunded: Refund successful
Cancelled --> [*]
Completed --> [*]
Refunded --> [*]---
8. Error handling and exception branching
8.1 Error classification
| Error type | Error code range | Processing strategy | HTTP status code |
|---|---|---|---|
| Parameter verification error | 1001-1099 | Return directly without retrying | 400 |
| Business rule error | 2001-2099 | Return directly without retrying | 422 |
| Resource does not exist | 3001-3099 | Return directly | 404 |
| System internal error | 5001-5099 | Record log, can retry | 500 |
| External dependency errors | 6001-6099 | Downgrade/retry/circuit break | 502/503 |
8.2 Error code definition
Quote the error code in the Contract and supplement the internal error code
| Error code | Name | Description | Handling suggestions |
|---|---|---|---|
ORDER_1001 | INVALID_PARAM | Invalid request parameter | Check parameter format |
ORDER_2001 | INSUFFICIENT_STOCK | Insufficient stock | Reduce quantity or replace items |
ORDER_2002 | USER_NOT_ACTIVE | User is not activated | Contact customer service |
8.3 Exception handling process
try:
result = service.create_order(request)
except ValidationError as e:
return error_response(400, e.code, e.message)
except BusinessError as e:
return error_response(422, e.code, e.message)
except ExternalServiceError as e:
logger.error(f"External service failed: {e}")
#Downgrade processing
return fallback_response()
except Exception as e:
logger.error(f"Unexpected error: {e}")
return error_response(500, "INTERNAL_ERROR", "Service internal error")---
9. Concurrency/Transaction/Impotent
9.1 Concurrency model
| Scenario | Concurrency strategy | Implementation method |
|---|---|---|
| Order creation | Optimistic locking | Version number verification |
| Inventory deduction | Pessimistic lock | SELECT FOR UPDATE |
| Status Updates | CAS | Atomic Operations |
9.2 Transaction Boundaries
@transactional
def create_order_with_stock_deduction(request):
# The following operations are in the same transaction
order = create_order(request)
deduct_stock(request.items)
return order| Operation combination | Transaction strategy | Rollback conditions |
|---|---|---|
| Create order + deduct inventory | Same transaction | Any failure |
| Create order + send notification | Separate (eventually consistent) | Rollback if order fails, notification can be retried |
9.3 Idempotent design
| Interface | Idempotent keys | Idempotent strategies |
|---|---|---|
| Create order | request_id | Token anti-duplication (Redis SETNX) |
| Payment callback | payment_id | State machine idempotent (skip if already paid) |
def create_order_idempotent(request_id, request):
# 1. Check idempotent keys
if redis.exists(f"order:idempotent:{request_id}"):
return get_existing_order(request_id)
# 2. Set idempotent key (with expiration time)
redis.setex(f"order:idempotent:{request_id}", 3600, "processing")
# 3. Execute business logic
order = create_order(request)
# 4. Update idempotent keys
redis.setex(f"order:idempotent:{request_id}", 86400, order.id)
return order---
10. Configuration/Feature Flag
10.1 Configuration items
| Configuration items | Type | Default value | Description | Environment differences |
|---|---|---|---|---|
order.max_items | int | 100 | Maximum number of items in a single order | None |
order.timeout_minutes | int | 30 | Unpaid order timeout | None |
db.pool_size | int | 10 | Database connection pool size | dev:5, prod:20 |
10.2 Feature Flag
| Flag | Default value | Description | Grayscale strategy |
|---|---|---|---|
enable_new_pricing | false | New pricing strategy | grayscale by user ID |
enable_async_notification | true | Asynchronous notification | Full |
if feature_flag.is_enabled("enable_new_pricing", user_id=user.id):
price = new_pricing_service.calculate(items)
else:
price = legacy_pricing_service.calculate(items)---
11. Test design
11.1 Unit test scope
| Module | Test Focus | Coverage Goal |
|---|---|---|
service | Business logic branch | ≥ 80% |
repository | CRUD operations | ≥ 70% |
handler | Parameter verification, error handling | ≥ 70% |
11.2 Integration testing
| Test scenarios | Dependencies | Test methods |
|---|---|---|
| Complete order creation process | DB, MQ | TestContainer |
| Payment callback processing | Payment service Mock | WireMock |
11.3 Mock/Fixture strategy
| Dependencies | Mock methods | Description |
|---|---|---|
| Database | TestContainer / SQLite | Real DB for integration testing |
| External API | WireMock / httptest | Simulate external service response |
| Message queue | Memory queue | Verify message sending |
11.4 Key test cases
| # | Test scenario | Input | Expected output |
|---|---|---|---|
| 1 | Order created normally | Valid request | Order created successfully |
| 2 | Out of stock | Quantity exceeded stock | Return out of stock error |
| 3 | User not activated | User ID not activated | User status error returned |
| 4 | Idempotent repeated request | Same request_id | Return existing order |
---
12. Traceability mapping
| Upstream entry | Source | LLD Chapter | Status |
|---|---|---|---|
| {PRD-001} Create Order Function | PRD | §5, §7 | ✅ Covered |
| {PRD-002} Order Status Management | PRD | §7.3 | ✅ Covered |
| {HLD-001} Order Service Architecture | HLD | §4 | ✅ Covered |
| {HLD-002} Cache Policy | HLD | §9 | ✅ Covered |
POST /api/v1/orders | Contract | §5.3 | ✅ Covered |
GET /api/v1/orders/{id} | Contract | §5.3 | ✅ Covered |
---
13. Questions to be confirmed
| # | Issue | Affected Chapters | Status | Person in Charge |
|---|---|---|---|---|
| 1 | {Problem description} | §X.X | To be confirmed | {Personnel} |
---
14. Change record
| Version | Date | Change content | Change person |
|---|---|---|---|
| v1.0 | {date} | initial release | {person} |
LLD 文档模板(Core)
本模板为 LLD 核心章节,所有 LLD 必须包含这些内容。Add-on 模块章节见 modules.md。---
1. 文档信息
| 属性 | 值 |
|---|---|
| 文档名称 | LLD - {模块/功能名称} |
| 版本 | v1.0 |
| 作者 | {作者} |
| 创建日期 | {YYYY-MM-DD} |
| PRD 基线 | {PRD 文件路径} v{版本} |
| HLD 基线 | {HLD 文件路径} v{版本} |
| Contract 基线 | {Contract 文件路径} |
| Guardrails | {Guardrails 路径} / 无 |
| 状态 | 草稿 / 评审中 / 已批准 |
---
2. LLD Manifest
使用 lld-manifest.md 模板,列出本 LLD 包含的模块。| 模块 | Included | N/A 理由 | 证据位置 | Guardrails 要求 |
|---|---|---|---|---|
| Core | Y | - | 本文档 | 必须 |
| API Contract | {Y/N} | {理由} | {§X.X} | {是否强制} |
| Storage & Migration | {Y/N} | {理由} | {§X.X} | {是否强制} |
| ... |
---
3. 范围与假设
3.1 In-Scope(本 LLD 覆盖)
明确列出本 LLD 设计覆盖的功能/模块:
- {功能/模块 1}
- {功能/模块 2}
- ...
3.2 Out-of-Scope(本 LLD 不覆盖)
明确列出不在本 LLD 范围内的内容(避免歧义):
- {不覆盖的功能 1}(原因:{由其他 LLD 覆盖 / 后续迭代})
- ...
3.3 关键假设
列出设计依赖的假设,若假设不成立则设计需调整:
| # | 假设 | 依据 | 影响 |
|---|---|---|---|
| 1 | {假设描述} | {来源:HLD/PRD/用户确认} | {若不成立的影响} |
3.4 依赖
| 依赖项 | 类型 | 状态 | 负责方 |
|---|---|---|---|
| {服务/模块名} | 内部服务 / 外部 API / 共享库 | 已就绪 / 开发中 | {团队} |
---
4. 模块/包结构
4.1 目录结构
{module-name}/
├── cmd/ # 入口/启动
│ └── main.go
├── internal/ # 内部实现(不可外部导入)
│ ├── handler/ # 请求处理层
│ ├── service/ # 业务逻辑层
│ ├── repository/ # 数据访问层
│ └── model/ # 内部模型
├── pkg/ # 可导出的公共包
│ └── dto/ # 数据传输对象
├── config/ # 配置
└── test/ # 测试
├── unit/
└── integration/根据实际技术栈调整目录结构(如 Java 用src/main/java,Python 用src/)
4.2 依赖关系图
flowchart TD
subgraph External[外部依赖]
API[API Gateway]
DB[(Database)]
MQ[Message Queue]
end
subgraph Module[本模块]
Handler[Handler Layer]
Service[Service Layer]
Repo[Repository Layer]
end
API --> Handler
Handler --> Service
Service --> Repo
Repo --> DB
Service --> MQ4.3 包/模块职责
| 包/模块 | 职责 | 依赖 |
|---|---|---|
handler | 请求解析、参数校验、响应封装 | service |
service | 业务逻辑编排 | repository, client |
repository | 数据持久化 | model |
---
5. 关键接口与函数签名
5.1 核心接口定义
// OrderService 订单服务接口
type OrderService interface {
// CreateOrder 创建订单
// 参数: ctx - 上下文, req - 创建请求
// 返回: 订单实体, 错误
CreateOrder(ctx context.Context, req *CreateOrderRequest) (*Order, error)
// GetOrder 查询订单
GetOrder(ctx context.Context, orderID string) (*Order, error)
// CancelOrder 取消订单
CancelOrder(ctx context.Context, orderID string, reason string) error
}根据实际语言调整语法(TypeScript/Java/Python 等)
5.2 关键方法签名
| 方法 | 输入 | 输出 | 说明 |
|---|---|---|---|
CreateOrder | CreateOrderRequest | Order, error | 创建新订单 |
GetOrder | orderID: string | Order, error | 按 ID 查询 |
CancelOrder | orderID, reason | error | 取消订单 |
5.3 Contract 映射
引用 API Contract,说明接口到函数的映射关系
| Contract 接口 | 函数/方法 | 说明 |
|---|---|---|
POST /api/v1/orders | OrderService.CreateOrder | - |
GET /api/v1/orders/{id} | OrderService.GetOrder | - |
---
6. 数据结构与 DTO
6.1 核心数据结构
// Order 订单实体(内部模型)
type Order struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Items []OrderItem `json:"items"`
TotalAmount int64 `json:"total_amount"` // 单位:分
Status OrderStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// OrderStatus 订单状态枚举
type OrderStatus string
const (
OrderStatusPending OrderStatus = "pending"
OrderStatusPaid OrderStatus = "paid"
OrderStatusCancelled OrderStatus = "cancelled"
)6.2 DTO(数据传输对象)
// CreateOrderRequest 创建订单请求
type CreateOrderRequest struct {
UserID string `json:"user_id" validate:"required"`
Items []ItemInput `json:"items" validate:"required,min=1"`
}
// CreateOrderResponse 创建订单响应
type CreateOrderResponse struct {
OrderID string `json:"order_id"`
Status string `json:"status"`
}6.3 数据转换
| 来源 | 目标 | 转换方法 |
|---|---|---|
CreateOrderRequest | Order | mapper.ToOrder() |
Order | CreateOrderResponse | mapper.ToResponse() |
---
7. 关键流程/伪代码
7.1 主流程(Happy Path)
sequenceDiagram
participant C as Client
participant H as Handler
participant S as Service
participant R as Repository
participant DB as Database
C->>H: POST /orders
H->>H: 参数校验
H->>S: CreateOrder(req)
S->>S: 业务校验
S->>R: Save(order)
R->>DB: INSERT
DB-->>R: OK
R-->>S: order
S-->>H: order
H-->>C: 201 Created7.2 关键分支伪代码
def create_order(request):
# 1. 参数校验
if not validate(request):
raise ValidationError("invalid request")
# 2. 业务校验
user = user_service.get_user(request.user_id)
if not user.is_active:
raise BusinessError("user not active")
# 3. 库存检查
for item in request.items:
stock = inventory.check(item.product_id)
if stock < item.quantity:
raise BusinessError("insufficient stock")
# 4. 创建订单
order = Order(
id=generate_id(),
user_id=request.user_id,
items=request.items,
status=OrderStatus.PENDING
)
# 5. 持久化
repository.save(order)
# 6. 发送事件(如有)
event_bus.publish(OrderCreatedEvent(order))
return order7.3 状态机(如适用)
stateDiagram-v2
[*] --> Pending: 创建订单
Pending --> Paid: 支付成功
Pending --> Cancelled: 用户取消
Paid --> Shipped: 发货
Paid --> Refunding: 申请退款
Shipped --> Completed: 确认收货
Refunding --> Refunded: 退款成功
Cancelled --> [*]
Completed --> [*]
Refunded --> [*]---
8. 错误处理与异常分支
8.1 错误分类
| 错误类型 | 错误码范围 | 处理策略 | HTTP 状态码 |
|---|---|---|---|
| 参数校验错误 | 1001-1099 | 直接返回,不重试 | 400 |
| 业务规则错误 | 2001-2099 | 直接返回,不重试 | 422 |
| 资源不存在 | 3001-3099 | 直接返回 | 404 |
| 系统内部错误 | 5001-5099 | 记录日志,可重试 | 500 |
| 外部依赖错误 | 6001-6099 | 降级/重试/熔断 | 502/503 |
8.2 错误码定义
引用 Contract 中的错误码,补充内部错误码
| 错误码 | 名称 | 描述 | 处理建议 |
|---|---|---|---|
ORDER_1001 | INVALID_PARAM | 请求参数无效 | 检查参数格式 |
ORDER_2001 | INSUFFICIENT_STOCK | 库存不足 | 减少数量或更换商品 |
ORDER_2002 | USER_NOT_ACTIVE | 用户未激活 | 联系客服 |
8.3 异常处理流程
try:
result = service.create_order(request)
except ValidationError as e:
return error_response(400, e.code, e.message)
except BusinessError as e:
return error_response(422, e.code, e.message)
except ExternalServiceError as e:
logger.error(f"External service failed: {e}")
# 降级处理
return fallback_response()
except Exception as e:
logger.error(f"Unexpected error: {e}")
return error_response(500, "INTERNAL_ERROR", "服务内部错误")---
9. 并发/事务/幂等
9.1 并发模型
| 场景 | 并发策略 | 实现方式 |
|---|---|---|
| 订单创建 | 乐观锁 | 版本号校验 |
| 库存扣减 | 悲观锁 | SELECT FOR UPDATE |
| 状态更新 | CAS | 原子操作 |
9.2 事务边界
@transactional
def create_order_with_stock_deduction(request):
# 以下操作在同一事务中
order = create_order(request)
deduct_stock(request.items)
return order| 操作组合 | 事务策略 | 回滚条件 |
|---|---|---|
| 创建订单 + 扣库存 | 同一事务 | 任一失败 |
| 创建订单 + 发通知 | 分离(最终一致) | 订单失败回滚,通知可重试 |
9.3 幂等设计
| 接口 | 幂等键 | 幂等策略 |
|---|---|---|
| 创建订单 | request_id | Token 防重(Redis SETNX) |
| 支付回调 | payment_id | 状态机幂等(已支付则跳过) |
def create_order_idempotent(request_id, request):
# 1. 检查幂等键
if redis.exists(f"order:idempotent:{request_id}"):
return get_existing_order(request_id)
# 2. 设置幂等键(带过期时间)
redis.setex(f"order:idempotent:{request_id}", 3600, "processing")
# 3. 执行业务逻辑
order = create_order(request)
# 4. 更新幂等键
redis.setex(f"order:idempotent:{request_id}", 86400, order.id)
return order---
10. 配置/Feature Flag
10.1 配置项
| 配置项 | 类型 | 默认值 | 说明 | 环境差异 |
|---|---|---|---|---|
order.max_items | int | 100 | 单笔订单最大商品数 | 无 |
order.timeout_minutes | int | 30 | 未支付订单超时时间 | 无 |
db.pool_size | int | 10 | 数据库连接池大小 | dev:5, prod:20 |
10.2 Feature Flag
| Flag | 默认值 | 说明 | 灰度策略 |
|---|---|---|---|
enable_new_pricing | false | 新定价策略 | 按用户 ID 灰度 |
enable_async_notification | true | 异步通知 | 全量 |
if feature_flag.is_enabled("enable_new_pricing", user_id=user.id):
price = new_pricing_service.calculate(items)
else:
price = legacy_pricing_service.calculate(items)---
11. 测试设计
11.1 单元测试范围
| 模块 | 测试重点 | 覆盖率目标 |
|---|---|---|
service | 业务逻辑分支 | ≥ 80% |
repository | CRUD 操作 | ≥ 70% |
handler | 参数校验、错误处理 | ≥ 70% |
11.2 集成测试
| 测试场景 | 依赖 | 测试方式 |
|---|---|---|
| 订单创建完整流程 | DB, MQ | TestContainer |
| 支付回调处理 | 支付服务 Mock | WireMock |
11.3 Mock/Fixture 策略
| 依赖 | Mock 方式 | 说明 |
|---|---|---|
| 数据库 | TestContainer / SQLite | 集成测试用真实 DB |
| 外部 API | WireMock / httptest | 模拟外部服务响应 |
| 消息队列 | 内存队列 | 验证消息发送 |
11.4 关键测试用例
| # | 测试场景 | 输入 | 预期输出 |
|---|---|---|---|
| 1 | 正常创建订单 | 有效请求 | 订单创建成功 |
| 2 | 库存不足 | 超出库存的数量 | 返回库存不足错误 |
| 3 | 用户未激活 | 未激活用户 ID | 返回用户状态错误 |
| 4 | 幂等重复请求 | 相同 request_id | 返回已存在的订单 |
---
12. 追溯映射
| 上游条目 | 来源 | LLD 章节 | 状态 |
|---|---|---|---|
| {PRD-001} 创建订单功能 | PRD | §5, §7 | ✅ 已覆盖 |
| {PRD-002} 订单状态管理 | PRD | §7.3 | ✅ 已覆盖 |
| {HLD-001} 订单服务架构 | HLD | §4 | ✅ 已覆盖 |
| {HLD-002} 缓存策略 | HLD | §9 | ✅ 已覆盖 |
POST /api/v1/orders | Contract | §5.3 | ✅ 已覆盖 |
GET /api/v1/orders/{id} | Contract | §5.3 | ✅ 已覆盖 |
---
13. 待确认问题
| # | 问题 | 影响章节 | 状态 | 负责人 |
|---|---|---|---|---|
| 1 | {问题描述} | §X.X | 待确认 | {人员} |
---
14. 变更记录
| 版本 | 日期 | 变更内容 | 变更人 |
|---|---|---|---|
| v1.0 | {日期} | 初始版本 | {人员} |
#LLD Manifest Template
| Module | Included (Y/N) | N/A Reason | Evidence Location | Guardrails Requirements |
|---|---|---|---|---|
| Core | Y | - | §2 | Required |
| API Contract | ||||
| Storage & Migration | ||||
| Async/Event | ||||
| Infra/IaC | ||||
| Observability | ||||
| Security/Compliance | ||||
| Deployment/Release | ||||
| Frontend UX | ||||
| External Integration | ||||
| SDK/Library |
LLD Manifest 模板
| 模块 | Included (Y/N) | N/A 理由 | 证据位置 | Guardrails 要求 |
|---|---|---|---|---|
| Core | Y | - | §2 | 必须 |
| API Contract | ||||
| Storage & Migration | ||||
| Async/Event | ||||
| Infra/IaC | ||||
| Observability | ||||
| Security/Compliance | ||||
| Deployment/Release | ||||
| Frontend UX | ||||
| External Integration | ||||
| SDK/Library |
LLD 模块清单(Add-ons)
每个模块只在能力触发时包含;缺失需在 Manifest 中 N/A 说明。
API Contract
- 触发:对外/跨团队接口或已有 Contract
- 必含:Contract 引用、接口→函数映射、错误码映射、版本/兼容策略
- 章节建议:
- Contract 引用
- 接口映射表
- 错误/权限映射
Storage & Migration
- 触发:数据库/文件/持久化
- 必含:表/集合/文件格式、索引、迁移/回滚、数据校验
- 章节建议:
- Schema/字段
- 迁移与回填
- 兼容性与历史数据处理
Async/Event
- 触发:队列/事件/异步任务
- 必含:主题/队列、消息 schema、顺序/幂等、DLQ/重试
- 章节建议:
- Topic/Queue 清单
- 消息结构
- 失败处理
Infra/IaC
- 触发:资源变更、Terraform/Cloud 资源
- 必含:资源清单、模块复用、IAM/权限、环境变量
- 章节建议:
- Terraform 模块与资源
- 权限与配置
- 共享组件复用
Observability
- 触发:上线或生产可观测性要求
- 必含:日志/指标/Tracing、告警、Dashboard
Security/Compliance
- 触发:权限/PII/合规
- 必含:认证授权、数据分级、加密/脱敏、审计
Deployment/Release
- 触发:多环境/灰度/回滚
- 必含:CI/CD 或发布步骤、回滚策略、Feature Flag
Frontend UX
- 触发:UI/多端交互
- 必含:路由/状态、交互流程、错误态、性能约束
External Integration
- 触发:第三方依赖
- 必含:接口地址、认证、限流/重试、降级
SDK/Library
- 触发:公共库/SDK
- 必含:API 面、版本策略、兼容性、发布方式
LLD Output Template
This document defines the output format templates for each stage of lld-writer.
---
Context Collection Report
Output timing: Phase 0.5
## Context Collection Report
### Baseline Documentation
| Document Type | Path | Version | Status |
|----------|------|------|------|
| PRD | {path} | {version} | Confirmed |
| HLD | {path} | {version} | Confirmed |
| Contract | {path} | {version} | Confirmed |
| Guardrails | {path/none} | - | Confirmed |
### Key constraint extraction
- Technology Stack: {Extracted from HLD/Guardrails}
- Mandatory module: {extracted from Guardrails}
- Reuse requirements: {extracted from HLD}---
LLD document information
Output timing: Phase 2.2
## 1. Document Information
| Properties | Values |
|------|-----|
| Document Name | LLD - {Module Name} |
| Version | v1.0 |
| Author | {Author} |
| Creation Date | {YYYY-MM-DD} |
| PRD baseline | {PRD path} v{version} |
| HLD baseline | {HLD path} v{version} |
| Contract Baseline | {Contract Path} |
| Guardrails | {path/none} |---
Traceback mapping table
Output timing: Phase 2.6
## Traceback mapping
| Upstream entry | Source | LLD Chapter | Status |
|----------|------|----------|------|
| {PRD-001} User Login | PRD | §5.2 Authentication Process | ✅ Covered |
| {HLD-003} Cache Strategy | HLD | §6.1 Cache Design | ✅ Covered |
| POST /api/v1/users | Contract | §5.1 User Interface | ✅ Covered |Status Description:
- ✅ Covered: The upstream entry has a corresponding design in LLD
- ⚠️ Partial coverage: Supplementary required
- ❌ Not covered: missing, must be added
---
List of issues to be confirmed
Output timing: Phase 2.7
## Questions to be confirmed
| # | Issue | Affected Chapters | Status |
|---|------|----------|------|
| 1 | {Problem description} | §X.X | To be confirmed |
| 2 | {Problem description} | §X.X | To be confirmed |---
Self-test report
Output timing: Phase 3.7
## Self-test report
### Coverage statistics
| Check items | Results |
|--------|------|
| PRD demand coverage | 100% (X/X) |
| HLD decision making | ✅ Passed |
| Contract consistency | ✅ No conflicts |
| Guardrails Coverage | ✅ Full Coverage / N/A |
### Question list
| # | Problem | Severity | Status |
|---|------|--------|------|
| - | None | - | - |
### Self-examination conclusion
✅ After passing the self-inspection, you can submit it for reviewSeverity Definition:
- P0 (blocking): Contract violation, Guardrails violation
- P1 (critical): missing modules, insufficient coverage
- P2 (recommendation): readability, details
LLD 输出模板
本文档定义 lld-writer 各阶段的输出格式模板。
---
上下文收集报告
输出时机:Phase 0.5
## 上下文收集报告
### 基线文档
| 文档类型 | 路径 | 版本 | 状态 |
|----------|------|------|------|
| PRD | {路径} | {版本} | 已确认 |
| HLD | {路径} | {版本} | 已确认 |
| Contract | {路径} | {版本} | 已确认 |
| Guardrails | {路径/无} | - | 已确认 |
### 关键约束提取
- 技术栈:{从 HLD/Guardrails 提取}
- 强制模块:{从 Guardrails 提取}
- 复用要求:{从 HLD 提取}---
LLD 文档信息
输出时机:Phase 2.2
## 1. 文档信息
| 属性 | 值 |
|------|-----|
| 文档名称 | LLD - {模块名} |
| 版本 | v1.0 |
| 作者 | {作者} |
| 创建日期 | {YYYY-MM-DD} |
| PRD 基线 | {PRD 路径} v{版本} |
| HLD 基线 | {HLD 路径} v{版本} |
| Contract 基线 | {Contract 路径} |
| Guardrails | {路径/无} |---
追溯映射表
输出时机:Phase 2.6
## 追溯映射
| 上游条目 | 来源 | LLD 章节 | 状态 |
|----------|------|----------|------|
| {PRD-001} 用户登录 | PRD | §5.2 认证流程 | ✅ 已覆盖 |
| {HLD-003} 缓存策略 | HLD | §6.1 缓存设计 | ✅ 已覆盖 |
| POST /api/v1/users | Contract | §5.1 用户接口 | ✅ 已覆盖 |状态说明:
- ✅ 已覆盖:上游条目在 LLD 中有对应设计
- ⚠️ 部分覆盖:需要补充
- ❌ 未覆盖:缺失,必须补充
---
待确认问题清单
输出时机:Phase 2.7
## 待确认问题
| # | 问题 | 影响章节 | 状态 |
|---|------|----------|------|
| 1 | {问题描述} | §X.X | 待确认 |
| 2 | {问题描述} | §X.X | 待确认 |---
自检报告
输出时机:Phase 3.7
## 自检报告
### 覆盖率统计
| 检查项 | 结果 |
|--------|------|
| PRD 需求覆盖率 | 100% (X/X) |
| HLD 决策承接 | ✅ 通过 |
| Contract 一致性 | ✅ 无冲突 |
| Guardrails 覆盖 | ✅ 全覆盖 / N/A |
### 问题清单
| # | 问题 | 严重度 | 状态 |
|---|------|--------|------|
| - | 无 | - | - |
### 自检结论
✅ 通过自检,可提交审查严重度定义:
- P0(阻塞):Contract 冲突、Guardrails 违反
- P1(严重):模块缺失、覆盖率不足
- P2(建议):可读性、细节问题
LLD Profiles(默认模块组合)
Profile 仅提供默认模块清单,仍需与 Guardrails 对齐。
saas-serverless
- Core
- API Contract
- Storage & Migration
- Async/Event
- Infra/IaC
- Observability
- Security/Compliance
- Deployment/Release
- External Integration(如有)
- Frontend UX(如有)
web-app
- Core
- API Contract
- Storage & Migration
- Observability
- Security/Compliance
- Deployment/Release
- Frontend UX
data-pipeline
- Core
- Storage & Migration
- Async/Event
- Infra/IaC
- Observability
- Security/Compliance
desktop-app
- Core
- Storage & Migration
- Frontend UX
- Observability
- Deployment/Release
sdk-library
- Core
- SDK/Library
- Observability(如有)