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 dat
- 0
- Installs
- —
- Rating
- —
- Success rate
- 6
- Files scanned
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 98eca691d84654e7… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
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. - Composite keys.
- Foreign keys from
HasForeignKey, navigation properties and migration operations. - Delete behavior when explicit:
Cascade,Restrict,NoAction,SetNull,ClientSetNull. - Required/optional relationship markers.
- Owned types from
OwnsOne,OwnsManyand[Owned]. - Many-to-many relationships from
UsingEntityand implicit EF Core join tables. - Indexes from
HasIndex,IsUniqueand migrations. - Alternate keys from
HasAlternateKey. - Shadow properties configured in Fluent API.
- Value conversions when they affect persisted type or readability.
- Enum properties.
- Ignored properties and ignored entities.
Diagram Rendering Rules
Tables
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.
Relationships
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:Nowned
Owned Types
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.
Many-to-Many
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.
Technical Tables
Hide technical tables by default unless requested.
Examples:
__EFMigrationsHistory- Hangfire tables
- ASP.NET Identity tables
- Audit logs
- Outbox tables
If technical tables are hidden, mention them in the summary after the diagram.
Grouping Modes
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.
Style Rules
Use consistent styles:
- Primary entity tables: solid border.
- Join tables: dashed border.
- Owned types: lighter stroke or nested inline fields.
- Technical tables: muted style.
- External tables or migration-only tables: dotted border.
- Required relationships: solid line.
- Optional relationships: dashed line.
- Cascade delete: label suffix
cascade.
Quality Gate Before Delivery
Before delivering the diagram, verify:
- The selected DbContext is clear.
- All
DbSet<T>entities are considered. - Fluent API configurations are read.
- Migrations are checked when present.
- Table names and schema names match EF Core mapping.
- Primary keys are present.
- Foreign keys and cardinalities are represented.
- Owned types are handled according to user choice.
- Many-to-many join tables are explicit unless the user asked otherwise.
- Hidden technical tables are listed in the final summary.
- D2 syntax is valid with
d2 fmt. - Edge endpoints use full dot-notation when inside containers.
- The diagram remains readable and avoids crossing-heavy layouts.
Output Format
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:
- The
.d2source file content. - The render command using the selected layout engine.
- A concise summary of assumptions and hidden tables.
Files
6- SKILL.md
e0689c25df8.9 KB - references/d2-erd-style.md
bbd4dd3c54490 B - references/efcore-model-extraction.md
68605a8487927 B - references/grouping-modes.md
b9085e7914401 B - references/quality-gate.md
6827076597516 B - references/relationship-rules.md
9a3105d65b1010 B
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from github/awesome-copilot8
Use this skill when the user explicitly asks to map, document, or onboard into an existing codebase. Trigger for prompts like "map this codebase", "document this architecture", "onboard me to this repo", or "create codebase docs". Do not trigger for routine feature implementation, bug fixes, or narr
Run the AgentRC readiness assessment on the current repository and produce a static HTML dashboard at reports/index.html. Wraps `npx github:microsoft/agentrc readiness` and hands off rendering to the @ai-readiness-reporter custom agent. Supports policies (--policy) for org-specific scoring. Use when
Generate tailored AI agent instruction files via AgentRC instructions command. Produces .github/copilot-instructions.md (default, recommended for Copilot in VS Code) plus optional per-area .instructions.md files with applyTo globs for monorepos. Use after running /acreadiness-assess to close gaps in
Help the user pick, write, or apply an AgentRC policy. Policies customise readiness scoring by disabling irrelevant checks, overriding impact/level, setting pass-rate thresholds, or chaining org baselines with team overrides. Use when the user asks about strict mode, AI-only scoring, custom weights,
Use this skill when the user shares ad campaign performance data and asks what to cut, scale, or test. Trigger for prompts like "analyze my ad campaigns", "where am I wasting ad spend", "reallocate my ad budget", "which ads are actually working", or "ROAS analysis". Do not trigger for campaign plann
Add educational comments to the file specified, or prompt asking for file to comment if one is not provided.
Write, debug, and optimize Adobe Illustrator automation scripts using ExtendScript (JavaScript/JSX). Use when creating or modifying scripts that manipulate documents, layers, paths, text frames, colors, symbols, artboards, or any Illustrator DOM objects. Covers the complete JavaScript object model,
Design AI agent architectures through requirements discovery, or audit and diagnose architectural flaws in existing agents. Architecture only; excludes implementation and general code review.
Related database skillsscan passed
ClickHouse database patterns, query optimization, analytics, and data engineering best practices for high-performance analytical workloads. Use when writing ClickHouse schemas or queries, or when an analytical query is too slow.
Use when the user wants to provision infrastructure or third-party services using Stripe Projects. Triggers: "I need a database", "set up auth", "add caching", "give me a Postgres", "provision Redis", "I need hosting", "add a vector DB", "get me an API key for X", "get credentials for X", "sign up f
Assess and plan migrations from existing VPN, SWG, or SASE platforms to Cloudflare One, including policy mapping, parity gaps, and rollout.
Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to
Sets up, manages, queries, and configures Cloud Firestore databases (Standard/Enterprise edition), including data modeling, security rules, indexes, and SDK integrations (Web, Python, iOS, Android, Flutter). Use when creating/listing Firestore databases, defining data models/indexes, writing SDK que
Creates a complete Amazon Aurora database cluster with instances, handling cluster creation, instance provisioning, and Secrets Manager password management in the proper sequence. Use when setting up new Aurora MySQL or PostgreSQL clusters with production-ready configuration.