efcore-d2-db-diagram
Has your agent generate D2 database diagrams from Entity Framework Core models. It's useful for visualizing table relationships and schemas.
What it does
This tool creates a visual diagram of your database from your project's code. It understands how you've defined your tables and the relationships between them using Entity Framework Core.
When to use it
- ✓When you want to see how your database tables connect.
- ✓To document the database structure of a C# project.
- ✓To understand complex relationships like many-to-many.
Example of what to ask your AI
“Generate a database diagram for my project using Entity Framework Core.”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
The tool analyzes your C# code that uses Entity Framework Core. It looks for table and column definitions and how they relate to draw the diagram.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add github/awesome-copilot --skill efcore-d2-db-diagramOr download just the file:
curl -L https://raw.githubusercontent.com/github/awesome-copilot/main/skills/efcore-d2-db-diagram/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
EF Core D2 Database Diagram Generator
When to Use
Use this skill when the user wants to generate a database / ERD diagram from an Entity Framework Core codebase.
Typical requests:
- Generate a D2 database diagram from EF Core entities.
- Visualize tables, columns, primary keys, foreign keys and relationships.
- Analyze
DbContext,DbSet<T>,IEntityTypeConfiguration<T>, Fluent API and migrations. - Produce a
.d2file renderable to SVG/PNG with thed2CLI. - Document the database model of an ASP.NET Core / .NET project.
Goal
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:
- Database tables and relationships.
- Primary keys, foreign keys, required/optional columns.
- Owned types and value objects.
- Many-to-many relationships and join tables.
- Indexes, unique constraints and table names.
- EF Core conventions only when explicit mapping is absent.
Output is .d2 source code. It can be rendered to SVG or PNG via the d2 CLI.
Tools
- d2 CLI: render
.d2files to SVG/PNG.d2 input.d2 output.svgd2 --layout=elk input.d2 output.svg
- d2 fmt: format D2 files.
d2 fmt input.d2
- No MCP server is required. The skill generates D2 source code as text.
Recommended Workflow
- Read the EF Core project structure.
- Locate all
DbContextclasses. - Locate all
DbSet<T>declarations. - Locate entity classes, owned types, enum types and value objects.
- Read
OnModelCreatingand allIEntityTypeConfiguration<T>classes. - Read migrations when available to confirm table names, join tables, indexes and delete behaviors.
- Build a normalized database model before writing D2.
- Ask the mandatory diagram questionnaire before generation.
- Generate the
.d2file using the database model, not raw class nesting. - Validate D2 syntax with
d2 fmtbefore delivery. - Render with
d2 --layout=elk schema.d2 schema.svgwhen possible. - If regenerating, re-read EF Core mappings and migrations first.
Mandatory Questions Before Diagram Generation
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:
- DbContext:
auto-detect - Columns:
key-only - Column types:
Yes - Nullable markers:
Yes - Indexes:
Yes - Enums:
No - Owned types:
inline - Join tables:
explicit - Audit/technical tables:
No - Migration-only tables:
Yes - Grouping:
bounded-context - Layout:
elk - Output:
d2
Reference Documents
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 |
EF Core Extraction Rules
Source Priority
Use this priority order when sources disagree:
- Latest applied migration / migration snapshot.
- Fluent API configuration in
OnModelCreatingorIEntityTypeConfiguration<T>. - Data annotations.
- EF Core conventions.
- Raw C# class shape.
Required EF Core Concepts to Detect
Detect and represent:
DbContextandDbSet<T>.- Entity class names and actual table names from
ToTable. - Schema names from
ToTable("Table", "schema"). - Primary keys from
HasKey,[Key], conventions and migrations.
…
FAQ
What is an ERD diagram?
ERD stands for Entity-Relationship Diagram. It's a drawing that shows database tables and how they link to each other.
What is Entity Framework Core?
It's a tool that helps developers work with databases in C# projects without having to write all the SQL code manually.
What is a .d2 file?
It's a text file that describes the diagram. It can be turned into images like SVG or PNG using another tool called the 'd2 CLI'.
Details
Original description by the author
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.
repo: github/awesome-copilot
Popularity
- GitHub stars
- 40k
- Ranking position
- #5130
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
acquire-codebase-knowledge
Helps your agent understand and document an existing code project. It's useful for onboarding new people or getting an overview of the architecture.
github/awesome-copilot
acreadiness-assess
Enables your agent to assess a project's readiness for AI and generate a report. It's useful for understanding how well a project is prepared to use AI tools.
github/awesome-copilot
acreadiness-generate-instructions
Helps your agent create instructions for AI tools based on an assessment. It's useful for improving how AI interacts with code and closing identified gaps.
github/awesome-copilot
acreadiness-policy
Enables your agent to help define or apply policies for AI project assessment. It's useful for standardizing how projects are evaluated and ensuring compliance.
github/awesome-copilot
Similar skills
benchmark-optimization-loop
Has your agent improve something's speed in a measured way. It tests multiple versions and chooses the fastest one that still works correctly.
affaan-m/ECC
change-impact
Helps your agent analyze the impact of code changes before making them. It compares the planned vs. actual results afterward, covering paths, data, tests, and documentation. Useful for risky or system-wide changes.
affaan-m/ECC
click-path-audit
Lets your agent trace all user buttons and interactions to find bugs. It finds issues where functions seem to work alone but fail together. Useful when bugs persist even after debugging.
affaan-m/ECC