agentleFS
lifebugzlifebugz/cc-mermaid/skills/from-code/SKILL.md

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.

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
  1. Distinctive:

    Read files directly only when the user names one or two specific files.

    line 28
  2. Distinctive:

    If the first argument is a mode, use it.

    line 34
  3. Distinctive:

    If several modes apply, say what each would show and let the user pick.

    line 46
  4. Very specific:

    Never diagram vendored or generated code: node_modules/, vendor/, dist/, build/, .venv/, target/, __pycache__/, and anything matched by …

    line 54
  5. Distinctive:

    When writing a diagram to a file, add a provenance comment as the first line after the type keyword:

    line 75
  6. Distinctive:

    When the ask is "this diagram is out of date":

    line 91
  7. Very specific:

    Read the existing diagram and its %% mermaid:sources: line.

    line 93
  8. Distinctive:

    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 …

    line 115
  9. Distinctive:

    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 …

    line 117
  10. Very specific:

    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 …

    line 119

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.

ModeProducesTriggered by these files
ererDiagramschema.prisma, Drizzle schema, *.sql DDL/migrations, ActiveRecord models, SQLAlchemy models, JPA entities
cloudarchitecture-beta*.tf/*.tfvars, CloudFormation/SAM templates, CDK stacks, Pulumi programs, k8s/*.yaml, Helm charts
dockerarchitecture-beta or flowchartDockerfile*, docker-compose*.y*ml, compose*.y*ml, stack files
sequencesequenceDiagramAn entry point the user names (a route, handler, CLI command, job)
c4C4Context / C4Container / C4ComponentThe module/package tree - whole-repo scope
autowhichever fitsDetect, 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.tf

This 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":

  1. Read the existing diagram and its %% mermaid:sources: line. Without one, infer the documented paths from node labels and say that you inferred them.
  2. Dispatch diagram-drift-auditor, or scan the named sources directly if there are only a few.
  3. 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.
  4. 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 /mermaid to draw from a description instead.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.