- name
- reverse
- scope
- partial
- description
- [UDS] System archeology โ reverse engineer an existing system across the Logic, Data, and Runtime dimensions.
Use when: documenting an undocumented system, recovering specifications from existing code, mapping an unknown data model or runtime topology.
Not for: assessing health and risk before a feature โ use /discover; deriving tests forward from an approved spec โ use /spec-derive.
Keywords: reverse engineering, system archeology, legacy code, spec extraction, data model, runtime, ๅๅๅทฅ็จ, ็ณป็ตฑ่ๅค, ่ฆๆ ผๆๅ.
- allowed-tools
- Read, Grep, Glob, Bash(pg_dump:*), Bash(mysql:*), Bash(sqlite3:*), Bash(npm run:*), Bash(cat:*), Bash(docker:*)
- argument-hint
- [spec|data|runtime|bdd|tdd] <input>
- status
- stable
# Reverse Engineering Assistant | ๅๅๅทฅ็จๅฉๆ
System archeology framework: reverse engineer existing systems across three dimensions โ **Logic**, **Data**, and **Runtime**.
็ณป็ตฑ่ๅคๆกๆถ๏ผๅพไธๅ็ถญๅบฆๅๅๅทฅ็จๆขๆ็ณป็ตฑโโ**้่ผฏ**ใ**่ณๆ**ใ**ๅท่ก็ฐๅข**ใ
## Three Dimensions | ไธๅคง็ถญๅบฆ
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ System Archeology Framework โ
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Logic โ Data โ Runtime โ
โ (spec) โ (data) โ (runtime) โ
โโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ APIs โ DB Schemas โ Logs & Error Patterns โ
โ Modules โ ORMs/Models โ Config & Environment โ
โ Flows โ Migrations โ Metrics & Performance โ
โ Tests โ Seed Data โ Infra & Deployment โ
โโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
## Subcommands | ๅญๅฝไปค
| Subcommand | Dimension | Input | Output | ่ชชๆ |
|------------|-----------|-------|--------|------|
| *(none)* | All | Project root | Full Archeology Report | ไธ็ถญๅบฆๅ
จ้ขๅๆ |
| `spec` | Logic | Code files/dirs | `SPEC-XXX.md` | ๅพ็จๅผ็ขผๆๅ่ฆๆ ผ |
| `data` | Data | DB schemas, ORMs, migrations | Data Model Spec | ๅๆ่ณๆๆจกๅ่็ตๆง |
| `runtime` | Runtime | Logs, configs, metrics | Runtime Baseline | ๅๆๅท่ก็ฐๅขๅบๆบ |
| `bdd` | โ | `SPEC-XXX.md` | `.feature` | ๅฐ AC ่ฝ็บ Gherkin |
| `tdd` | โ | `.feature` | Coverage Report | ๅๆๆธฌ่ฉฆ่ฆ่็ |
## Full Analysis Mode | ๅ
จ้ขๅๆๆจกๅผ
When `/reverse` is invoked without a subcommand, execute all three dimensions sequentially:
1. **Data** โ Scan schemas, ORMs, migrations
2. **Runtime** โ Analyze logs, configs, deployment
3. **Logic (spec)** โ Extract APIs, flows, tests โ Generate SPEC
Output: Integrated **System Archeology Report** combining all three dimensions.
## Dimension Details | ็ถญๅบฆ่ฉณๆ
### spec: Logic Dimension (ๆขๆ)
1. **Scan** - Read source files and identify public APIs, data flows, and business logic
2. **Classify** - Tag each finding as `[Confirmed]`, `[Inferred]`, or `[Unknown]`
3. **Structure** - Organize into SDD spec format with Acceptance Criteria
4. **Attribute** - Cite every reversed item with `file:line` source reference
### data: Data Dimension (ๆฐๅข)
1. **Discover** - Find database schemas, ORM models, migration files, seed data
2. **Map** - Build entity-relationship model from code evidence
3. **Classify** - Tag relationships as `[Confirmed]` (FK constraints) or `[Inferred]` (code patterns)
4. **Report** - Output data model spec with:
- Entity list with fields and types
- Relationship map (1:1, 1:N, M:N)
- Index and constraint inventory
- Migration history summary
- Data flow paths (write โ read)
**Evidence sources**: `schema.prisma`, `*.migration.*`, `models/`, `entities/`, `knexfile.*`, `sequelize`, `typeorm`, SQL files, `docker-compose.yml` (DB services)
### runtime: Runtime Dimension (ๆฐๅข)
1. **Scan configs** - Environment variables, config files, feature flags
2. **Analyze logs** - Log patterns, error frequency, log levels
3. **Check infra** - Docker configs, CI/CD pipelines, deployment manifests
4. **Baseline** - Output runtime baseline with:
- Environment variable inventory (names only, **never values/secrets**)
- Config file map and hierarchy
- External service dependencies (APIs, queues, caches)
- Deployment topology (containers, services)
- Health check and monitoring endpoints
**Evidence sources**: `.env.example`, `docker-compose.yml`, `Dockerfile`, `*.config.*`, CI/CD files, `k8s/`, log files (patterns only)
**Security**: NEVER output actual secret values. Only list variable names and describe their purpose.
## Anti-Hallucination Rules | ้ฒๅนป่ฆบ่ฆๅ
| Rule | Requirement | ่ฆๆฑ |
|------|-------------|------|
| **Certainty Tags** | Use `[Confirmed]`, `[Inferred]`, `[Unknown]` for all findings | ๆๆ็ผ็พ้ ๆจๆณจ็ขบๅฎๆง |
| **Source Attribution** | Cite `file:line` for every reversed item | ๆฏ้
ๅๅ็ตๆ้ ๅผ็จไพๆบ |
| **No Fabrication** | Never invent APIs or behaviors not found in code | ไธๅพๆ้ ็จๅผ็ขผไธญไธๅญๅจ็ API ๆ่ก็บ |
| **No Secrets** | Never output secret values from configs or env files | ไธๅพ่ผธๅบ่จญๅฎๆชๆ็ฐๅข่ฎๆธ็ๅฏ้ฐๅผ |
## Usage | ไฝฟ็จๆนๅผ
```
/reverse - Full 3-dimension analysis | ไธ็ถญๅบฆๅ
จ้ขๅๆ
/reverse spec src/auth/ - Logic: extract spec | ้่ผฏ๏ผๆๅ่ฆๆ ผ
/reverse data - Data: analyze schemas & models | ่ณๆ๏ผๅๆ็ตๆง
/reverse runtime - Runtime: analyze configs & infra | ๅท่ก็ฐๅข๏ผๅๆ้
็ฝฎ
/reverse bdd specs/SPEC-AUTH.md - Convert spec ACs to Gherkin
/reverse tdd features/auth.feature - Analyze test coverage
```
## Next Steps Guidance | ไธไธๆญฅๅผๅฐ
After `/reverse` (full or `spec`) completes, the AI assistant should suggest:
> **็ณป็ตฑ่ๅคๅฎๆใๅปบ่ญฐไธไธๆญฅ / System archeology complete. Suggested next steps:**
> - ๅท่ก `/sdd` ๅฏฉๆฅไธฆๆ ธๅๆญค่ฆๆ ผ โญ **Recommended / ๆจ่ฆ** โ Review and approve the generated spec
> - ๅท่ก `/derive` ๅพ่ฆๆ ผๆจๅฐๆธฌ่ฉฆ โ Derive tests from spec (requires approval first)
> - ๅฏฉๆฅ่ฆๆ ผไธญ็ `[Inferred]` ๅ `[Unknown]` ๆจ่จ โ Review uncertainty tags manually
## Reference | ๅ่
- [BDD Extraction Workflow Guide](./bdd-extraction.md) โ Read it when extracting BDD scenarios out of an existing spec.
- [TDD Analysis Workflow Guide](./tdd-analysis.md) โ Read it when analysing test coverage against scenarios and finding the gaps.
- Step-by-step workflow: [workflow.md](./workflow.md) โ the reverse-engineering phases in order (code scanning, data models, configuration, test analysis, coverage). Read it when actually running the process rather than deciding whether to.
- Detailed guide: [guide.md](./guide.md)
- Core standard: [reverse-engineering-standards.md](../../core/reverse-engineering-standards.md)
## AI Agent Behavior | AI ไปฃ็่ก็บ
> ๅฎๆด็ AI ่ก็บๅฎ็พฉ่ซๅ้ฑๅฐๆ็ๅฝไปคๆไปถ๏ผ[`/reverse`](../commands/reverse.md#ai-agent-behavior--ai-ไปฃ็่ก็บ)
>
> For complete AI agent behavior definition, see the corresponding command file: [`/reverse`](../commands/reverse.md#ai-agent-behavior--ai-ไปฃ็่ก็บ)
View on GitHub