重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
technical-spec by majiayu000/claude-arsenal
npx skills add https://github.com/majiayu000/claude-arsenal --skill technical-spec撰写高效技术设计文档、RFC、架构决策记录和技术评估框架的专家指南。
这些规则是强制性的。违反它们意味着技能未正常工作。
每个设计文档必须包含至少 2 个备选解决方案。
❌ 禁止:
## 解决方案
我们将使用 PostgreSQL 作为数据库。
(未考虑任何备选方案)
✅ 要求:
## 建议方案
使用 PostgreSQL 作为主数据库。
## 已考虑的备选方案
### 选项 A: PostgreSQL(推荐)
**优点**:ACID 合规性、JSON 支持、成熟的生态系统
**缺点**:垂直扩展限制
**决策**:因其可靠性和团队专业知识而被选中
### 选项 B: MongoDB
**优点**:水平扩展、灵活的模式
**缺点**:最终一致性、团队不太熟悉
**决策**:由于一致性要求而被拒绝
### 选项 C: DynamoDB
**优点**:无服务器、自动扩展
**缺点**:供应商锁定、复杂的查询模式
**决策**:由于查询灵活性需求而被拒绝
系统设计必须包含架构图。不允许纯文本描述。
❌ 禁止:
"用户向 API 发送请求,API 与数据库通信并返回响应。"
✅ 要求:
至少包含以下一种:
- C4 上下文/容器图
- 关键流程的序列图
- 数据流图
示例(Mermaid):
```mermaid
sequenceDiagram
Client->>API: POST /orders
API->>Auth: Validate token
Auth-->>API: User context
API->>DB: Create order
DB-->>API: Order ID
API-->>Client: 201 Created
### 定义成功指标
**每个设计必须包含可衡量的成功标准。**
```markdown
❌ 禁止:
## 目标
- 让系统更快
- 提高可靠性
- 更好的用户体验
✅ 要求:
## 成功指标
| 指标 | 当前值 | 目标值 | 测量方式 |
|--------|---------|--------|-------------|
| API 延迟(P95) | 500ms | <200ms | Prometheus 直方图 |
| 可用性 | 99.5% | 99.9% | 正常运行时间监控 |
| 错误率 | 2% | <0.1% | 错误跟踪 |
| 吞吐量 | 1K 请求/秒 | 10K 请求/秒 | 负载测试 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
所有设计必须识别风险及其缓解措施。
❌ 禁止:
(无风险部分,假设一切都会正常工作)
✅ 要求:
## 风险与缓解措施
| 风险 | 严重性 | 可能性 | 缓解措施 |
|------|----------|------------|------------|
| 数据库迁移失败 | 高 | 中等 | 备份 + 回滚计划,在预演环境测试 |
| 第三方 API 不可用 | 中等 | 低 | 断路器,后备缓存 |
| 团队缺乏专业知识 | 中等 | 中等 | 结对编程,外部评审 |
| 范围蔓延 | 高 | 高 | 固定范围文档,变更控制 |
| 场景 | 文档类型 | 复杂度 |
|---|---|---|
| 新功能设计 | 技术设计文档 | 中-高 |
| 系统架构 | C4 模型图 | 中等 |
| 重大技术决策 | 架构决策记录 | 低-中等 |
| 跨团队提案 | RFC(征求意见稿) | 中-高 |
| 技术评估 | 技术选型矩阵 | 中等 |
| API 契约 | OpenAPI/AsyncAPI 规范 | 低-中等 |
目的:实现功能或系统的蓝图 受众:工程师、技术负责人 时机:在实现重要功能之前 章节:问题、解决方案、备选方案、风险、时间线
目的:用于讨论和反馈的提案 受众:跨职能团队 时机:需要就技术方向达成共识时 章节:问题陈述、提案、权衡、开放性问题
目的:记录单个架构决策 受众:当前及未来的工程师 时机:任何具有架构重要性的选择 章节:上下文、决策、后果、状态
目的:在多个缩放级别上可视化系统架构 受众:技术和非技术利益相关者 时机:沟通系统结构时 级别:上下文、容器、组件、代码
# 标题:用户认证系统
**作者**:Jane Doe
**状态**:提议中 | 评审中 | 已批准 | 已实施
**创建日期**:2025-12-18
**最后更新**:2025-12-18
**评审者**:@tech-lead, @security-team
## 问题
**当前状态**:用户通过传统会话 Cookie 认证,不支持 MFA。
**影响**:23% 的安全事件与凭证泄露有关。
**约束**:必须支持 10K 并发用户,登录延迟 <200ms。
**目标**:实现支持 MFA 和 OAuth 的安全、可扩展的认证。
## 解决方案
实施基于 JWT 的认证,包含:
- 访问令牌(15分钟 TTL)+ 刷新令牌(7天 TTL)
- 基于 TOTP 的 MFA(兼容 Google Authenticator)
- OAuth 2.0 提供商(Google, GitHub)
- Redis 用于令牌黑名单和会话管理
### 高层设计
[在此处包含 C4 容器图]
### 数据流
1. 用户提交凭证 → 认证服务验证
2. 认证服务生成 JWT 对,将刷新令牌存储在 Redis 中
3. 客户端在 Authorization 头部包含访问令牌
4. API 网关验证令牌,提取用户上下文
5. 令牌过期时,客户端用刷新令牌交换新的访问令牌
## 备选方案
### 选项 A: 基于会话的认证
**优点**:实现更简单,服务器端可撤销
**缺点**:无法水平扩展,延迟更高
**决策**:拒绝 - 不满足可扩展性要求
### 选项 B: Auth0(第三方)
**优点**:久经考验,功能完整
**缺点**:每月 500 美元成本,供应商锁定
**决策**:推迟 - 如果团队进度不足再重新考虑
## 风险与缓解措施
| 风险 | 严重性 | 可能性 | 缓解措施 |
|------|----------|------------|------------|
| JWT 密钥泄露 | 严重 | 低 | 每季度轮换密钥,使用 HSM |
| 令牌被盗(XSS) | 高 | 中等 | HttpOnly Cookie,CSP 头部 |
| Redis 停机 | 高 | 低 | 回退到无状态验证 |
| 时钟偏差问题 | 中等 | 中等 | 使用 `nbf` 声明,允许 5 分钟容差 |
## 工作分解
### 阶段 1: 核心认证(第 1-2 周)
- [ ] JWT 生成/验证服务
- [ ] 密码哈希(bcrypt)
- [ ] 用户存储库接口
- [ ] 单元测试 + 集成测试
### 阶段 2: MFA(第 3 周)
- [ ] TOTP 密钥生成
- [ ] 二维码生成
- [ ] 验证端点
- [ ] 备用代码
### 阶段 3: OAuth(第 4 周)
- [ ] Google OAuth 集成
- [ ] GitHub OAuth 集成
- [ ] 账户关联流程
### 成功指标
- 认证逻辑 100% 测试覆盖率
- 令牌验证延迟 <100ms
- 审计中零安全漏洞
## 开放性问题
1. **令牌存储**:刷新令牌应该存储在 httpOnly Cookie 还是 localStorage 中?
- **建议**:Cookie(XSS 防护),需要 CSRF 缓解措施
2. **MFA 强制执行**:对所有用户是可选还是强制?
- **需要**:产品团队决策
3. **会话限制**:我们应该限制每个用户的并发会话数吗?
- **影响**:Redis 存储需求,用户体验复杂度
✅ 应该做:
- 使用简单直接的语言
- 首次使用时定义缩写
- 为复杂流程包含图表
- 使用表格进行比较
- 提供具体示例
❌ 不应该做:
- 使用未解释的行话
- 写大段文字
- 假设读者具备先验知识
- 跳过决策背后的“原因”
- 创建过时的文档
Mermaid(简单流程)
sequenceDiagram
Client->>API: POST /login
API->>DB: Validate credentials
DB-->>API: User data
API->>Redis: Store session
API-->>Client: JWT token
PlantUML with C4(架构)
@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
System_Boundary(c1, "Auth System") {
Container(api, "API Gateway", "Node.js", "Routes requests")
Container(auth, "Auth Service", "Go", "Handles authentication")
ContainerDb(redis, "Redis", "Cache", "Sessions & tokens")
}
Person(user, "User")
user -> api : Login request
api -> auth : Validate
auth -> redis : Store token
@enduml
在整个组织中使用一致的模板:
templates/design-doc-template.mdtemplates/adr-template.mdreference/tech-selection.md# 将文档与代码一起存储
docs/
├── architecture/
│ ├── ADRs/
│ │ ├── 001-database-selection.md
│ │ └── 002-api-authentication.md
│ └── diagrams/
│ └── c4-system-context.puml
├── design/
│ └── auth-system-design.md
└── rfcs/
└── 2025-01-user-authentication.md
## 需求可追溯性
| 需求 | 设计元素 | 实现 | 测试 |
|-------------|---------------|----------------|-------|
| REQ-001: MFA 支持 | Auth Service TOTP 模块 | `auth/totp.go` | `auth/totp_test.go` |
| REQ-002: OAuth 登录 | OAuth 提供商适配器 | `auth/oauth.go` | `auth/oauth_test.go` |
| REQ-003: <100ms 延迟 | Redis 令牌缓存 | `middleware/jwt.go` | `benchmark/auth_bench.go` |
## 文档状态
- **提议中**:初始草案,寻求反馈
- **评审中**:利益相关者正在评审
- **已批准**:已接受,准备实施
- **已实施**:完全实施
- **已弃用**:不再有效,被 ADR-XXX 取代
实施前:
实施后:
❌ 设计作为事后辩解
- 不要在实施后编写文档来证明决策的合理性
- 在实施前编写以深入思考设计
❌ 过多细节
- 不要记录每个函数和变量
- 专注于系统级设计,而非逐行代码
❌ 瀑布式的规格先行
- 不要花费数月时间追求完美设计
- 编写足够内容以启动,随着学习而迭代
❌ 过时的文档
- 不要让文档与现实脱节
- 更新或删除过时的文档
❌ 没有备选方案分析
- 不要只呈现一个解决方案
- 展示你已考虑过的权衡
❌ 缺少成功标准
- 不要忘记定义“完成”的标准
- 包含可衡量的成功指标
┌─────────────────────────────────────────────────────────────┐
│ 技术文档快速指南 │
├─────────────────────────────────────────────────────────────┤
│ 文档类型选择 │
│ ├── 新功能 → 技术设计文档 │
│ ├── 架构 → C4 图 + 系统设计文档 │
│ ├── 单一决策 → 架构决策记录 │
│ ├── 跨团队提案 → 征求意见稿 │
│ └── 技术选择 → 技术评估矩阵 │
├─────────────────────────────────────────────────────────────┤
│ 核心章节(技术设计文档) │
│ ├── 1. 问题陈述(为什么?) │
│ ├── 2. 建议方案(是什么?) │
│ ├── 3. 已考虑的备选方案(为什么不选 X?) │
│ ├── 4. 风险评估(可能出什么问题?) │
│ ├── 5. 实施计划(如何做 & 何时做?) │
│ ├── 6. 成功指标(如何衡量?) │
│ └── 7. 开放性问题(什么不清楚?) │
├─────────────────────────────────────────────────────────────┤
│ 最佳实践 │
│ ├── 在实施前编写 │
│ ├── 为复杂流程使用图表 │
│ ├── 保持语言简单直接 │
│ ├── 展示权衡,而不仅仅是解决方案 │
│ ├── 定义成功标准 │
│ └── 随着系统演进更新文档 │
└─────────────────────────────────────────────────────────────┘
基于 2025 年最佳实践的研究:
每周安装数
49
仓库
GitHub 星标数
12
首次出现
Jan 24, 2026
安全审计
安装于
opencode41
gemini-cli39
cursor39
codex39
claude-code37
github-copilot35
Expert guidance for writing effective technical design documents, RFCs, Architecture Decision Records, and technology evaluation frameworks.
These rules are mandatory. Violating them means the skill is not working correctly.
Every design document must include at least 2 alternative solutions.
❌ FORBIDDEN:
## Solution
We will use PostgreSQL for the database.
(No alternatives considered)
✅ REQUIRED:
## Proposed Solution
PostgreSQL for primary database.
## Alternatives Considered
### Option A: PostgreSQL (Recommended)
**Pros**: ACID compliance, JSON support, mature ecosystem
**Cons**: Vertical scaling limits
**Decision**: Chosen for reliability and team expertise
### Option B: MongoDB
**Pros**: Horizontal scaling, flexible schema
**Cons**: Eventual consistency, less familiar to team
**Decision**: Rejected due to consistency requirements
### Option C: DynamoDB
**Pros**: Serverless, auto-scaling
**Cons**: Vendor lock-in, complex query patterns
**Decision**: Rejected due to query flexibility needs
System designs must include architecture diagrams. No text-only descriptions.
❌ FORBIDDEN:
"The user sends a request to the API, which talks to the database
and returns a response."
✅ REQUIRED:
Include at least one of:
- C4 Context/Container diagram
- Sequence diagram for key flows
- Data flow diagram
Example (Mermaid):
```mermaid
sequenceDiagram
Client->>API: POST /orders
API->>Auth: Validate token
Auth-->>API: User context
API->>DB: Create order
DB-->>API: Order ID
API-->>Client: 201 Created
### Success Metrics Defined
**Every design must include measurable success criteria.**
```markdown
❌ FORBIDDEN:
## Goals
- Make the system faster
- Improve reliability
- Better user experience
✅ REQUIRED:
## Success Metrics
| Metric | Current | Target | Measurement |
|--------|---------|--------|-------------|
| API Latency (P95) | 500ms | <200ms | Prometheus histogram |
| Availability | 99.5% | 99.9% | Uptime monitoring |
| Error Rate | 2% | <0.1% | Error tracking |
| Throughput | 1K req/s | 10K req/s | Load testing |
All designs must identify risks and their mitigations.
❌ FORBIDDEN:
(No risk section, assuming everything will work)
✅ REQUIRED:
## Risks & Mitigations
| Risk | Severity | Likelihood | Mitigation |
|------|----------|------------|------------|
| Database migration fails | High | Medium | Backup + rollback plan, test in staging |
| Third-party API unavailable | Medium | Low | Circuit breaker, fallback cache |
| Team lacks expertise | Medium | Medium | Pair programming, external review |
| Scope creep | High | High | Fixed scope document, change control |
| Scenario | Document Type | Complexity |
|---|---|---|
| New feature design | Technical Design Doc | Medium-High |
| System architecture | C4 Model Diagrams | Medium |
| Major technical decision | Architecture Decision Record (ADR) | Low-Medium |
| Cross-team proposal | RFC (Request for Comments) | Medium-High |
| Technology evaluation | Tech Selection Matrix | Medium |
| API contract | OpenAPI/AsyncAPI Spec | Low-Medium |
Purpose : Blueprint for implementing a feature or system Audience : Engineers, technical leads When : Before implementing significant features Sections : Problem, solution, alternatives, risks, timeline
Purpose : Proposal for discussion and feedback Audience : Cross-functional teams When : Need consensus on technical direction Sections : Problem statement, proposal, trade-offs, open questions
Purpose : Document a single architectural decision Audience : Current and future engineers When : Any architecturally significant choice Sections : Context, decision, consequences, status
Purpose : Visualize system architecture at multiple zoom levels Audience : Technical and non-technical stakeholders When : Communicating system structure Levels : Context, Container, Component, Code
# Title: User Authentication System
**Author**: Jane Doe
**Status**: Proposed | In Review | Approved | Implemented
**Created**: 2025-12-18
**Last Updated**: 2025-12-18
**Reviewers**: @tech-lead, @security-team
## Problem
**Current State**: Users authenticate via legacy session cookies, no MFA support.
**Impact**: 23% of security incidents related to compromised credentials.
**Constraint**: Must support 10K concurrent users, <200ms login latency.
**Goal**: Implement secure, scalable authentication with MFA and OAuth support.
## Solution
Implement JWT-based authentication with:
- Access tokens (15min TTL) + Refresh tokens (7 day TTL)
- TOTP-based MFA (Google Authenticator compatible)
- OAuth 2.0 providers (Google, GitHub)
- Redis for token blacklist and session management
### High-Level Design
[Include C4 Container diagram here]
### Data Flow
1. User submits credentials → Auth Service validates
2. Auth Service generates JWT pair, stores refresh token in Redis
3. Client includes access token in Authorization header
4. API Gateway validates token, extracts user context
5. On expiry, client exchanges refresh token for new access token
## Alternatives
### Option A: Session-based authentication
**Pros**: Simpler implementation, server-side revocation
**Cons**: Doesn't scale horizontally, higher latency
**Decision**: Rejected - doesn't meet scalability requirements
### Option B: Auth0 (3rd party)
**Pros**: Battle-tested, feature-complete
**Cons**: $500/month cost, vendor lock-in
**Decision**: Deferred - revisit if team velocity insufficient
## Risks & Mitigations
| Risk | Severity | Likelihood | Mitigation |
|------|----------|------------|------------|
| JWT secret leak | Critical | Low | Rotate secrets quarterly, use HSM |
| Token theft (XSS) | High | Medium | HttpOnly cookies, CSP headers |
| Redis downtime | High | Low | Fallback to stateless validation |
| Clock skew issues | Medium | Medium | Use `nbf` claim, allow 5min tolerance |
## Work Breakdown
### Phase 1: Core Authentication (Week 1-2)
- [ ] JWT generation/validation service
- [ ] Password hashing (bcrypt)
- [ ] User repository interface
- [ ] Unit tests + integration tests
### Phase 2: MFA (Week 3)
- [ ] TOTP secret generation
- [ ] QR code generation
- [ ] Verification endpoint
- [ ] Backup codes
### Phase 3: OAuth (Week 4)
- [ ] Google OAuth integration
- [ ] GitHub OAuth integration
- [ ] Account linking flow
### Success Metrics
- 100% test coverage for auth logic
- <100ms token validation latency
- Zero security vulnerabilities in audit
## Open Questions
1. **Token storage**: Should refresh tokens be in httpOnly cookie or localStorage?
- **Recommendation**: Cookie (XSS protection), need CSRF mitigation
2. **MFA enforcement**: Opt-in or mandatory for all users?
- **Requires**: Product team decision
3. **Session limits**: Should we limit concurrent sessions per user?
- **Impact**: Redis storage requirements, UX complexity
✅ DO:
- Use simple, direct language
- Define acronyms on first use
- Include diagrams for complex flows
- Use tables for comparisons
- Provide concrete examples
❌ DON'T:
- Use jargon without explanation
- Write walls of text
- Assume prior knowledge
- Skip the "why" behind decisions
- Create docs that become stale
Mermaid (Simple flows)
sequenceDiagram
Client->>API: POST /login
API->>DB: Validate credentials
DB-->>API: User data
API->>Redis: Store session
API-->>Client: JWT token
PlantUML with C4 (Architecture)
@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
System_Boundary(c1, "Auth System") {
Container(api, "API Gateway", "Node.js", "Routes requests")
Container(auth, "Auth Service", "Go", "Handles authentication")
ContainerDb(redis, "Redis", "Cache", "Sessions & tokens")
}
Person(user, "User")
user -> api : Login request
api -> auth : Validate
auth -> redis : Store token
@enduml
Use consistent templates across your organization:
templates/design-doc-template.mdtemplates/adr-template.mdreference/tech-selection.md# Store docs with code
docs/
├── architecture/
│ ├── ADRs/
│ │ ├── 001-database-selection.md
│ │ └── 002-api-authentication.md
│ └── diagrams/
│ └── c4-system-context.puml
├── design/
│ └── auth-system-design.md
└── rfcs/
└── 2025-01-user-authentication.md
## Requirements Traceability
| Requirement | Design Element | Implementation | Tests |
|-------------|---------------|----------------|-------|
| REQ-001: MFA support | Auth Service TOTP module | `auth/totp.go` | `auth/totp_test.go` |
| REQ-002: OAuth login | OAuth provider adapter | `auth/oauth.go` | `auth/oauth_test.go` |
| REQ-003: <100ms latency | Redis token cache | `middleware/jwt.go` | `benchmark/auth_bench.go` |
## Document Status
- **Proposed**: Initial draft, seeking feedback
- **In Review**: Under review by stakeholders
- **Approved**: Accepted, ready for implementation
- **Implemented**: Fully implemented
- **Deprecated**: No longer valid, superseded by ADR-XXX
Before implementation:
After implementation:
❌ Design as justification
- Don't write docs after implementation to justify decisions
- Write BEFORE to think through design
❌ Too much detail
- Don't document every function and variable
- Focus on system-level design, not line-by-line code
❌ Spec-first waterfall
- Don't spend months on perfect design
- Write enough to start, iterate as you learn
❌ Stale documentation
- Don't let docs drift from reality
- Update or delete outdated docs
❌ No alternatives analysis
- Don't present only one solution
- Show you considered trade-offs
❌ Missing success criteria
- Don't forget to define "done"
- Include measurable success metrics
┌─────────────────────────────────────────────────────────────┐
│ TECHNICAL DOCUMENT QUICK GUIDE │
├─────────────────────────────────────────────────────────────┤
│ Document Type Selection │
│ ├── New feature → Technical Design Doc (TDD) │
│ ├── Architecture → C4 Diagrams + System Design Doc │
│ ├── Single decision → Architecture Decision Record (ADR) │
│ ├── Cross-team proposal → Request for Comments (RFC) │
│ └── Technology choice → Tech Evaluation Matrix │
├─────────────────────────────────────────────────────────────┤
│ Essential Sections (TDD) │
│ ├── 1. Problem Statement (Why?) │
│ ├── 2. Proposed Solution (What?) │
│ ├── 3. Alternatives Considered (Why not X?) │
│ ├── 4. Risk Assessment (What could go wrong?) │
│ ├── 5. Implementation Plan (How & When?) │
│ ├── 6. Success Metrics (How to measure?) │
│ └── 7. Open Questions (What's unclear?) │
├─────────────────────────────────────────────────────────────┤
│ Best Practices │
│ ├── Write BEFORE implementation │
│ ├── Use diagrams for complex flows │
│ ├── Keep language simple and direct │
│ ├── Show trade-offs, not just solutions │
│ ├── Define success criteria │
│ └── Update docs as system evolves │
└─────────────────────────────────────────────────────────────┘
Research based on 2025 best practices from:
Weekly Installs
49
Repository
GitHub Stars
12
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode41
gemini-cli39
cursor39
codex39
claude-code37
github-copilot35
论文复现上下文解析器 - 解决AI论文复现中的关键信息缺口与冲突检测
28,400 周安装