Patterns for entity relationship design and data modeling
View on GitHubplugins/aai-dev-database/skills/data-modeling/SKILL.md
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/the-answerai/alphaagent-team/blob/main/plugins/aai-dev-database/skills/data-modeling/SKILL.md -a claude-code --skill data-modelingInstallation paths:
.claude/skills/data-modeling/# Data Modeling Skill
Patterns for designing effective data models.
## Entity-Relationship Design
### Identifying Entities
```
Questions to ask:
1. What are the core "things" in the system?
2. What data needs to be persisted?
3. What has its own identity/lifecycle?
Examples:
- User (has identity, persisted)
- Order (has identity, persisted)
- Session token (temporary, maybe not entity)
```
### Defining Relationships
```prisma
// One-to-One: Each user has exactly one profile
model User {
profile Profile?
}
model Profile {
userId String @unique
user User @relation(fields: [userId], references: [id])
}
// One-to-Many: User has many posts
model User {
posts Post[]
}
model Post {
authorId String
author User @relation(fields: [authorId], references: [id])
}
// Many-to-Many: Posts have many tags, tags have many posts
model Post {
tags Tag[]
}
model Tag {
posts Post[]
}
```
### Cardinality Decisions
| Relationship | When to Use | Example |
|--------------|-------------|---------|
| 1:1 | Optional extension data | User -> Profile |
| 1:N | Parent owns children | Order -> OrderItems |
| M:N | Independent association | Post <-> Tag |
## Common Domain Models
### User/Auth Model
```prisma
model User {
id String @id @default(uuid())
email String @unique
passwordHash String
emailVerified Boolean @default(false)
// Profile data
name String?
avatarUrl String?
// Auth
sessions Session[]
apiKeys ApiKey[]
// Audit
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lastLoginAt DateTime?
}
model Session {
id String @id @default(uuid())
userId String
token String @unique
expiresAt DateTime
userAgent String?
ipAddress String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
@@index([token])
}
```
### E-Commerce Model
```prisma
model Product {
id Strin