Data Modeling Expert
The Data Modeling Expert agent specializes in database design, entity relationship modeling, schema design, and data architecture for applications.
Expertise Areas#
- Entity Relationship Design - ERD planning and optimization
- Prisma Schema Patterns - ORM schema best practices
- SaaS Data Models - Multi-tenant architectures
- Soft Delete Pattern - Non-destructive deletion
- Audit Logging - Change tracking systems
- Indexing Strategy - Performance optimization
- Data Migration - Schema evolution patterns
Usage Examples#
Schema Design#
Use the data-modeling-expert agent to design a database schema for a multi-tenant SaaS application.
Response includes:
- Entity definitions
- Relationship mapping
- Tenant isolation strategy
- Index recommendations
Prisma Schema#
Use the data-modeling-expert agent to create a Prisma schema for a project management application.
Response includes:
- Model definitions
- Relations setup
- Enum types
- Index decorators
Migration Strategy#
Use the data-modeling-expert agent to plan a data migration for adding user roles to an existing system.
Response includes:
- Migration script
- Backfill logic
- Rollback plan
- Testing approach
Best Practices Applied#
1. Schema Design#
- Proper normalization
- Clear relationships
- Consistent naming
- Appropriate constraints
2. Performance#
- Strategic indexing
- Query optimization
- Covering indexes
- Partial indexes
3. Data Integrity#
- Foreign key constraints
- Check constraints
- Unique constraints
- Default values
4. Operations#
- Soft delete patterns
- Audit logging
- Migration strategies
- Backup considerations
Common Patterns#
User with Relations#
1model User {
2 id String @id @default(cuid())
3 email String @unique
4 name String?
5 role Role @default(USER)
6 createdAt DateTime @default(now())
7 updatedAt DateTime @updatedAt
8
9 profile Profile?
10 posts Post[]
11 teams TeamMember[]
12
13 @@index([email])
14}
15
16model Profile {
17 id String @id @default(cuid())
18 bio String?
19 avatar String?
20 userId String @unique
21 user User @relation(fields: [userId], references: [id], onDelete: Cascade)
22}Multi-Tenant SaaS Schema#
1model Organization {
2 id String @id @default(cuid())
3 name String
4 slug String @unique
5 plan Plan @default(FREE)
6 stripeId String? @unique
7 members OrganizationMember[]
8 projects Project[]
9 subscription Subscription?
10 createdAt DateTime @default(now())
11 updatedAt DateTime @updatedAt
12
13 @@index([slug])
14}
15
16model OrganizationMember {
17 id String @id @default(cuid())
18 organizationId String
19 userId String
20 role OrgRole @default(MEMBER)
21 organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
22 user User @relation(fields: [userId], references: [id], onDelete: Cascade)
23
24 @@unique([organizationId, userId])
25}
26
27enum Plan {
28 FREE
29 PRO
30 TEAM
31 ENTERPRISE
32}
33
34enum OrgRole {
35 OWNER
36 ADMIN
37 MEMBER
38}Soft Delete Pattern#
1model Document {
2 id String @id @default(cuid())
3 title String
4 content String?
5 deletedAt DateTime?
6 createdAt DateTime @default(now())
7 updatedAt DateTime @updatedAt
8
9 @@index([deletedAt])
10}1// Prisma middleware for soft delete
2prisma.$use(async (params, next) => {
3 if (params.model === 'Document') {
4 if (params.action === 'findMany' || params.action === 'findFirst') {
5 params.args.where = {
6 ...params.args.where,
7 deletedAt: null,
8 };
9 }
10
11 if (params.action === 'delete') {
12 params.action = 'update';
13 params.args.data = { deletedAt: new Date() };
14 }
15 }
16 return next(params);
17});Audit Log Pattern#
1model AuditLog {
2 id String @id @default(cuid())
3 entityType String
4 entityId String
5 action String
6 changes Json?
7 userId String?
8 user User? @relation(fields: [userId], references: [id])
9 ipAddress String?
10 createdAt DateTime @default(now())
11
12 @@index([entityType, entityId])
13 @@index([userId])
14 @@index([createdAt])
15}Sample Prompts#
| Task | Prompt |
|---|---|
| Schema design | "Design a schema for an e-commerce platform" |
| Multi-tenant | "Create a multi-tenant data model with organization isolation" |
| Relationships | "Model a many-to-many relationship with metadata" |
| Audit log | "Add audit logging for all user actions" |
| Migration | "Plan migration for adding user preferences" |
Configuration#
1// bootspring.config.js
2module.exports = {
3 agents: {
4 customInstructions: {
5 'data-modeling-expert': `
6 - Use Prisma for schema definition
7 - Implement soft delete for important entities
8 - Add audit logging for sensitive operations
9 - Design for multi-tenancy from the start
10 - Include proper indexing strategy
11 `,
12 },
13 },
14 database: {
15 provider: 'postgresql',
16 orm: 'prisma',
17 },
18};Related Agents#
- Database Expert - Query optimization
- Backend Expert - API integration
- Architecture Expert - System design