reverse-engineer-domain
Skill2 starsChanged 6 days agoMITView on GitHub
Reverse-engineer business rules and invariants from legacy or brownfield code. USE THIS SKILL when user mentions: reverse engineer, extract business rules, extract invariants, analyze legacy, software archeology, brownfield extraction, discover rules, find invariants in code, or extract domain logic from existing code. Automatically triages outputs to bounded contexts or the staging buffer docs/product/discovered/.
In this repository19 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adr-amendSkill
- adr-createSkill
- adr-review-alternativesSkill
- adr-validateSkill
- agents-maintainerSkill
- audit-docsSkill
- explore-domainSkill
- sdlc-guideSkill
- setup-sdlcSkill
- inception-workshopSkill
- prd-workshopSkill
- user-story-mappingSkill
- modify-flowSkill
- create-moduleSkill
- implement-flowSkill
- create-entity-lifecycleSkill
- create-featuresSkill
- create-flow-documentationSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 52
When analyzing legacy code, determine the target location based on domain clarity:
- Very specific: line 63
Add Domain Tags to enable subsequent clustering and context mapping.
- Very specific: line 93
Call read_file on templates/invariants.md, fill out every section verbatim, and remove all instructional commentary.
- Distinctive: line 98
Before ending your turn, verify every item below with concrete evidence (not just a checkmark).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PROTOCOL: REVERSE-ENGINEER-DOMAIN (EXECUTION LEVEL 3)
<state_machine> CURRENT_STEP -> REQUIRED_TOOL -> REQUIRED_OUTPUT -> MANDATORY_HALT Step 1: Read Source -> read_file / grep (legacy/brownfield code) -> Conditional branches, exceptions, transaction boundaries -> Continue to Step 2 Step 2: Triage -> evaluate domain confidence -> Target destination (bounded-contexts/{ctx} vs discovered/RAW) -> Continue to Step 3 Step 3: Write Rules -> read_file(templates/business-rules.md, invariants) -> Standardized BR-* and INV-* files with file:line traceability -> 🛑 HALT TURN (Present extracted rules) </state_machine>
<execution_invariants>
- WORKFLOW IMMUTABILITY: You may reason freely INSIDE each step to analyze legacy code, branch conditions, and domain boundaries, but you are strictly forbidden from skipping triage or improvising output formats (
workflow structure = immutable | step reasoning = flexible). - TEMPLATE LOCK: Reconstructing template headers or tables from internal memory is strictly forbidden. You MUST call
read_fileontemplates/business-rules.mdortemplates/invariants.mdbefore generating any file. - MANDATORY TRIAGE ROUTING:
- High-confidence bounded context ->
docs/product/bounded-contexts/{context}/{business-rules,invariants}/ - Ambiguous/tangled legacy ->
docs/product/discovered/{business-rules,invariants}/withBR-RAW-XXX/INV-RAW-XXXIDs and exactfile:linepointers.
- High-confidence bounded context ->
- ESCAPE HATCH: If the situation does not fit the contract, do not silently improvise and do not force-fit: declare the deviation in one line and ask. </execution_invariants>
<output_contract>
- TARGET_PATHS:
docs/product/bounded-contexts/{context}/{business-rules,invariants}/ORdocs/product/discovered/{business-rules,invariants}/ - SOURCE_TEMPLATES:
templates/business-rules.mdandtemplates/invariants.md(MUST callread_filebefore writing) - SCHEMA_INVARIANCE: Preserve every H1/H2/H3 heading, metadata field, Gherkin scenario structure, and Traceability table verbatim, and strip all instructional meta-commentary.
- ESCAPE_HATCH: Never silently omit or invent template sections. If an upstream flow/journey link (
Traces up to) does not exist yet in a brownfield repo, preserve the bullet and write"None documented yet (brownfield extraction)". </output_contract>
1. Core Distinction: Business Rules vs. Invariants
| Aspect | Business Rule (BR-XXX) | Domain Invariant (INV-XXX) |
| Scope | Broad (Workflows, policies, formulas, eligibility) | Strict (Transactional consistency, state integrity) |
| Strictness | Allows business fallbacks or compensating actions | Absolute. Cannot be violated under any circumstance |
| Enforcement | Handled by UI, Workflow Handlers, or Domain Services | Protected synchronously inside the Aggregate boundary |
| If Violated | Business handles the exception (e.g., fee, reject) | Illegal state: transaction is immediately rolled back |
2. Autonomous Triage Engine (Where to Output)
When analyzing legacy code, determine the target location based on domain clarity:
| Scenario | Confidence | Output Destination |
| Clear Bounded Context | High (module or domain is clearly identified) | docs/product/bounded-contexts/{context}/business-rules/<br>docs/product/bounded-contexts/{context}/invariants/ |
| Ambiguous / Tangled Legacy | Low / Medium (Big Ball of Mud, shared spaghetti, or unknown context) | docs/product/discovered/business-rules/<br>docs/product/discovered/invariants/ |
Staging Rules for docs/product/discovered/
- Prefix identifiers with
RAW(e.g.,BR-RAW-001,INV-RAW-001). - Include full source file and line number pointers (e.g.,
legacy/services/OrderManager.ts:145-189). - Set
Candidate Bounded Context: [TBD / Suspected: ...]. - Add
Domain Tagsto enable subsequent clustering and context mapping.
3. Natural Language Activation
This skill is conversational and automatically infers your intent:
| Intent | Natural Language Examples | Action Executed |
| File Extraction | "Extract business rules from src/legacy/order.ts", "Analyze conference.ts for invariants" | Scans the file, identifies rules and invariants, and writes them to the appropriate directory. |
| Directory / Module Extraction | "Reverse engineer the legacy billing module", "Extract domain logic from legacy/services/" | Iterates through files in the directory, compiling all discovered rules and invariants. |
| Snippet Analysis | "What business rules are in this code snippet: [code]", "Extract invariants from this logic" | Analyzes the provided code and outputs formatted rule/invariant files. |
| Staging Review | "Review discovered rules", "What rules are in the staging buffer?" | Inspects docs/product/discovered/ and summarizes candidate contexts for graduation. |
4. Extraction Instructions
Extracting Business Rules (BR-XXX)
- Review the input for conditional branching (
if/else), fee calculations, discounts, eligibility criteria, status transitions, or orchestration workflows. - Formulate the rule using the standard pattern:
When [Trigger / Condition], then [Apply this Policy / Calculation], otherwise [Fallback Action].
- Fill out
templates/business-rules.mdand remove all instructional commentary.
Extracting Invariants (INV-XXX)
- Scan for transaction boundaries, capacity limits, structural uniqueness, or conditions that throw fatal domain exceptions.
- State the invariant as an absolute truth:
Invariant: [e.g., The total registered attendees can never exceed venue capacity.]
- Define the monitored fields and write Gherkin scenarios for positive (valid) and negative (violation blocked) cases.
- Call
read_fileontemplates/invariants.md, fill out every section verbatim, and remove all instructional commentary.
<self_validation_gate> Before ending your turn, verify every item below with concrete evidence (not just a checkmark). If any item cannot be cited with real evidence from this turn, DO NOT produce your final response — return to the failed step and fix the violation first:
- Source Code Read Evidence: List the exact source files and
file:lineenforcement sites read viaread_file:<file:line list> - Template Read Evidence: Exact
templates/business-rules.mdand/ortemplates/invariants.mdpaths passed toread_file:<paths> - Triage & Output Evidence: Exact output paths written (
bounded-contexts/{ctx}/vsdiscovered/withRAWprefix) and confirmation that all 6 (BR) or 7 (INV) sections are present:<paths></self_validation_gate>
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

