skills/efcore-d2-db-diagram/SKILL.md
Generate D2 database diagrams from Entity Framework Core models. USE FOR: EF Core database diagram, Entity Framework Core ERD, DbContext diagram, C# entity relationship diagram, PostgreSQL schema visualization, generate .d2 file from EF Core entities, Fluent API mapping diagram, migrations-based database diagram, table relationships, owned types, many-to-many join tables, indexes and constraints. DO NOT USE FOR: runtime debugging, database migration execution, schema deployment, SQL performance tuning, or draw.io diagrams.
npx skillsauth add williamlimasilva/.copilot efcore-d2-db-diagramInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when the user wants to generate a database / ERD diagram from an Entity Framework Core codebase.
Typical requests:
DbContext, DbSet<T>, IEntityTypeConfiguration<T>, Fluent API and migrations..d2 file renderable to SVG/PNG with the d2 CLI.Create a readable D2 entity-relationship diagram that reflects the actual EF Core persistence model, not only the raw C# class shape.
The diagram must prioritize:
Output is .d2 source code. It can be rendered to SVG or PNG via the d2 CLI.
.d2 files to SVG/PNG.
d2 input.d2 output.svgd2 --layout=elk input.d2 output.svgd2 fmt input.d2DbContext classes.DbSet<T> declarations.OnModelCreating and all IEntityTypeConfiguration<T> classes..d2 file using the database model, not raw class nesting.d2 fmt before delivery.d2 --layout=elk schema.d2 schema.svg when possible.Ask these questions for every new diagram and every regeneration unless the user already answered them in the same request.
Which DbContext should be diagrammed? (auto-detect/all/specific name)Display columns? (all/key-only/none)Display column types? (Yes/No)Display nullable/required markers? (Yes/No)Display indexes and unique constraints? (Yes/No)Display enum values? (Yes/No)Display owned types? (inline/separate/hide)Display many-to-many join tables? (explicit/compact/hide)Display audit/technical tables? (Yes/No)Display migration-only tables not present as entities? (Yes/No)Which grouping mode? (bounded-context/schema/namespace/flat)Which layout engine? (elk/dagre/tala)Which output format? (d2/svg/png)Default values, when the user asks for a quick generation:
auto-detectkey-onlyYesYesYesNoinlineexplicitNoYesbounded-contextelkd2Load these on demand when needed:
| Reference | When to load |
|---|---|
| references/efcore-model-extraction.md | Rules for reading DbContext, DbSet, Fluent API, configurations and migrations |
| references/d2-erd-style.md | D2 syntax and visual conventions for ERD diagrams |
| references/relationship-rules.md | How to infer one-to-one, one-to-many, many-to-many and owned relationships |
| references/grouping-modes.md | Rules for bounded-context, schema, namespace and flat grouping |
| references/quality-gate.md | Final checklist before delivering the generated diagram |
Use this priority order when sources disagree:
OnModelCreating or IEntityTypeConfiguration<T>.Detect and represent:
DbContext and DbSet<T>.ToTable.ToTable("Table", "schema").HasKey, [Key], conventions and migrations.HasForeignKey, navigation properties and migration operations.Cascade, Restrict, NoAction, SetNull, ClientSetNull.OwnsOne, OwnsMany and [Owned].UsingEntity and implicit EF Core join tables.HasIndex, IsUnique and migrations.HasAlternateKey.Represent each persisted table as a D2 node with shape: sql_table when possible.
Use this content convention:
Clients: {
shape: sql_table
constraint: primary_key
Id: uuid {constraint: primary_key}
Name: text
Status: enum
}
If sql_table is unavailable or causes validation issues, fallback to a rectangle with structured text.
Use directional edges from dependent table to principal table.
Labels must include relationship cardinality and FK name when known:
Offers.ClientId -> Clients.Id: "N:1 FK_Offers_Clients_ClientId"
Use these cardinality labels:
1:11:NN:1N:NownedOwned types default to inline rendering.
Inline example:
Clients: {
shape: sql_table
Id: uuid {constraint: primary_key}
Address.Street: text
Address.ZipCode: text
Address.City: text
}
If the user chooses separate, represent owned types as visually subordinate tables and use an owned relationship.
Default to explicit join tables because EF Core creates real tables.
For implicit many-to-many relationships, create a generated join table node and mark it as implicit join.
Hide technical tables by default unless requested.
Examples:
__EFMigrationsHistoryIf technical tables are hidden, mention them in the summary after the diagram.
bounded-context: group by detected domain area or folder/module.schema: group by database schema, e.g. public, auth, billing.namespace: group by C# namespace.flat: no containers, all tables at the same level.Use consistent styles:
cascade.Before delivering the diagram, verify:
DbSet<T> entities are considered.d2 fmt.When the user asks for a skill installation, provide this folder structure:
.github/
skills/
efcore-d2-db-diagram/
SKILL.md
references/
efcore-model-extraction.md
d2-erd-style.md
relationship-rules.md
grouping-modes.md
quality-gate.md
When the user asks to generate a diagram, provide:
.d2 source file content.tools
Create a new workshop or use an existing directory as one. Handles two paths: (A) use an existing local directory the operator points at, or (B) create a new private GitHub repo in the signed-in account. Never creates a repo inside another repo.
development
Guide for setting up vcpkg in C++ projects, managing dependency versions, and cross-compiling. Covers manifest initialization, CMake and Visual Studio integration, classic-to-manifest migration, version pinning, baselines, overrides, triplets, and cross-compilation. Use when a user is working with vcpkg project setup, installation, version management, or cross-platform builds. For specialized tasks, additional references cover custom registries and overlay ports (references/registries.md), CI/CD and binary caching (references/ci.md), and troubleshooting and dependency lifecycle (references/troubleshooting.md).
testing
Emit structured agent signals — hands-up, blocked, done, checkpoint, partnership. Signals are written as JSON to .signals/ for dashboard consumption and noted in the journal for persistence.
development
Install and configure Markstream streaming Markdown renderers for Vue, React, Svelte, Angular, Nuxt, and Vue 2 applications. Use for package selection, minimal peer dependencies, CSS order, SSR boundaries, streaming mode, and renderer setup.