Demonstration of database diagram generation from an Entity Framework Core model, using the GitHub Copilot skill efcore-d2-db-diagram.
- Project Overview
- Prerequisites
- Using the efcore-d2-db-diagram Skill
- Generated Diagram
- Bounded Contexts Description
- Regenerating the Diagram
- Installing the Skill on Another Project
This project contains an EF Core model representing a library management application (LibraryDbContext). It demonstrates how the efcore-d2-db-diagram skill can automatically analyse entities, Fluent API configurations and relationships to produce an ERD diagram in D2 format.
Project structure:
Library.Data/
├── LibraryDbContext.cs # Main DbContext
├── Domain/
│ ├── Administration/ # Staff, Role, AuditLog
│ ├── Catalogue/ # Book, Author, BookAuthor, Category, Copy
│ ├── Loans/ # Loan, Reservation, Fine
│ └── Members/ # Member, MemberType, Subscription
├── Configurations/ # IEntityTypeConfiguration<T> per entity
└── Enums/ # BookCondition, LoanStatus, ReservationStatus
| Tool | Purpose |
|---|---|
| .NET 8+ | Build the C# project |
| d2 CLI | Validate and render .d2 files |
| GitHub Copilot (agent mode) | Invoke the efcore-d2-db-diagram skill |
Install d2:
# macOS / Linux
curl -fsSL https://d2lang.com/install.sh | sh -s --
# Windows (winget)
winget install terrastruct.d2The skill is installed at .github/skills/efcore-d2-db-diagram/SKILL.md.
The skill follows this automated process:
- Read the project structure — detect the
DbContext,DbSet<T>declarations and entity folders. - Analyse entities — extract properties, primary keys, foreign keys and navigation properties.
- Read Fluent API configurations —
IEntityTypeConfiguration<T>for table names, constraints, indexes and delete behaviors. - Build the normalised database model — group by bounded context (Catalogue, Members, Loans, Administration).
- Generate the
.d2file — key-only columns, annotated relationships and per-context styles. - Validate syntax —
d2 fmt library-schema.d2. - Render SVG —
d2 --layout=elk library-schema.d2 library-schema.svg.
| Parameter | Value |
|---|---|
| DbContext | LibraryDbContext (auto-detected) |
| Columns displayed | Keys only (PK / FK) |
| Column types | Yes |
| Nullable markers | Yes |
| Indexes | Yes |
| Enum values | No |
| Owned types | Inline |
| Many-to-many join tables | Explicit |
| Technical/audit tables | Hidden (AuditLog) |
| Grouping | Bounded context |
| Layout | elk |
| Output format | .d2 + .svg |
In VS Code agent mode, simply ask:
"Generate the base diagram using the efcore-d2 skill"
Copilot automatically loads the skill, analyses the source code and produces the library-schema.d2 file.
Source file:
library-schema.d2
After modifying the EF Core model, regenerate the diagram in two steps:
# 1. Ask Copilot to regenerate (agent mode)
# "Regenerate the database diagram"
# 2. Validate and render manually
d2 fmt library-schema.d2
d2 --layout=elk library-schema.d2 library-schema.svgThe efcore-d2-db-diagram skill is self-contained and can be dropped into any repository. It works with GitHub Copilot (VS Code agent mode) and Claude (via the MCP filesystem or any agent that reads workspace files).
Copy the following folder structure into the root of your target repository:
.github/
└── skills/
└── efcore-d2-db-diagram/
├── SKILL.md # Main skill instructions
└── references/
├── d2-erd-style.md # D2 syntax and visual conventions
├── efcore-model-extraction.md # EF Core extraction rules
├── grouping-modes.md # Grouping strategies
├── quality-gate.md # Pre-delivery checklist
└── relationship-rules.md # Relationship inference rules
You can copy the files directly from this repository:
# From your target project root
mkdir -p .github/skills
cp -r /path/to/ef-d2-diagram-skill-demo/.github/skills/efcore-d2-db-diagram \
.github/skills/Or clone and copy on Windows:
Copy-Item -Recurse `
"C:\src\ef-d2-diagram-skill-demo\.github\skills\efcore-d2-db-diagram" `
".github\skills\"No configuration file is needed. GitHub Copilot agent mode automatically discovers skills placed under .github/skills/ when the skill's SKILL.md contains a valid frontmatter name field.
Requirements:
- VS Code with the GitHub Copilot and GitHub Copilot Chat extensions
- Agent mode enabled (
Chat: Agent Modein VS Code settings)
Invoke the skill:
Open the Copilot Chat panel, switch to agent mode and type:
"Generate the database diagram from my EF Core model"
Copilot detects the skill, reads your DbContext, entities and Fluent API configurations, then produces the .d2 file and optionally renders it to SVG.
Claude can use this skill when it has access to your repository files, either through the MCP filesystem server or by working directly in a VS Code workspace with the Copilot Chat extension configured to use Claude as the underlying model.
Option A — Claude via GitHub Copilot (model switch)
If your GitHub Copilot subscription supports Claude models, switch the model in the Copilot Chat panel and invoke the skill exactly the same way as with Copilot:
"Generate the database diagram using the efcore-d2 skill"
The skill file at .github/skills/efcore-d2-db-diagram/SKILL.md is automatically picked up regardless of the underlying model.
Option B — Claude with MCP filesystem
If you are using Claude Desktop or Claude API with the MCP filesystem server, configure it to expose your project root, then instruct Claude to read the skill:
// claude_desktop_config.json (MCP server configuration)
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/your/project"
]
}
}
}Then prompt Claude:
"Read the skill at
.github/skills/efcore-d2-db-diagram/SKILL.mdand follow its instructions to generate a D2 database diagram from the EF Core model in this project."
| File | Purpose |
|---|---|
SKILL.md |
Entry point — workflow, default parameters, mandatory questions, quality gate |
references/efcore-model-extraction.md |
Rules for reading DbContext, DbSet, Fluent API and migrations |
references/d2-erd-style.md |
D2 syntax and visual conventions for ERD diagrams |
references/relationship-rules.md |
How to infer 1:1, 1:N, N:N and owned relationships |
references/grouping-modes.md |
Bounded-context, schema, namespace and flat grouping rules |
references/quality-gate.md |
Final checklist before delivering the generated diagram |