feat: add efcore-d2-db-diagram skill and related documentation (#1821)

This commit is contained in:
Mikael
2026-05-25 03:34:34 +02:00
committed by GitHub
parent 59fdc7867a
commit c9dace874d
7 changed files with 482 additions and 0 deletions
@@ -0,0 +1,45 @@
# D2 ERD Style
## Recommended header
```d2
vars: {
d2-config: {
layout-engine: elk
theme-id: 300
}
}
```
## Table node
```d2
Clients: {
shape: sql_table
Id: uuid {constraint: primary_key}
Name: varchar(200)
Status: enum
}
```
## Relationship
```d2
Offers.ClientId -> Clients.Id: "N:1"
```
## Styles
```d2
classes: {
join_table: {
style.stroke-dash: 4
}
technical: {
style.opacity: 0.55
}
optional_relation: {
style.stroke-dash: 3
}
}
```
@@ -0,0 +1,60 @@
# EF Core Model Extraction
## Files to inspect
Inspect, in this order:
1. `DbContext` classes.
2. `DbSet<T>` declarations.
3. `OnModelCreating`.
4. `IEntityTypeConfiguration<T>` classes.
5. Entity classes.
6. Migrations and model snapshot.
7. Data annotations.
## Mapping priority
When sources conflict, use:
1. Latest migration / model snapshot.
2. Fluent API.
3. Data annotations.
4. EF Core conventions.
5. C# shape.
## Important EF Core APIs
Look for:
- `ToTable`
- `HasKey`
- `HasAlternateKey`
- `HasIndex`
- `IsUnique`
- `Property`
- `HasColumnName`
- `HasColumnType`
- `IsRequired`
- `HasMaxLength`
- `HasConversion`
- `HasOne`
- `WithMany`
- `WithOne`
- `HasForeignKey`
- `OnDelete`
- `OwnsOne`
- `OwnsMany`
- `UsingEntity`
- `Ignore`
## Migrations
Use migrations to detect:
- Actual table names.
- Join tables.
- Shadow FK columns.
- Indexes.
- Composite keys.
- Delete behaviors.
- Migration-only tables.
@@ -0,0 +1,28 @@
# Grouping Modes
## bounded-context
Group tables by domain area using folder, namespace and naming clues.
Examples:
- Clients
- Offers
- Freelances
- Billing
- Audit
- Identity
## schema
Group by database schema from `ToTable` or migrations.
## namespace
Group by C# namespace.
## flat
Do not create containers.
Use flat mode for small schemas or when the user wants maximum compatibility.
@@ -0,0 +1,16 @@
# Quality Gate
Before delivery:
- Confirm the selected DbContext.
- Confirm source files inspected.
- Validate table names against Fluent API and migrations.
- Include primary keys.
- Include foreign keys.
- Include cardinalities.
- Include join tables unless hidden by user choice.
- Include owned types according to user choice.
- Hide technical tables only if configured and list them in the summary.
- Run `d2 fmt` when available.
- Use full dot-notation for edges inside containers.
- Provide render command.
@@ -0,0 +1,59 @@
# Relationship Rules
## One-to-many
Detected from:
- `HasOne(...).WithMany(...)`
- FK property on dependent entity.
- Collection navigation on principal entity.
Render dependent to principal:
```d2
Orders.ClientId -> Clients.Id: "N:1"
```
## One-to-one
Detected from:
- `HasOne(...).WithOne(...)`
- Unique FK index.
- Shared primary key relationship.
Render dependent to principal:
```d2
ClientProfiles.ClientId -> Clients.Id: "1:1"
```
## Many-to-many
Detected from:
- `UsingEntity`
- Two collection navigations without explicit join entity.
- Migration-created join table with two FKs and composite key.
Render the join table explicitly by default.
## Owned types
Detected from:
- `OwnsOne`
- `OwnsMany`
- `[Owned]`
Inline by default unless table splitting or separate table mapping is detected.
## Optional relationships
A relationship is optional when:
- FK is nullable.
- `IsRequired(false)` is configured.
- Migration column is nullable.
Use dashed line for optional relationships.