Deep codebase analysis to generate 8 comprehensive documentation files. Adapts based on path choice - Greenfield extracts business logic only (tech-agnostic), Brownfield extracts business logic + technical implementation (tech-prescriptive). This is Step 2 of 6 in the reverse engineering process.
Inherits all available tools
Additional assets for this skill
This skill inherits all available tools. When active, it can use any tool Claude has access to.
templates/bmad/architecture.mdtemplates/bmad/coding-standards.mdtemplates/bmad/index.mdtemplates/bmad/prd.mdtemplates/bmad/project-structure.mdtemplates/bmad/tech-stack.mdStep 2 of 6 in the Reverse Engineering to Spec-Driven Development process.
Estimated Time: 30-45 minutes
Prerequisites: Step 1 completed (analysis-report.md and path selection)
Output: 9 comprehensive documentation files in docs/reverse-engineering/
Path-Dependent Behavior:
Use this skill when:
Trigger Phrases:
This skill performs deep codebase analysis and generates 9 comprehensive documentation files.
Content adapts based on your path:
/speckit.analyze validation9 Documentation Files Generated:
Load state file to check detection type and route:
# Check what kind of application we're analyzing
DETECTION_TYPE=$(cat .stackshift-state.json | jq -r '.detection_type // .path')
echo "Detection: $DETECTION_TYPE"
# Check extraction approach
ROUTE=$(cat .stackshift-state.json | jq -r '.route // .path')
echo "Route: $ROUTE"
# Check spec output location (Greenfield only)
SPEC_OUTPUT=$(cat .stackshift-state.json | jq -r '.config.spec_output_location // "."')
echo "Writing specs to: $SPEC_OUTPUT"
# Create output directories if needed
if [ "$SPEC_OUTPUT" != "." ]; then
mkdir -p "$SPEC_OUTPUT/docs/reverse-engineering"
mkdir -p "$SPEC_OUTPUT/.specify/memory/specifications"
fi
State file structure (new):
{
"detection_type": "monorepo-service", // What kind of app
"route": "greenfield", // How to spec it
"implementation_framework": "speckit", // speckit or bmad
"config": {
"spec_output_location": "~/git/my-new-app",
"build_location": "~/git/my-new-app",
"target_stack": "Next.js 15..."
}
}
Check implementation framework:
IMPL_FRAMEWORK=$(cat .stackshift-state.json | jq -r '.implementation_framework // "speckit"')
echo "Framework: $IMPL_FRAMEWORK"
File write locations by framework:
| Framework | Route | Where Files Go |
|---|---|---|
| speckit | Any | ./docs/reverse-engineering/ (8 files) |
| bmad | Any | ./docs/ + ./docs/architecture/ (6 files) |
Spec Kit output structure:
docs/reverse-engineering/
├── functional-specification.md
├── integration-points.md
├── configuration-reference.md
├── data-architecture.md
├── operations-guide.md
├── technical-debt-analysis.md
├── observability-requirements.md
├── visual-design-system.md
└── test-documentation.md
BMAD output structure:
docs/
├── index.md # Navigation index for BMAD agents
├── architecture/
│ ├── tech-stack.md # LEAN - loaded every dev session
│ ├── coding-standards.md # LEAN - loaded every dev session
│ └── project-structure.md # LEAN - loaded every dev session
├── architecture.md # Full architecture documentation
└── prd.md # Product requirements document
CRITICAL for BMAD: The docs/architecture/*.md files must be lean (< 500 lines each) because BMAD's dev agent loads them into context on EVERY interaction. Keep them focused on rules and patterns the agent needs to follow.
Extraction approach based on detection + route:
| Detection Type | + Greenfield | + Brownfield |
|---|---|---|
| Monorepo Service | Business logic only (tech-agnostic) | Full implementation + shared packages (tech-prescriptive) |
| Nx App | Business logic only (framework-agnostic) | Full Nx/Angular implementation details |
| Generic App | Business logic only | Full implementation |
How it works:
detection_type determines WHAT patterns to look for (shared packages, Nx project config, monorepo structure, etc.)route determines HOW to document them (tech-agnostic vs tech-prescriptive)Examples:
Approach depends on path:
Use the Task tool with subagent_type=stackshift:code-analyzer (or Explore as fallback) to analyze:
See operations/backend-analysis.md
See operations/frontend-analysis.md
See operations/infrastructure-analysis.md
See operations/testing-analysis.md
Create docs/reverse-engineering/ directory and generate all 8 documentation files.
See operations/generate-docs.md for templates and guidelines.
Output depends on implementation_framework in .stackshift-state.json:
docs/reverse-engineering/docs/ and docs/architecture/Focus: Business logic, WHAT the system does (not HOW)
Sections:
Critical: Framework-agnostic, testable, measurable
Complete inventory of all configuration:
All data models and API contracts:
How to deploy and maintain:
Issues and improvements:
Logging, monitoring, alerting:
UI/UX patterns:
Testing requirements:
IMPORTANT: BMAD dev agents load docs/architecture/*.md files on EVERY interaction. Keep them lean (< 500 lines each).
Navigation index for BMAD agents:
# Project Documentation Index
## Architecture (Always Loaded)
- [Tech Stack](architecture/tech-stack.md)
- [Coding Standards](architecture/coding-standards.md)
- [Project Structure](architecture/project-structure.md)
## Full Documentation
- [Architecture](architecture.md)
- [Product Requirements](prd.md)
## Generated by StackShift
Date: [timestamp]
Route: [greenfield/brownfield]
Keep under 100 lines. Technologies and versions only:
# Tech Stack
## Frontend
- React 18.2 with TypeScript 5.3
- TailwindCSS 3.4
- Next.js 14 (App Router)
## Backend
- Node.js 20 LTS
- Express 4.x / tRPC
## Database
- PostgreSQL 15
- Prisma ORM 5.x
## Infrastructure
- AWS (Lambda, RDS, S3)
- Vercel for frontend
Keep under 150 lines. Rules the dev agent must follow:
# Coding Standards
## Patterns
- Error handling: Custom AppError class with try/catch
- Validation: Zod schemas at API boundaries
- Logging: Winston with structured JSON
- Auth: JWT tokens, middleware pattern
## Conventions
- File naming: kebab-case for files, PascalCase for components
- 2-space indentation, no semicolons
- Prefer async/await over .then()
- Always use TypeScript strict mode
## Testing
- Unit tests with Vitest
- E2E with Playwright
- Minimum 80% coverage for new code
Keep under 100 lines. Directory map only:
# Project Structure
src/
├── app/ # Next.js App Router pages
├── components/ # React components
│ ├── ui/ # Primitives (Button, Input)
│ └── features/ # Feature components
├── lib/ # Shared utilities
├── server/ # API routes and services
│ ├── api/ # tRPC routers
│ └── db/ # Prisma client
└── types/ # TypeScript types
Key files:
- src/lib/auth.ts - Authentication utilities
- src/server/db/schema.prisma - Database schema
- src/app/api/[...trpc]/route.ts - API entry
Complete architecture documentation (can be longer):
Features as requirements for BMAD PM agent:
For GitHub Spec Kit (implementation_framework: speckit):
docs/reverse-engineering/ directory createdFor BMAD Method (implementation_framework: bmad):
docs/ and docs/architecture/ directories createddocs/architecture/*.md files are LEAN (< 500 lines each)docs/index.md provides navigation for agentsdocs/prd.md contains features as requirementsdocs/architecture.md contains full technical details*workflow-init (Gears 3-5 simplified, Gear 6 hands off)Once all documentation is generated and reviewed:
For GitHub Spec Kit:
/stackshift.create-specs to transform docs into .specify/ specsFor BMAD Method:
*workflow-init/stackshift.cruise-control to auto-complete remaining gearsDO:
DON'T:
Use the Explore agent to ensure you find:
Each document must be:
subagent_type=stackshift:code-analyzer for path-aware extractionsubagent_type=Explore if StackShift agent not availablestackshift:code-analyzer agent understands greenfield vs brownfield routes automaticallyRemember: This is Step 2 of 6. The documentation you generate here will be transformed into formal specifications in Step 3.