agentleFS
fapariciorfaparicior/sdlc-skills/skills/evolution/reverse-engineer-domain/SKILL.md

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/.

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
  1. Distinctive:

    When analyzing legacy code, determine the target location based on domain clarity:

    line 52
  2. Very specific:

    Add Domain Tags to enable subsequent clustering and context mapping.

    line 63
  3. Very specific:

    Call read_file on templates/invariants.md, fill out every section verbatim, and remove all instructional commentary.

    line 93
  4. Distinctive:

    Before ending your turn, verify every item below with concrete evidence (not just a checkmark).

    line 98

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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>

  1. 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).
  2. TEMPLATE LOCK: Reconstructing template headers or tables from internal memory is strictly forbidden. You MUST call read_file on templates/business-rules.md or templates/invariants.md before generating any file.
  3. MANDATORY TRIAGE ROUTING:
    • High-confidence bounded context -> docs/product/bounded-contexts/{context}/{business-rules,invariants}/
    • Ambiguous/tangled legacy -> docs/product/discovered/{business-rules,invariants}/ with BR-RAW-XXX / INV-RAW-XXX IDs and exact file:line pointers.
  4. 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}/ OR docs/product/discovered/{business-rules,invariants}/
  • SOURCE_TEMPLATES: templates/business-rules.md and templates/invariants.md (MUST call read_file before 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

AspectBusiness Rule (BR-XXX)Domain Invariant (INV-XXX)
ScopeBroad (Workflows, policies, formulas, eligibility)Strict (Transactional consistency, state integrity)
StrictnessAllows business fallbacks or compensating actionsAbsolute. Cannot be violated under any circumstance
EnforcementHandled by UI, Workflow Handlers, or Domain ServicesProtected synchronously inside the Aggregate boundary
If ViolatedBusiness 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:

ScenarioConfidenceOutput Destination
Clear Bounded ContextHigh (module or domain is clearly identified)docs/product/bounded-contexts/{context}/business-rules/<br>docs/product/bounded-contexts/{context}/invariants/
Ambiguous / Tangled LegacyLow / 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 Tags to enable subsequent clustering and context mapping.

3. Natural Language Activation

This skill is conversational and automatically infers your intent:

IntentNatural Language ExamplesAction 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)

  1. Review the input for conditional branching (if/else), fee calculations, discounts, eligibility criteria, status transitions, or orchestration workflows.
  2. Formulate the rule using the standard pattern:

    When [Trigger / Condition], then [Apply this Policy / Calculation], otherwise [Fallback Action].

  3. Fill out templates/business-rules.md and remove all instructional commentary.

Extracting Invariants (INV-XXX)

  1. Scan for transaction boundaries, capacity limits, structural uniqueness, or conditions that throw fatal domain exceptions.
  2. State the invariant as an absolute truth:

    Invariant: [e.g., The total registered attendees can never exceed venue capacity.]

  3. Define the monitored fields and write Gherkin scenarios for positive (valid) and negative (violation blocked) cases.
  4. Call read_file on templates/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:line enforcement sites read via read_file: <file:line list>
  • Template Read Evidence: Exact templates/business-rules.md and/or templates/invariants.md paths passed to read_file: <paths>
  • Triage & Output Evidence: Exact output paths written (bounded-contexts/{ctx}/ vs discovered/ with RAW prefix) and confirmation that all 6 (BR) or 7 (INV) sections are present: <paths> </self_validation_gate>

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.