Explain My Code
Analyze a complete code repository as a senior software architect and produce one self-contained, production-grade Markdown document that lets anyone new to the project fully understand the system with no handover meetings or outside help.
When to Use
- User asks to document, explain, or map a codebase or repository
- User wants an onboarding document for people new to the project
- User wants a system/architecture overview with Mermaid diagrams
- User points at a repo and asks "what does this do / how does it work" AND wants it captured as a written document, not a one-line reply
Do NOT use for bug-finding code review, refactoring plans, or diagram-only output (see negative boundary in description).
Co-Load Precedence
When co-loading with codebase-to-mermaid: that skill owns standalone diagram generation; this skill embeds diagrams inside the full document. When co-loading with refactoring-analyst: that skill owns refactor planning; this skill only describes the system (Section 13 suggests improvements at a high level, it does not plan the refactor). When co-loading with a code-review skill (e.g. wordpress-architect-review): review owns defect findings; this skill owns architecture explanation (Section 12 lists observations/risks but does not perform line-level review).
Workflow
Phase 1: SCOPE THE TARGET
- Determine the repository root. Default to the current working directory. If the user named a path, use that.
- If no code is present at the target, STOP and ask the user for the repo path (see Error Handling).
- Map the top-level layout with
Glob (**/*) and read manifest/config files first (package.json, pom.xml, go.mod, requirements.txt, Cargo.toml, *.csproj, Dockerfile, compose files, CI configs).
Phase 2: IDENTIFY FOUNDATIONS
- Identify tech stack: languages, frameworks, frontend/backend/infra split, package managers.
- Classify architecture: monolith vs microservices vs modular.
- Locate entry points (main files, server bootstrap, CLI roots) and config loading.
Phase 3: TRAVERSE SYSTEMATICALLY
- Walk folder-by-folder, service-by-service, module-by-module.
- Infer design patterns (MVC, Clean, Hexagonal, Factory, Observer, etc.) - record where and why each is used.
- Trace core business logic, dependency flow, and data flow (input → processing → storage).
- For large repos, analyze in chunks; accumulate knowledge and refine earlier sections as understanding improves (see Error Handling: large repo).
Phase 4: WRITE THE DOCUMENT
- Produce ALL 13 sections in the order under Output Format. Do not skip any section.
- Use real file names, classes, and functions from the repo - never generic placeholders.
- Embed Mermaid diagrams (
graph TD, sequenceDiagram) where they clarify architecture and flow.
- Where behavior is undocumented, infer logically and explicitly state the assumption.
Phase 5: VERIFY BEFORE DELIVERY
- Confirm every one of the 13 sections is present and non-shallow.
- Confirm cited file/class/function names actually exist in the repo (
Grep-verifiable - no invented symbols).
- Confirm Mermaid blocks are syntactically valid.
- Write the result to
CODEBASE_DOCUMENTATION.md at the repo root (or a user-specified path) with Write, then tell the user the path.
Output Format
Single Markdown file, default name CODEBASE_DOCUMENTATION.md, containing these sections in order:
- Project Overview - purpose, high-level functionality, key use cases
- System Architecture - explanation, monolith/microservices/hybrid, Mermaid
graph TD diagram
- Repository Structure - folder hierarchy, role of each major directory, module responsibilities
- Tech Stack & Dependencies - languages, frameworks, external libraries, package managers, dependency graph if possible
- Core Components / Services - per component: responsibility, key classes/functions, interactions
- Application Flow - 6.1 Startup flow (entry point, init sequence, config, DI); 6.2 Request/execution flow; 6.3 Auth flow if applicable; 6.4 Data flow; include Mermaid
sequenceDiagram
- Key Design Patterns - patterns used, where and why
- Database & Models - schema overview, ORM usage, entity relationships
- External Integrations - APIs, third-party services, queues, caches
- Configuration & Environment - env vars, config files, build configs
- Build & Deployment - build steps, scripts, CI/CD if present
- Observations & Risks - code smells, tight coupling, scalability concerns, missing abstractions
- Suggestions for Improvement - refactoring ideas, performance, architecture alternatives
Constraints (from source prompt, preserved):
- Be precise and technical; avoid generic explanations.
- Do NOT give shallow summaries or skip flows/architecture.
- Do NOT assume undocumented behavior without stating the reasoning.
- The deliverable is the document file; keep it complete, structured, and self-sufficient for onboarding.
Error Handling
No repository / empty target: Ask the user for the repo path. Do not fabricate documentation for code that was not read.
Large repo (cannot read fully in one pass): Tell the user, then analyze in chunks - manifests and entry points first, then per-module. Accumulate findings and refine earlier sections. Note any directories sampled rather than fully read.
Ambiguous path (multiple repos in directory): Ask which repo to document before proceeding.
Generated/vendored code (node_modules, vendor, build, dist): Exclude from traversal; mention it was skipped.
Section genuinely not applicable (e.g., no database): Keep the heading, state "Not applicable - ". Do not silently drop a section.
Quality Gates
Examples
Standard case: User runs the skill in a Node/Express + React repo. The skill reads package.json files, identifies a modular monolith, walks server/ and client/, and writes CODEBASE_DOCUMENTATION.md with all 13 sections, a graph TD of the request path, and a sequenceDiagram of an authenticated API call - citing real route files and controllers.
Edge case: User points at a directory containing two services and no top-level manifest. The skill detects ambiguity, asks which service to document (or confirms "both as one system"), excludes node_modules/dist, marks Section 8 "Not applicable - no database layer found", and states the assumption that inter-service calls are HTTP based on observed fetch usage.
1---2name: explain-my-code3description: Explain My Code4---5# Explain My Code67Analyze a complete code repository as a senior software architect and produce one self-contained, production-grade Markdown document that lets anyone new to the project fully understand the system with no handover meetings or outside help.89## When to Use1011- User asks to document, explain, or map a codebase or repository12- User wants an onboarding document for people new to the project13- User wants a system/architecture overview with Mermaid diagrams14- User points at a repo and asks "what does this do / how does it work" AND wants it captured as a written document, not a one-line reply1516Do NOT use for bug-finding code review, refactoring plans, or diagram-only output (see negative boundary in description).1718## Co-Load Precedence1920When co-loading with codebase-to-mermaid: that skill owns standalone diagram generation; this skill embeds diagrams inside the full document. When co-loading with refactoring-analyst: that skill owns refactor planning; this skill only describes the system (Section 13 suggests improvements at a high level, it does not plan the refactor). When co-loading with a code-review skill (e.g. wordpress-architect-review): review owns defect findings; this skill owns architecture explanation (Section 12 lists observations/risks but does not perform line-level review).2122## Workflow2324### Phase 1: SCOPE THE TARGET25261. Determine the repository root. Default to the current working directory. If the user named a path, use that.272. If no code is present at the target, STOP and ask the user for the repo path (see Error Handling).283. Map the top-level layout with `Glob` (`**/*`) and read manifest/config files first (package.json, pom.xml, go.mod, requirements.txt, Cargo.toml, *.csproj, Dockerfile, compose files, CI configs).2930### Phase 2: IDENTIFY FOUNDATIONS31321. Identify tech stack: languages, frameworks, frontend/backend/infra split, package managers.332. Classify architecture: monolith vs microservices vs modular.343. Locate entry points (main files, server bootstrap, CLI roots) and config loading.3536### Phase 3: TRAVERSE SYSTEMATICALLY37381. Walk folder-by-folder, service-by-service, module-by-module.392. Infer design patterns (MVC, Clean, Hexagonal, Factory, Observer, etc.) - record where and why each is used.403. Trace core business logic, dependency flow, and data flow (input → processing → storage).414. For large repos, analyze in chunks; accumulate knowledge and refine earlier sections as understanding improves (see Error Handling: large repo).4243### Phase 4: WRITE THE DOCUMENT44451. Produce ALL 13 sections in the order under Output Format. Do not skip any section.462. Use real file names, classes, and functions from the repo - never generic placeholders.473. Embed Mermaid diagrams (`graph TD`, `sequenceDiagram`) where they clarify architecture and flow.484. Where behavior is undocumented, infer logically and explicitly state the assumption.4950### Phase 5: VERIFY BEFORE DELIVERY51521. Confirm every one of the 13 sections is present and non-shallow.532. Confirm cited file/class/function names actually exist in the repo (`Grep`-verifiable - no invented symbols).543. Confirm Mermaid blocks are syntactically valid.554. Write the result to `CODEBASE_DOCUMENTATION.md` at the repo root (or a user-specified path) with `Write`, then tell the user the path.5657## Output Format5859Single Markdown file, default name `CODEBASE_DOCUMENTATION.md`, containing these sections in order:60611. **Project Overview** - purpose, high-level functionality, key use cases622. **System Architecture** - explanation, monolith/microservices/hybrid, Mermaid `graph TD` diagram633. **Repository Structure** - folder hierarchy, role of each major directory, module responsibilities644. **Tech Stack & Dependencies** - languages, frameworks, external libraries, package managers, dependency graph if possible655. **Core Components / Services** - per component: responsibility, key classes/functions, interactions666. **Application Flow** - 6.1 Startup flow (entry point, init sequence, config, DI); 6.2 Request/execution flow; 6.3 Auth flow if applicable; 6.4 Data flow; include Mermaid `sequenceDiagram`677. **Key Design Patterns** - patterns used, where and why688. **Database & Models** - schema overview, ORM usage, entity relationships699. **External Integrations** - APIs, third-party services, queues, caches7010. **Configuration & Environment** - env vars, config files, build configs7111. **Build & Deployment** - build steps, scripts, CI/CD if present7212. **Observations & Risks** - code smells, tight coupling, scalability concerns, missing abstractions7313. **Suggestions for Improvement** - refactoring ideas, performance, architecture alternatives7475Constraints (from source prompt, preserved):76- Be precise and technical; avoid generic explanations.77- Do NOT give shallow summaries or skip flows/architecture.78- Do NOT assume undocumented behavior without stating the reasoning.79- The deliverable is the document file; keep it complete, structured, and self-sufficient for onboarding.8081## Error Handling8283**No repository / empty target:** Ask the user for the repo path. Do not fabricate documentation for code that was not read.8485**Large repo (cannot read fully in one pass):** Tell the user, then analyze in chunks - manifests and entry points first, then per-module. Accumulate findings and refine earlier sections. Note any directories sampled rather than fully read.8687**Ambiguous path (multiple repos in directory):** Ask which repo to document before proceeding.8889**Generated/vendored code (node_modules, vendor, build, dist):** Exclude from traversal; mention it was skipped.9091**Section genuinely not applicable (e.g., no database):** Keep the heading, state "Not applicable - <reason>". Do not silently drop a section.9293## Quality Gates9495- [ ] All 13 sections present and substantive (no shallow summaries)96- [ ] Cited file/class/function names verified to exist in the repo (accuracy gate)97- [ ] At least one architecture diagram and one flow diagram in valid Mermaid syntax (format gate)98- [ ] Assumptions about undocumented behavior are explicitly labeled99- [ ] Output written to a `.md` file and its path reported to the user100101## Examples102103**Standard case:** User runs the skill in a Node/Express + React repo. The skill reads package.json files, identifies a modular monolith, walks `server/` and `client/`, and writes `CODEBASE_DOCUMENTATION.md` with all 13 sections, a `graph TD` of the request path, and a `sequenceDiagram` of an authenticated API call - citing real route files and controllers.104105**Edge case:** User points at a directory containing two services and no top-level manifest. The skill detects ambiguity, asks which service to document (or confirms "both as one system"), excludes `node_modules`/`dist`, marks Section 8 "Not applicable - no database layer found", and states the assumption that inter-service calls are HTTP based on observed `fetch` usage.