npx skills add ...
npx skills add github/awesome-copilot --skill efcore-d2-db-diagram
npx skills add github/awesome-copilot --skill efcore-d2-db-diagram
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.
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:
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:
Use these cardinality labels:
1:11:NN:1N:NownedOwned types default to inline rendering.
Inline example:
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:
When the user asks to generate a diagram, provide:
.d2 source file content.Clients: {
shape: sql_table
Id: uuid {constraint: primary_key}
Address.Street: text
Address.ZipCode: text
Address.City: text
}.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