Efcore-D2-Db-Diagram
Efcore-D2-Db-Diagram是一款code方向的AI技能,核心价值是Generate D2 database diagrams from Entity Framework Core models,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。
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 visu
mkdir -p ./skills/efcore-d2-db-diagram && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/efcore-d2-db-diagram/SKILL.md -o ./skills/efcore-d2-db-diagram/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
# 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 `.d2` file renderable to SVG/PNG with the `d2` CLI.
- 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:
1. Database tables and relationships.
2. Primary keys, foreign keys, required/optional columns.
3. Owned types and value objects.
4. Many-to-many relationships and join tables.
5. Indexes, unique constraints and table names.
6. 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 `.d2` files to SVG/PNG.
- `d2 input.d2 output.svg`
- `d2 --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
1. Read the EF Core project structure.
2. Locate all `DbContext` classes.
3. Locate all `DbSet<T>` declarations.
4. Locate entity classes, owned types, enum types and value objects.
5. Read `OnModelCreating` and all `IEntityTypeConfiguration<T>` classes.
6. Read migrations when available to confirm table names, join tables, indexes and delete behaviors.
7. Build a normalized database model before writing D2.
8. Ask the mandatory diagram questionnaire before generation.
9. Generate the `.d2` file using the database model, not raw class nesting.
10. Validate D2 syntax with `d2 fmt` before delivery.
11. Render with `d2 --layout=elk schema.d2 schema.svg` when possible.
12. 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.
1. `Which DbContext should be diagrammed? (auto-detect/all/specific name)`
2. `Display columns? (all/key-only/none)`
3. `Display column types? (Yes/No)`
4. `Display nullable/required markers? (Yes/No)`
5. `Display indexes and unique constraints? (Yes/No)`
6. `Display enum values? (Yes/No)`
7. `Display owned types? (inline/separate/hide)`
8. `Display many-to-many join tables? (explicit/compact/hide)`
9. `Display audit/technical tables? (Yes/No)`
10. `Display migration-only tables not present as entities? (Yes/No)`
11. `Which grouping mode? (bounded-context/schema/namespace/flat)`
12. `Which layout engine? (elk/dagre/tala)`
13. `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 ord
🎯 Best For
- Developers scaffolding new projects
- Prototype builders
- Claude users
- GitHub Copilot users
- Software engineers
💡 Use Cases
- Bootstrapping React components
- Creating API route handlers
- Code quality improvement
- Best practice enforcement
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply Efcore-D2-Db-Diagram to Your Work
Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.
- 4
Review and Refine
Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.
❓ Frequently Asked Questions
Can I customize the generated output?
Yes — modify the skill's prompt instructions to match your project conventions and coding style.
Is Efcore-D2-Db-Diagram compatible with Cursor and VS Code?
Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.
Do I need specific dependencies for Efcore-D2-Db-Diagram?
Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.
How do I install Efcore-D2-Db-Diagram?
Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/efcore-d2-db-diagram/SKILL.md, ready to use.
Can I customize this skill for my team?
Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.
⚠️ Common Mistakes to Avoid
Using generated code without understanding
Understand what generated code does before shipping it to production.
Skipping validation
Always test AI-generated code changes, even for simple refactors.
Missing dependency updates
Check if the skill requires updated dependencies or new packages.