| name | code-tutorial |
|---|---|
| description | Generate beginner-friendly, line-by-line code tutorials for any codebase — first a flow "main-line" doc that traces ONE user action end-to-end (file·function·line), then per-file deep-dives with inline syntax mini-lessons. Best for onboarding docs, teaching a codebase to non-experts, or explaining an unfamiliar repo. Triggers on requests like "explain this codebase line by line", "write a beginner walkthrough", "teach me how this repo works for a total beginner". |
Turn any codebase into a structured, beginner-friendly tutorial series. The audience is a "beginner's beginner" — someone who may not know the language's syntax yet. The output is a set of Markdown docs that teach the repo the way a patient mentor would: first the big picture, then every line.
The order matters and is the heart of this skill:
Phase 1 — build the FLOW MAIN-LINE first (one doc that follows a single user action end-to-end), then Phase 2 — write the per-file line-by-line deep-dives.
Building the main-line first gives both you and the reader a global map, so every later deep-dive has a known place in the whole. Doing it the other way around (files first) leaves the reader assembling a puzzle with no picture on the box.
Use this skill when the user wants to teach or document a codebase for people who don't know it well, e.g.:
- "Explain this whole repo line by line for a total beginner."
- "Write onboarding docs that walk through how a request flows through the code."
- "I'm new to this language — annotate the code and teach me the syntax as it appears."
- "Produce a learning series for
src/that a non-programmer could follow."
Not for: quick one-off "what does this function do" answers (just answer directly), or API reference generation (that's a different genre).
These are distilled from real tutorials that worked. Hold to all of them.
- Audience = beginner's beginner. Assume no prior syntax knowledge. Explain with plain language and analogies before jargon. Define every term the first time it appears.
- Syntax mini-lessons inline. The first time any language construct appears (a keyword, an operator, a pattern), stop and teach it in a short boxed aside (a「Syntax mini-lesson」/「语法小课堂」). Never assume the reader has seen it before.
- Dependency order, not filename order. Read and present files so that each doc only relies on concepts already taught. Foundations (types/contracts/config) first; the files that depend on them later.
- Cite real locations, verified. Every
file · function · linereference must be checked against the actual source before writing it. Wrong line numbers actively mislead a beginner. Re-read the file and confirm. - Code is the source of truth. When code contradicts comments/docs/README (e.g. a "stub" that is actually fully implemented), say so honestly and follow the code. Teaching readers to notice this is itself a skill.
- Deliver in batches, pause to digest. For a large repo, hand off a few docs at a time and let the reader catch up, rather than dumping everything at once.
- Cross-link relentlessly. Each doc points back to where a concept was first taught and forward to what's next. Maintain a running index so nothing is orphaned.
- Skim the repo: entry point, main modules, dependency direction.
- Pick the target language(s); note the build/run model.
- Decide the recommended reading order (dependency order). This becomes the Phase-2 sequence.
- Pick the one user action to trace in Phase 1 — the most representative end-to-end path (e.g. "user sends a command → effect happens"). It should touch the spine of the system.
Write a single "journey" document that follows your chosen action from the user all the way to the final effect, one hop at a time.
For each hop, give: the file, the function/method, the exact line range, a one-line plain-language description, and a link to the Phase-2 deep-dive for that file (the deep-dive may not exist yet — link to where it will be; that's fine).
Before writing each citation, open the source and verify file:function:line. This is non-negotiable — Principle 4.
Include:
- A "shape changes" table showing how the data is transformed at each layer (e.g. natural language → object → JSON → wire bytes → …). This is often the single most clarifying artifact.
- A return path if the action expects a response (how the answer comes back — callbacks, id-pairing, etc.).
- A station quick-reference table (every hop in one scannable table).
- A short "global lessons" section naming the cross-cutting patterns (layering, adapter, id-pairing, caching…) the reader will meet again.
Use references/flow-doc-template.md as the skeleton.
Now walk the files in dependency order. One doc per source file. Each doc follows the same fixed structure so the reader builds a rhythm:
- Locator block — link to the source file + one paragraph on what this file is and why it's read at this point in the order.
- Line-by-line breakdown — quote real code in small chunks; explain every line; insert a「Syntax mini-lesson」the first time each construct appears.
- Chapter recap — what this file does, in plain language.
- Syntax checklist — bullet list of the new/reinforced syntax points this doc covered (a reference the reader can scan later).
- Next link — point to the next doc in the order.
Maintain a series index (README) with: a progress table (which files are done), and a "syntax learning map" (each syntax point → the doc where it's first taught), so a reader who forgets something can jump back.
Use references/line-by-line-template.md as the per-doc skeleton.
Replace key ASCII diagrams with rendered visuals by invoking the relevant drawing skill:
- Directed flow / call chains (the Phase-1 main-line, a
switchdispatch, a data-flow) → invoke thegraphvizskill (```dotfenced blocks). - Layered/tiered architecture (a 3-tier system, a stack of layers) → invoke the
architectureskill (embedded HTML/CSS).
Pick by shape: arrows-and-nodes → graphviz; stacked colored tiers → architecture. Keep the explanatory prose; only the ASCII art becomes a rendered figure. A minimal dot flow chain:
digraph flow {
rankdir=LR;
node [shape=box, style="rounded,filled", fillcolor="#dbeafe"];
user [label="user input"];
handler [label="handler()\nfile.ts:42"];
out [label="effect"];
user -> handler -> out;
}See references/diagrams.md for when-to-use guidance and more DOT snippets (cluster grouping, switch dispatch).
- Line numbers: spot-check several
file:function:linecitations against the real source. - Links: every relative link to another doc/source resolves.
- Diagrams render: validate
dotblocks (dot -Tsvg) or preview; architecture HTML blocks have balanced tags and no blank lines inside the structure. - Order holds: no doc uses a concept not yet taught.
- Honesty: any code-vs-docs discrepancy is flagged, not papered over.
- references/flow-doc-template.md — Phase-1 "journey" doc skeleton (placeholders for hops, shape-change table, quick-ref).
- references/line-by-line-template.md — Phase-2 per-file deep-dive skeleton (locator, mini-lessons, recap, checklist).
- references/diagrams.md — when to use graphviz vs architecture, external-skill install link, DOT snippets.
- examples/rosclaw-excerpt.md — a real excerpt of finished output (flow main-line + a line-by-line slice).