From shinpr-claude-code-workflows
Generates PRD and Design Docs from existing codebases via discovery, generation, verification, and review workflow. Configurable for target path, depth, reference architecture, fullstack, and human review.
npx claudepluginhub joshuarweaver/cascade-code-general-misc-1 --plugin shinpr-claude-code-workflowsThis skill uses the workspace's default tool permissions.
**Context**: Reverse engineering workflow to create documentation from existing code
Creates isolated Git worktrees for feature branches with prioritized directory selection, gitignore safety checks, auto project setup for Node/Python/Rust/Go, and baseline verification.
Executes implementation plans in current session by dispatching fresh subagents per independent task, with two-stage reviews: spec compliance then code quality.
Dispatches parallel agents to independently tackle 2+ tasks like separate test failures or subsystems without shared state or dependencies.
Context: Reverse engineering workflow to create documentation from existing code
Target: $ARGUMENTS
Core Identity: "I am an orchestrator."
Execution Protocol:
$STEP_N_OUTPUT as-is to sub-agents — the orchestrator bridges data without processing or filtering itTask Registration: Register phases first using TaskCreate, then steps within each phase as you enter it. Update status using TaskUpdate.
Use AskUserQuestion to confirm:
docs/prd/ or existing PRD directorydocs/design/ or existing design directoryPhase 1: PRD Generation
Step 1: Scope Discovery (unified, single pass → group into PRD units → human review)
Step 2-5: Per-unit loop (Generation → Verification → Review → Revision)
Phase 2: Design Doc Generation (if requested)
Step 6: Design Doc Scope Mapping (reuse Step 1 results, no re-discovery)
Step 7-10: Per-unit loop (Generation → Verification → Review → Revision)
※ fullstack=Yes: each unit produces backend + frontend Design Docs
Register using TaskCreate:
Agent tool invocation:
subagent_type: dev-workflows:scope-discoverer
description: "Discover functional scope"
prompt: |
Discover functional scope targets in the codebase.
target_path: $USER_TARGET_PATH
reference_architecture: $USER_RA_CHOICE
focus_area: $USER_FOCUS_AREA (if specified)
Store output as: $STEP_1_OUTPUT
Quality Gate:
$STEP_1_OUTPUT.prdUnits existssourceUnits across prdUnits (flattened, deduplicated) match the set of discoveredUnits IDs — no unit missing, no unit duplicatedunitInventory has at least one non-empty category (routes, testFiles, or publicExports). Units with all three empty indicate incomplete discovery — re-run scope-discoverer with focus on that unit's relatedFilesHuman Review Point (if enabled): Present $STEP_1_OUTPUT.prdUnits with their source unit mapping. The user confirms, adjusts grouping, or excludes units from scope. This is the most important review point — incorrect grouping cascades into all downstream documents.
FOR each unit in $STEP_1_OUTPUT.prdUnits (sequential, one unit at a time):
Agent tool invocation:
subagent_type: dev-workflows:prd-creator
description: "Generate PRD"
prompt: |
Create reverse-engineered PRD for the following feature.
Operation Mode: reverse-engineer
External Scope Provided: true
Feature: $PRD_UNIT_NAME (from $STEP_1_OUTPUT)
Description: $PRD_UNIT_DESCRIPTION
Related Files: $PRD_UNIT_COMBINED_RELATED_FILES
Entry Points: $PRD_UNIT_COMBINED_ENTRY_POINTS
Use provided scope as investigation starting point.
If tracing entry points reveals files outside this scope, include them.
Create final version PRD based on thorough code investigation.
Store output as: $STEP_2_OUTPUT (PRD path)
Prerequisite: $STEP_2_OUTPUT (PRD path from Step 2)
Agent tool invocation:
subagent_type: dev-workflows:code-verifier
description: "Verify PRD consistency"
prompt: |
Verify consistency between PRD and code implementation.
doc_type: prd
document_path: $STEP_2_OUTPUT
verbose: false
Note: Omit code_paths — the verifier independently discovers code scope from the document, ensuring independent verification not constrained by scope-discoverer's output.
Store output as: $STEP_3_OUTPUT
Quality Gate:
Required Input: $STEP_3_OUTPUT (verification JSON from Step 3)
Agent tool invocation:
subagent_type: dev-workflows:document-reviewer
description: "Review PRD"
prompt: |
Review the following PRD considering code verification findings.
doc_type: PRD
target: $STEP_2_OUTPUT
mode: composite
code_verification: $STEP_3_OUTPUT
## Additional Review Focus
- Alignment between PRD claims and verification evidence
- Resolution recommendations for each discrepancy
- Completeness of undocumented feature coverage
Store output as: $STEP_4_OUTPUT
Trigger Conditions (any one of the following):
$STEP_3_OUTPUTAgent tool invocation:
subagent_type: dev-workflows:prd-creator
description: "Revise PRD"
prompt: |
Update PRD based on review feedback and code verification results.
Operation Mode: update
Existing PRD: $STEP_2_OUTPUT
## Review Feedback
$STEP_4_OUTPUT
## Code Verification Results
$STEP_3_OUTPUT
Address discrepancies by severity. Critical and major items require correction.
Minor items: correct if straightforward, otherwise leave as-is with rationale.
Loop Control: Maximum 2 revision cycles. After 2 cycles, flag for human review regardless of status.
Next: Proceed to next unit. After all units → Phase 2.
Execute only if Design Docs were requested in Step 0
Register using TaskCreate:
No additional discovery required. Use $STEP_1_OUTPUT.discoveredUnits (implementation-granularity units) for technical profiles. Use $STEP_1_OUTPUT.prdUnits[].sourceUnits to trace which discovered units belong to each PRD unit.
Each PRD unit from Phase 1 maps to Design Doc unit(s):
Map $STEP_1_OUTPUT units to Design Doc generation targets, carrying forward:
technicalProfile.primaryModules → Primary FilestechnicalProfile.publicInterfaces → Public Interfacesdependencies → DependenciesrelatedFiles → Scope boundaryunitInventory → Unit Inventory (routes, test files, public exports)Store output as: $STEP_6_OUTPUT
FOR each unit in $STEP_6_OUTPUT (sequential, one unit at a time):
Scope: Document the current architecture exactly as implemented in code.
Standard mode (fullstack=No):
Agent tool invocation:
subagent_type: dev-workflows:technical-designer
description: "Generate Design Doc"
prompt: |
Create Design Doc for the following feature based on existing code.
Operation Mode: reverse-engineer
Feature: $UNIT_NAME (from $STEP_6_OUTPUT)
Description: $UNIT_DESCRIPTION
Primary Files: $UNIT_PRIMARY_MODULES
Public Interfaces: $UNIT_PUBLIC_INTERFACES
Dependencies: $UNIT_DEPENDENCIES
Unit Inventory: $UNIT_INVENTORY (routes, test files, public exports from scope discovery)
Parent PRD: $APPROVED_PRD_PATH
Document current architecture as-is. Use Unit Inventory as a completeness baseline — all routes and exports should be accounted for in the Design Doc.
Store output as: $STEP_7_OUTPUT
Fullstack mode (fullstack=Yes):
For each unit, invoke 7a then 7b sequentially (7b depends on 7a output):
7a. Backend Design Doc:
subagent_type: dev-workflows:technical-designer
description: "Generate backend Design Doc"
prompt: |
Create a backend Design Doc for the following feature based on existing code.
Operation Mode: reverse-engineer
Feature: $UNIT_NAME (from $STEP_6_OUTPUT)
Description: $UNIT_DESCRIPTION
Primary Files: $UNIT_PRIMARY_MODULES
Public Interfaces: $UNIT_PUBLIC_INTERFACES
Dependencies: $UNIT_DEPENDENCIES
Unit Inventory: $UNIT_INVENTORY
Parent PRD: $APPROVED_PRD_PATH
Focus on: API contracts, data layer, business logic, service architecture.
Document current architecture as-is. Use Unit Inventory as completeness baseline.
Store output as: $STEP_7a_OUTPUT
7b. Frontend Design Doc:
subagent_type: dev-workflows-frontend:technical-designer-frontend
description: "Generate frontend Design Doc"
prompt: |
Create a frontend Design Doc for the following feature based on existing code.
Operation Mode: reverse-engineer
Feature: $UNIT_NAME (from $STEP_6_OUTPUT)
Description: $UNIT_DESCRIPTION
Primary Files: $UNIT_PRIMARY_MODULES
Public Interfaces: $UNIT_PUBLIC_INTERFACES
Dependencies: $UNIT_DEPENDENCIES
Unit Inventory: $UNIT_INVENTORY
Parent PRD: $APPROVED_PRD_PATH
Backend Design Doc: $STEP_7a_OUTPUT
Reference backend Design Doc for API contracts.
Focus on: component hierarchy, state management, UI interactions, data fetching.
Document current architecture as-is. Use Unit Inventory as completeness baseline.
Store output as: $STEP_7b_OUTPUT
Standard mode: Verify $STEP_7_OUTPUT.
Fullstack mode: Verify each Design Doc separately.
Agent tool invocation (per Design Doc):
subagent_type: dev-workflows:code-verifier
description: "Verify Design Doc consistency"
prompt: |
Verify consistency between Design Doc and code implementation.
doc_type: design-doc
document_path: $STEP_7_OUTPUT (or $STEP_7a_OUTPUT / $STEP_7b_OUTPUT)
verbose: false
Note: Omit code_paths — the verifier independently discovers code scope from the document.
Store output as: $STEP_8_OUTPUT
Required Input: $STEP_8_OUTPUT (verification JSON from Step 8)
Agent tool invocation (per Design Doc):
subagent_type: dev-workflows:document-reviewer
description: "Review Design Doc"
prompt: |
Review the following Design Doc considering code verification findings.
doc_type: DesignDoc
target: $STEP_7_OUTPUT (or $STEP_7a_OUTPUT / $STEP_7b_OUTPUT)
mode: composite
code_verification: $STEP_8_OUTPUT
## Parent PRD
$APPROVED_PRD_PATH
## Additional Review Focus
- Technical accuracy of documented interfaces
- Consistency with parent PRD scope
- Completeness of unit boundary definitions
Store output as: $STEP_9_OUTPUT
Trigger Conditions (same as Step 5):
$STEP_8_OUTPUTAgent tool invocation (per Design Doc):
subagent_type: dev-workflows:technical-designer (or dev-workflows-frontend:technical-designer-frontend for frontend Design Docs)
description: "Revise Design Doc"
prompt: |
Update Design Doc based on review feedback and code verification results.
Operation Mode: update
Existing Design Doc: $STEP_7_OUTPUT (or $STEP_7a_OUTPUT / $STEP_7b_OUTPUT)
## Review Feedback
$STEP_9_OUTPUT
## Code Verification Results
$STEP_8_OUTPUT
Address discrepancies by severity. Critical and major items require correction.
Minor items: correct if straightforward, otherwise leave as-is with rationale.
Loop Control: Maximum 2 revision cycles. After 2 cycles, flag for human review regardless of status.
Next: Proceed to next unit. After all units → Final Report.
Output summary including:
| Error | Action |
|---|---|
| Discovery finds nothing | Ask user for project structure hints |
| Generation fails | Log failure, continue with other units, report in summary |
| consistencyScore < 50 | Flag for mandatory human review — require explicit human approval |
| Review rejects after 2 revisions | Stop loop, flag for human intervention |