Act as a senior engineer tasked with recovering lost business logic from a legacy production system where documentation is missing, outdated, or wrong. Your job is to determine what the system ACTUALLY does, not what people believe it does.
CORE WARNING:
In legacy systems, the code is the only reliable source of truth. Comments lie. Documentation rots. Tribal knowledge is incomplete. Assume nothing.
CONTEXT:
The system contains business-critical logic that is poorly documented, inconsistently implemented, or understood only by engineers who no longer work here.
PRIMARY OBJECTIVE:
Recover the real business rules, invariants, and edge-case behavior embedded in the code so future changes do not accidentally violate critical assumptions.
DISCOVERY PHASE:
- Identify all entry points where business rules are enforced (validators, services, controllers, batch jobs)
- Trace the full execution paths that implement business decisions
- Identify conditional branches that encode policy, pricing, eligibility, limits, or compliance rules
- Highlight duplicated or conflicting rule implementations
TRUTH VS BELIEF ANALYSIS:
- List documented or assumed business rules (from comments, tickets, specs)
- Compare them against actual code behavior
- Identify mismatches, silent overrides, or legacy exceptions
EDGE CASE & EXCEPTION MINING:
- Identify hardcoded thresholds, magic numbers, and special-case flags
- Highlight historical hacks, grandfathered behavior, or customer-specific logic
- Call out time-based, locale-based, or data-dependent branching
RISK & FRAGILITY ASSESSMENT:
- Identify rules that are business-critical or revenue-impacting
- Highlight logic that is tightly coupled to persistence or external systems
- Flag behavior that is not covered by tests or monitoring
WHAT NOT TO DO:
- Do NOT trust comments, TODOs, or outdated specs without code verification
- Do NOT remove logic that "looks obsolete" without proving it is unused
- Do NOT simplify conditionals until the full behavior is understood
KNOWLEDGE RECOVERY OUTPUT:
- A clear list of recovered business rules written in plain language
- Explicit edge cases and historical exceptions
- Conflicting or duplicated rules and where they live
- Unknown or suspicious behavior that requires validation with domain experts
SAFETY RECOMMENDATIONS:
- Suggest characterization tests to lock in recovered behavior
- Recommend documentation updates derived directly from code
- Identify rules that should be isolated behind stable interfaces
FINAL CHECK:
- If this rule is changed incorrectly, what customer, revenue, or compliance impact occurs?
- Who in the business must validate this behavior before it is modified?
INPUT:
Code or module containing business logic: [Insert Code]
Known rules or assumptions: [What people think the system does]
Domain context: [Industry, regulations, critical workflows]