| name | reverse-engineer |
| scope | partial |
| description | Reverse engineer existing code into SDD specification documents.
Use when: analyzing legacy code, documenting undocumented systems, creating specs from existing implementations.
Keywords: reverse engineering, legacy code, documentation, spec extraction, code archaeology, ๅๅๅทฅ็จ, ่ๆ็จๅผ็ขผ, ่ฆๆ ผๆๅ.
|
Reverse Engineering to SDD Specification Guide
Language: English | ็น้ซไธญๆ
Version: 1.2.0
Last Updated: 2026-01-25
Applicability: Claude Code Skills
Core Standard: This skill implements Reverse Engineering Standards. For comprehensive methodology documentation accessible by any AI tool, refer to the core standard.
Purpose
This skill guides you through reverse engineering existing code into SDD (Spec-Driven Development) specification documents, with strict adherence to Anti-Hallucination standards.
Quick Reference
Reverse Engineering Workflow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Reverse Engineering Workflow โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ 1๏ธโฃ Code Analysis (AI Automated) โ
โ โโ Scan code structure, APIs, data models โ
โ โโ Parse existing tests for acceptance criteria โ
โ โโ Generate draft spec (with uncertainty labels) โ
โ โ
โ 2๏ธโฃ Human Input (Required) โ
โ โโ Write Motivation (why this feature exists) โ
โ โโ Add Risk Assessment โ
โ โโ Verify dependencies and business context โ
โ โ
โ 3๏ธโฃ Review & Confirm โ
โ โโ Discuss with stakeholders โ
โ โโ Confirm [Confirmed] / [Inferred] / [Unknown] labels โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
What Can vs Cannot Be Extracted
| Aspect | Extractable | Certainty | Notes |
|---|
| API Endpoints | โ
Yes | [Confirmed] | Route definitions, HTTP methods |
| Data Models | โ
Yes | [Confirmed] | Types, interfaces, schemas |
| Function Signatures | โ
Yes | [Confirmed] | Parameters, return types |
| Test Cases | โ
Yes | [Confirmed] | โ Acceptance Criteria |
| Dependencies | โ
Yes | [Confirmed] | Package references |
| Behavior Patterns | โ ๏ธ Partial | [Inferred] | From code analysis |
| Motivation/Why | โ No | [Unknown] | Needs human input |
| Business Context | โ No | [Unknown] | Needs human input |
| Risk Assessment | โ No | [Unknown] | Needs domain expertise |
| Trade-off Decisions | โ No | [Unknown] | Historical context missing |
Core Principles
1. Anti-Hallucination Compliance
CRITICAL: This skill MUST strictly follow Anti-Hallucination Standards.
Certainty Labels (from Unified Tag System)
This skill uses Certainty Tags for analyzing existing code. See Anti-Hallucination Standards for the complete tag reference.
| Tag | Use When | Example |
|---|
[Confirmed] | Direct evidence from code/tests | API endpoint at src/api/users.ts:15 |
[Inferred] | Logical deduction from patterns | "Likely uses dependency injection based on constructor pattern" |
[Unknown] | Cannot determine from code | Motivation, business requirements |
[Need Confirmation] | Requires human verification | Design intent, edge case handling |
Source Attribution
Every extracted item MUST include source attribution:
## API Design
### User Authentication
[Confirmed] POST /api/auth/login endpoint accepts email and password
- [Source: Code] src/controllers/AuthController.ts:25-45
- [Source: Code] src/routes/auth.ts:8
### Session Management
[Inferred] Sessions expire after 24 hours based on JWT expiry configuration
- [Source: Code] src/config/auth.ts:12 - TOKEN_EXPIRY=86400
- [Source: Knowledge] Standard JWT expiry interpretation (โ ๏ธ Verify intent)
2. Progressive Disclosure
Start with high-level architecture, then drill down:
- System Overview: Entry points, main components
- Component Details: Individual modules, their responsibilities
- Implementation Specifics: Algorithms, data flows
3. Test-to-Requirement Mapping
Extract acceptance criteria from tests:
describe('Authentication', () => {
it('should return 401 for invalid credentials', () => {...});
it('should issue JWT token on successful login', () => {...});
it('should refresh token before expiry', () => {...});
});
Becomes:
## Acceptance Criteria
[Inferred] From test analysis (src/tests/auth.test.ts):
- [ ] Return 401 status code for invalid credentials
- [ ] Issue JWT token on successful login
- [ ] Support token refresh before expiry
Workflow Stages
Stage 1: Code Scanning
Input: File path or directory
Output: Code structure analysis
Actions:
- Identify entry points (main functions, API routes, event handlers)
- Map module dependencies
- Extract type definitions and interfaces
- List configuration sources
Stage 2: Test Analysis
Input: Test files
Output: Acceptance criteria candidates
Actions:
- Parse test case names
- Extract Given-When-Then patterns (if BDD-style)
- Identify boundary conditions
- Note coverage gaps
Stage 3: Gap Identification
Input: Code + test analysis
Output: List of unknowns requiring human input
Required Human Input:
Stage 4: Spec Generation
Input: All analysis results
Output: Draft specification document
Template: Use reverse-spec-template.md
Stage 5: Human Review
Input: Draft specification
Output: Validated specification
Review Checklist:
Examples
Example 1: API Endpoint Extraction
Input Code (src/controllers/UserController.ts):
export class UserController {
@Get('/users/:id')
@Authorize('admin', 'user')
async getUser(@Param('id') id: string): Promise<User> {
return this.userService.findById(id);
}
}
Extracted Specification:
## API Endpoints
### GET /users/:id
[Confirmed] Retrieves a user by ID
- [Source: Code] src/controllers/UserController.ts:3-7
**Authorization**: [Confirmed] Requires 'admin' or 'user' role
- [Source: Code] @Authorize decorator at line 4
**Parameters**:
- `id` (path, required): User identifier [Confirmed]
**Response**: [Confirmed] Returns User object
- [Source: Code] Return type at line 5
**Error Handling**: [Unknown] Error responses not evident from code
Example 2: Test-to-Criteria Extraction
Input Test (src/tests/cart.test.ts):
describe('Shopping Cart', () => {
it('should add item to empty cart', () => {...});
it('should increment quantity for duplicate items', () => {...});
it('should not exceed maximum quantity of 99', () => {...});
it('should calculate total with tax', () => {...});
});
Extracted Acceptance Criteria:
## Acceptance Criteria
[Inferred] From test analysis (src/tests/cart.test.ts):
- [ ] Can add item to empty cart (line 2)
- [ ] Increments quantity for duplicate items (line 3)
- [ ] Maximum quantity limit: 99 items (line 4)
- [ ] Total calculation includes tax (line 5)
[Unknown] Tax calculation rules not specified in tests
[Need Confirmation] What happens when cart exceeds 99 items? (reject or cap?)
Integration with Other Skills
With /spec (Spec-Driven Development)
- Generate reverse-engineered spec using
/reverse-spec
- Review and fill in
[Unknown] sections
- Use
/spec review to validate completeness
- Proceed with normal SDD workflow for enhancements
With /tdd (Test-Driven Development)
- Extract existing test patterns
- Identify test coverage gaps
- Use
/tdd to add missing tests
- Update spec with new acceptance criteria
With /bdd (Behavior-Driven Development)
- Convert extracted acceptance criteria to Gherkin format
- Use
/bdd to formalize scenarios
- Validate scenarios with stakeholders
Complete Reverse Engineering Pipeline
The reverse engineering skill supports a complete SDD โ BDD โ TDD pipeline:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Complete Reverse Engineering Pipeline โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ Code + Tests โ
โ โ โ
โ โผ โ
โ /reverse-spec โ
โ โ โ
โ โโโ Generate SPEC-XXX with Acceptance Criteria โ
โ โ โ
โ โผ โ
โ /reverse-bdd โ
โ โ โ
โ โโโ AC โ Gherkin scenario conversion โ
โ โโโ Auto-transform bullet points to Given-When-Then โ
โ โโโ Generate .feature files โ
โ โ โ
โ โผ โ
โ /reverse-tdd โ
โ โ โ
โ โโโ Analyze existing unit tests โ
โ โโโ Generate coverage report with gaps โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Pipeline Commands
| Command | Input | Output | Purpose |
|---|
/reverse-spec | Code directory | SPEC-XXX.md | Extract requirements from code |
/reverse-bdd | SPEC file | .feature files | Convert AC to Gherkin scenarios |
/reverse-tdd | .feature files | Coverage report | Map scenarios to unit tests |
Usage Example
/reverse-spec src/auth/
/reverse-bdd specs/SPEC-AUTH.md
/reverse-tdd features/auth.feature
Detailed Guides
Anti-Patterns to Avoid
โ Don't Do This
-
Fabricating Motivation
- Wrong: "This feature was built to improve user experience"
- Right: "[Unknown] Motivation requires human input"
-
Assuming Requirements
- Wrong: "The system requires SSO support"
- Right: "[Need Confirmation] SSO configuration found in code - is this a requirement?"
-
Speculating About Unread Code
- Wrong: "The PaymentService handles Stripe integration"
- Right: "[Unknown] PaymentService functionality - need to read src/services/PaymentService.ts"
-
Presenting Options Without Uncertainty
- Wrong: "The code uses Redis for caching"
- Right: "[Confirmed] Redis client configured in src/config/cache.ts:5"
Best Practices
Do's
- โ
Read all relevant files before making claims
- โ
Tag every statement with certainty level
- โ
Include source citations with file:line
- โ
Clearly list what needs human input
- โ
Preserve original code comments as context
Don'ts
- โ Assume motivation or business context
- โ Present inferences as confirmed facts
- โ Skip source attribution
- โ Generate specs for unread code
- โ Fill in
[Unknown] sections without human input
Configuration Detection
This skill auto-detects project configuration:
- Check for existing
specs/ directory
- Check for SDD tooling (OpenSpec, Spec Kit)
- Detect test framework for acceptance criteria extraction
- Identify code patterns (MVC, DDD, etc.)
Related Standards
Version History
| Version | Date | Changes |
|---|
| 1.2.0 | 2026-01-25 | Added: Reference to Unified Tag System |
| 1.1.0 | 2026-01-19 | Add BDD/TDD pipeline integration; Add core standard reference |
| 1.0.0 | 2026-01-19 | Initial release |
License
This skill is released under CC BY 4.0.
Source: universal-dev-standards