zoobzio January 15, 2026 3 mins Edit this page

Entity Relationship Diagrams (ERD)

What is erd?

erd generates Entity Relationship Diagrams from Go struct definitions.

Entity Relationship Diagrams visualize how domain types connect—which entities exist, what attributes they have, and how they relate to each other. They're useful for documentation, onboarding, and validating that your mental model matches the code.

erd outputs two formats:

  • Mermaid — embeds in Markdown, renders in GitHub, documentation sites
  • GraphViz DOT — print-quality diagrams, PDF export, detailed layouts

How It Works

erd can build diagrams manually via a builder API, but the real power comes from automatic extraction. Point it at your domain model and it generates the diagram.

Define types with optional erd tags for key constraints:

type User struct {
    ID      string   `erd:"pk"`
    Email   string   `erd:"uk"`
    Profile *Profile
    Orders  []Order
}

type Profile struct {
    ID  string `erd:"pk"`
    Bio *string
}

type Order struct {
    ID     string  `erd:"pk,note:Auto-generated"`
    UserID string  `erd:"fk"`
    Total  float64
}

Scan your domain and export the schema:

sentinel.Scan[User]()
schema := sentinel.Schema()

Convert to a diagram:

diagram := erd.FromSchema("Domain Model", schema)

// For markdown/web
fmt.Println(diagram.ToMermaid())

// For print/PDF
fmt.Println(diagram.ToDOT())
erDiagram
    User {
        string ID PK
        string Email UK
    }
    Profile {
        string ID PK
        string Bio "nullable"
    }
    Order {
        string ID PK "Auto-generated"
        string UserID FK
        float64 Total
    }
    User ||--|| Profile : Profile
    User ||--o{ Order : Orders

Relationships and cardinality are inferred automatically—no manual wiring.

What Sentinel Provides

erd needsSentinel provides
Entity namesMetadata.TypeName
AttributesFieldMetadata.Name, FieldMetadata.Type
NullabilityFieldMetadata.Kind — pointers are nullable
Key markersFieldMetadata.Tags["erd"]
RelationshipsTypeRelationship with From, To, Kind
CardinalityTypeRelationship.Kind maps to ERD notation

Tag Reference

TagPurposeExample
pkPrimary keyerd:"pk"
fkForeign keyerd:"fk"
ukUnique keyerd:"uk"
note:xAdd annotationerd:"note:Auto-generated UUID"

Tags can be combined: erd:"pk,note:Auto-generated"

Cardinality Mapping

Sentinel's relationship kinds map directly to ERD notation:

Relationship KindGo TypeDiagram Notation
reference*Profile`
collection[]Order`
embeddingBaseModel`
mapmap[string]Tag}o--o{ M:N

Learn More