Explain Code Prompt — the Understanding Contract
"Explain this code" gets line-by-line narration. The understanding contract gets strategy, audience-fit, design decisions, and inference labeled as inference.
Explain a system's shape, not its statements: layers and their owners, boundary contracts, dependency direction, and one request traced through every handoff.
Architecture explanations fail when they describe files instead of structure. This prompt uses the architecture mode's strategy: identify the layers and the responsibility each owns, trace what each module exposes and hides, map dependency direction explicitly — flagging cycles and inversions — and follow the data through every boundary. The senior-developer audience keeps it at rationale level: why the boundaries sit where they sit, what changes together, what the isolation buys. The learning note demands the one-paragraph summary a new architect could repeat — shape, key boundaries, and the one rule never to break.
Name the layers and owners
Each module gets a one-line responsibility — structure first, files second.
Map direction, flag cycles
What depends on what is stated explicitly; cycles and inversions are findings of fact, not judgments.
Trace one real request
A representative request walks every layer, naming each handoff — the shape becomes concrete.
It explains, it does not judge. The NON-GOALS forbid it: "Do not review code quality — no findings, no severities, no verdicts." The EXPLANATION STRATEGY maps layers, boundary contracts, and dependency direction — flagging cycles and inversions as facts, not judgments — so you get the current-state shape for a design review, with the quality call left to you.
The ASSUMPTIONS section forces separation: every statement about intent, history, or rationale must be labeled an INFERENCE unless the code evidences it via a comment, test, or telling name, and where behavior is unknowable it must say "cannot be determined from this code" rather than fill the gap with a plausible story. The output ends with open questions for the team.
The AUDIENCE PROFILE assumes anything readable from the code is already understood and spends the explanation on "why this design, what constraints shaped it, where it is fragile" — explicitly not walking the code line by line. That calibration is why it traces one representative request through every boundary and produces a one-paragraph summary a new architect could repeat, rather than narrating statements.
"Explain this code" gets line-by-line narration. The understanding contract gets strategy, audience-fit, design decisions, and inference labeled as inference.
For code whose authors are gone: reconstruct likely intent as labeled inference, hunt undocumented assumptions, and end with a maintenance brief — what's safe to touch.
Explain the idea before the implementation: numbered steps with their contribution, honest best/worst-case complexity, and the alternatives each decision point rejected.
"Review this code" gets shallow comments. The review contract gets findings with severities, a checklist, and a verdict.
"Refactor this code" invites silent behavior changes. The refactoring contract preserves business rules, outputs, and side effects — and flags uncertainty instead of deciding it.
"Fix this error" gets guesses. The investigation contract gets a ten-stage diagnosis: facts separated from assumptions, alternatives weighed, fixes justified.
Build code explanation prompts — mode, audience, and depth turn into an understanding contract that teaches, not narrates.
The full path to taming an inherited codebase — understand it, document its architecture, pin its behavior with tests, then refactor, modernize, review, speed up, and ship it without breaking what works.
Recover a legacy system's architecture before you change it — package the codebase context, explain the current structure, surface the risks and seams, then document the recovered architecture.
Ask AI to "explain this codebase" and you get generic architecture and "read the controllers" — no reading order, no flow, nothing to act on. Here's how to explain a codebase for onboarding: a map of folders and flow, a reading path, safe first tasks, and the unknowns to confirm.
The new engineer asks how the system actually works and gets a whiteboard photo from two years ago, or an AI answer that confidently names a queue that isn't there. Here is how to document system architecture with AI: the current state, with every component traced to a fact or marked unconfirmed.