from-code
Skill0 starsChanged 4 months agoMITView on GitHub
Generates a Mermaid diagram from code that is already in the repository, instead of from a description. Reads schema files into an ER diagram, Terraform/CloudFormation/CDK/Kubernetes into a cloud architecture diagram, Dockerfiles and compose files into a container topology, a call chain into an execution sequence diagram, or the module tree into a C4 or component diagram. Also regenerates an existing diagram that has drifted from the code it documents.
In this repository5 other files it gives its agents.
- dependency-mapSkill
- improveSkill
- mermaidSkill
- ownership-mapSkill
- repairSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 7 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 28
Read files directly only when the user names one or two specific files.
- Distinctive: line 34
If the first argument is a mode, use it.
- Distinctive: line 46
If several modes apply, say what each would show and let the user pick.
- Very specific: line 54
Never diagram vendored or generated code: node_modules/, vendor/, dist/, build/, .venv/, target/, __pycache__/, and anything matched by …
- Distinctive: line 75
When writing a diagram to a file, add a provenance comment as the first line after the type keyword:
- Distinctive: line 91
When the ask is "this diagram is out of date":
- Very specific: line 93
Read the existing diagram and its %% mermaid:sources: line.
- Distinctive: line 115
Mark inferred edges as inferred: If a service *probably* calls another because of a config key rather than a real call site, say so in the …
- Distinctive: line 117
Report what was skipped: If the scout hit a file it could not parse, or the scope was truncated, the user needs to know the diagram is …
- Very specific: line 119
A diagram of nothing is a valid result: If the detectors find no matching files, say so and offer /mermaid to draw from a description …
≈ “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.
Files
Diagram from existing code
Arguments: $ARGUMENTS
The diagram must describe what the code actually does, not what it ought to do. Every node and edge has to trace back to a file you read.
Hard rule: delegate the scan
Never read the repository tree from the main thread. Dispatch the mermaid-source-scout subagent
and work from the structured inventory it returns.
Why this is a rule and not a preference: scanning a repo for diagram material means opening many files
and keeping little of each. Doing that inline fills the context with source you will not use, and by
drafting time the details you needed have been squeezed out. The scout reads widely, returns a compact
inventory with file:line evidence, and its context is discarded.
Read files directly only when the user names one or two specific files.
Workflow
1. Resolve the mode
If the first argument is a mode, use it. Otherwise detect candidates and ask - upstream showed a quick-pick widget here; in a CLI you just ask, which is better because you can explain the trade-off.
| Mode | Produces | Triggered by these files |
er | erDiagram | schema.prisma, Drizzle schema, *.sql DDL/migrations, ActiveRecord models, SQLAlchemy models, JPA entities |
cloud | architecture-beta | *.tf/*.tfvars, CloudFormation/SAM templates, CDK stacks, Pulumi programs, k8s/*.yaml, Helm charts |
docker | architecture-beta or flowchart | Dockerfile*, docker-compose*.y*ml, compose*.y*ml, stack files |
sequence | sequenceDiagram | An entry point the user names (a route, handler, CLI command, job) |
c4 | C4Context / C4Container / C4Component | The module/package tree - whole-repo scope |
auto | whichever fits | Detect, then offer the two or three that make sense |
If several modes apply, say what each would show and let the user pick. Do not silently pick one.
2. Scope the files, and confirm before scanning
Confirm the file list before the scan when the scope is broad - a whole-repo c4 run on a large
monorepo is expensive, and the user may only care about one package. Skip the confirmation when the
scope is already obvious (they named the file, or there is exactly one docker-compose.yml).
Never diagram vendored or generated code: node_modules/, vendor/, dist/, build/, .venv/,
target/, __pycache__/, and anything matched by .gitignore.
3. Dispatch the scout
Give it the mode, the scoped paths, and the per-mode extraction checklist from the reference file.
Require: nodes with kind and label, edges with direction and label, groups, and file:line evidence
per claim. Require it to state what it could not find.
4. Draft, validate, render
Hand the inventory into the core /mermaid loop: fetch the syntax doc for the target type, draft,
validate_and_render_mermaid_diagram, then present source plus link. All the drafting guidance,
pitfalls and output format live there - this skill supplies the content, not a second renderer.
For cloud, call search_mermaid_icons for the specific services found. Do not guess icon IDs; a
wrong ID breaks the render or silently degrades to a placeholder. With no lookup available, use the
five built-ins (cloud, database, disk, internet, server) and say that you did.
5. Record what the diagram documents
When writing a diagram to a file, add a provenance comment as the first line after the type keyword:
%% mermaid:sources: infra/main.tf, infra/rds.tfThis convention is this plugin's own, not an upstream mechanism - /mermaid:dependency-map and
the diagram-drift-auditor subagent read it to tell whether a diagram has gone stale. A %% comment
is used rather than YAML frontmatter because an unknown frontmatter key risks the Mermaid parser, while
%% is safe by construction.
Upstream's equivalent is an id: frontmatter key plus its closed-source GitHub Sync App. That is a
different mechanism and this plugin does not implement it.
Regenerating a drifted diagram
When the ask is "this diagram is out of date":
- Read the existing diagram and its
%% mermaid:sources:line. Without one, infer the documented paths from node labels and say that you inferred them. - Dispatch
diagram-drift-auditor, or scan the named sources directly if there are only a few. - Redraw, preserving every node ID and label that is still accurate. A regenerated diagram whose IDs all changed produces an unreviewable diff even when the picture is identical.
- Show what changed: added, removed, renamed.
Upstream sends your source to a metered endpoint for this - a staged diff for modified files, full content for newly added ones. Here the source never leaves the machine and there are no credits to spend.
Per-mode references
- references/er-from-schema.md - entities, columns, cardinality
- references/cloud-from-iac.md - Terraform, CloudFormation, CDK, k8s
- references/docker-topology.md - services, networks, volumes, ports
- references/sequence-from-callchain.md - lifelines, ordering
- references/c4-levels.md - context / container / component
Honesty rules
- Never invent an edge to make a diagram look complete. A missing relationship is information.
- Mark inferred edges as inferred. If a service probably calls another because of a config key rather than a real call site, say so in the reply - not silently in a solid arrow.
- Report what was skipped. If the scout hit a file it could not parse, or the scope was truncated, the user needs to know the diagram is partial.
- A diagram of nothing is a valid result. If the detectors find no matching files, say so and
offer
/mermaidto draw from a description instead.
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
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.

