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.svg
d2 --layout=elk input.d2 output.svg
d2 fmt input.d2
DbContext 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-detect
key-only
Yes
Yes
Yes
No
inline
explicit
No
Yes
bounded-context
elk
d2
Load 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:1
1:N
N:1
N:N
owned
Owned 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:
__EFMigrationsHistory
If 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.