When to use this skill
This is an OPTIONAL advanced modeling tool for complex database design. Most simple table creation should use relational-database-tool directly with SQL statements.
ONLY use this skill when you specifically need:
- Complex multi-table relationships with automatic foreign key management
- Visual ER diagram generation for documentation
- Automated field type mapping and constraint generation
- Enterprise-level data model documentation
For most cases, use rules/relational-database-tool/rule.md instead:
- Simple table creation with CREATE TABLE statements
- Basic CRUD operations
- Schema modifications with ALTER TABLE
- Direct SQL execution without Mermaid modeling
Do NOT use for:
- Querying or manipulating existing data (use database skills)
- NoSQL database design (use NoSQL skills)
- Frontend data structures (use appropriate frontend skills)
How to use this skill (for a coding agent)
⚠️ NOTE: This is OPTIONAL. For simple tasks, skip this and use relational-database-tool directly.
When you do use this advanced modeling approach:
Optional modeling workflow (only when complexity justifies it)
- Business analysis phase: Analyze user requirements, identify core entities and relationships
- Mermaid modeling phase: Create mermaid classDiagram following generation rules
- Model validation phase: Check completeness, consistency, and correctness
Apply generation rules strictly (when using this tool)
- Use correct type mappings (string, number, boolean, x-enum, etc.)
- Convert Chinese to English naming (PascalCase for classes, camelCase for fields)
- Define required(), unique(), display_field() functions when needed
- Use proper relationship notation with field names
Use tools correctly (only when you choose this approach)
- Call data model creation tools only for complex multi-entity business requirements
- Use
mermaidDiagram parameter with complete mermaid classDiagram code
- Set
publish to false initially, create then publish separately
- Choose appropriate
updateMode for new or existing models
Quick Decision Guide
Most Database Tasks → rules/relational-database-tool/rule.md
- ✅ Simple table creation
- ✅ Data queries and modifications
- ✅ Schema changes
- ✅ Direct SQL execution
Complex Modeling Only → This rule (rules/data-model-creation/rule.md)
- 🎯 Multi-entity relationship modeling
- 🎯 Automated foreign key management
- 🎯 Visual ER diagram generation
- 🎯 Enterprise documentation
Data Model AI Modeling Professional Rules
⚠️ IMPORTANT: Simplified Workflow Recommendation
For most database table creation tasks, use rules/relational-database-tool/rule.md directly:
- Simple table creation:
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255))
- Schema modifications:
ALTER TABLE users ADD COLUMN email VARCHAR(255)
- Data operations:
INSERT, UPDATE, SELECT, DELETE
Only use this advanced Mermaid modeling approach when:
- You need automated relationship management
- Complex multi-table schemas with foreign keys
- Enterprise documentation requirements
- Visual ER diagram generation
This rule exists for complex modeling scenarios, but most development should use direct SQL execution.
AI Modeling Expert Prompt
As an expert in data modeling and a senior architect in software development, you are proficient in Mermaid. Your main task is to provide model structures in mermaid classDiagram format based on user descriptions, following the detailed rules below:
Generation Rules
Type Mapping Priority: When user-described fields match the mapping relationship, prioritize using type as the field type. Mapping relationships are as follows:
| Business Field |
type |
| Text |
string |
| Number |
number |
| Boolean |
boolean |
| Enum |
x-enum |
| Email |
email |
| Phone |
phone |
| URL |
url |
| File |
x-file |
| Image |
x-image |
| Rich Text |
x-rtf |
| Region |
x-area-code |
| Time |
time |
| Date |
date |
| DateTime |
datetime |
| Object |
object |
| Array |
string[] |
| Location |
x-location |
Naming Convention: Convert Chinese descriptions to English naming (except enum values). Use PascalCase for class names, camelCase for field names.
Field Visibility: Use default visibility for fields, do not add "+" or "-".
Array Types: When descriptions include array types, use specific array formats such as string[], number[], x-rtf[], etc.
Chinese Administrative Regions: When involving Chinese administrative regions like "province/city/district", use x-area-code field type.
Required Fields: When descriptions explicitly mention required fields, define a required() parameterless function, return value as string array of required field names, e.g., required() ["name", "age"]. By default, fields are not required.
Unique Fields: When descriptions explicitly mention unique fields, define a unique() parameterless function, return value as string array of unique field names, e.g., unique() ["name", "age"]. By default, fields are not unique.
Default Values: When descriptions explicitly require field default values, use "= default value" format after field definition, e.g., age: number = 0. By default, fields have no default values.
Field Descriptions: For each field definition in user descriptions, use <<description>> format at the end of the definition line, e.g., name: string <<Name>>.
Display Field: Each entity class should have a field for display when being referenced. Usually a human-readable name or unique identifier. Define display_field() parameterless function, return value is a field name representing the main display field, e.g., display_field() "name" means the main display field is name. Otherwise, default to the implicit _id of the data model.
Class Notes: After all class definitions are complete, use note to describe class names. First use "%% Class naming" to anchor the area, then provide Chinese table names for each class.
Relationships: When descriptions contain relationships, relationship label LabelText should not use original semantics, but use relationship field names. For example, A "n" <-- "1" B: field1 means A has many-to-one relationship with B, data exists in A's field1 field. Refer to examples for specifics.
Naming: Field names and descriptions in Mermaid should be concise and accurately expressed.
Complexity Control: Unless user requires, control complexity, e.g., number of classes should not exceed 5, control field complexity.
Standard Example
classDiagram
class Student {
name: string <<Name>>
age: number = 18 <<Age>>
gender: x-enum = "Male" <<Gender>>
classId: string <<Class ID>>
identityId: string <<Identity ID>>
course: Course[] <<Courses>>
required() ["name"]
unique() ["name"]
enum_gender() ["Male", "Female"]
display_field() "name"
}
class Class {
className: string <<Class Name>>
display_field() "className"
}
class Course {
name: string <<Course Name>>
students: Student[] <<Students>>
display_field() "name"
}
class Identity {
number: string <<ID Number>>
display_field() "number"
}
%% Relationships
Student "1" --> "1" Identity : studentId
Student "n" --> "1" Class : student2class
Student "n" --> "m" Course : course
Student "n" <-- "m" Course : students
%% Class naming
note for Student "Student Model"
note for Class "Class Model"
note for Course "Course Model"
note for Identity "Identity Model"
Data Model Creation Workflow
1. Business Analysis Phase
- Carefully analyze user's business requirement descriptions
- Identify core entities and business objects
- Determine relationships between entities
- Clarify required fields, unique constraints, and default values
2. Mermaid Modeling Phase
- Strictly follow the above generation rules to create mermaid classDiagram
- Ensure field type mappings are correct
- Properly handle relationship directions and cardinalities
- Add complete Chinese descriptions and comments
3. Model Validation Phase
- Check model completeness and consistency
- Verify relationship rationality
- Confirm field constraint correctness
- Check naming convention compliance
MySQL Data Type Support
Basic Type Mappings
string → VARCHAR/TEXT
number → INT/BIGINT/DECIMAL
boolean → BOOLEAN/TINYINT
date → DATE
datetime → DATETIME
time → TIME
Extended Type Mappings
x-enum → ENUM type
x-file/x-image → File path storage
x-rtf → LONGTEXT rich text
x-area-code → Region code
x-location → Geographic location coordinates
email/phone/url → VARCHAR with validation
Relationship Implementation
- One-to-one: Foreign key constraints
- One-to-many: Foreign key associations
- Many-to-many: Intermediate table implementation
- Self-association: Same table foreign key
Tool Usage Guidelines
Tool Call Timing (RARE - Use Sparingly)
- Only when user explicitly requests advanced data modeling with Mermaid diagrams
- Only for complex enterprise applications with multi-entity relationships
- Only when user provides detailed business requirement descriptions requiring automated modeling
- Only when you need to update existing data model structure AND want visual ER diagrams
When to SKIP this tool (Most Cases)
- Simple table creation → Use
executeWriteSQL with CREATE TABLE
- Schema changes → Use
executeWriteSQL with ALTER TABLE
- Basic CRUD → Use appropriate SQL statements directly
- Data queries → Use
executeReadOnlySQL
Parameter Usage Guide
mermaidDiagram: Complete mermaid classDiagram code
publish: Whether to publish model immediately (recommend default to false, create then publish)
updateMode: Create new model or update existing model
Error Handling Strategy
- Syntax errors: Check Mermaid syntax format
- Field type errors: Verify type mapping relationships
- Relationship errors: Check relationship directions and cardinalities
- Naming conflicts: Provide renaming suggestions
Best Practices
Model Design Principles
- Single Responsibility: Each entity class is responsible for only one business concept
- Minimize Dependencies: Reduce unnecessary relationships
- Extensibility: Reserve field space for future expansion
- Consistency: Maintain consistency in naming and type usage
Performance Considerations
- Index Design: Create indexes for commonly queried fields
- Field Length: Reasonably set string field lengths
- Relationship Optimization: Avoid excessive many-to-many relationships
- Data Sharding: Consider table sharding strategies for large tables
Security Standards
- Sensitive Fields: Encrypt storage for sensitive information like passwords
- Permission Control: Clarify read/write permissions for fields
- Data Validation: Set appropriate field constraints
- Audit Logs: Add operation records for important entities
Common Business Scenario Templates
User Management System
classDiagram
class User {
username: string <<Username>>
email: email <<Email>>
password: string <<Password>>
avatar: x-image <<Avatar>>
status: x-enum = "active" <<Status>>
required() ["username", "email"]
unique() ["username", "email"]
enum_status() ["active", "inactive", "banned"]
display_field() "username"
}
E-commerce System
classDiagram
class Product {
name: string <<Product Name>>
price: number <<Price>>
description: x-rtf <<Product Description>>
images: x-image[] <<Product Images>>
category: string <<Category>>
stock: number = 0 <<Stock>>
required() ["name", "price"]
display_field() "name"
}
class Order {
orderNo: string <<Order Number>>
totalAmount: number <<Total Amount>>
status: x-enum = "pending" <<Order Status>>
createTime: datetime <<Create Time>>
required() ["orderNo", "totalAmount"]
unique() ["orderNo"]
enum_status() ["pending", "paid", "shipped", "completed", "cancelled"]
display_field() "orderNo"
}
Content Management System
classDiagram
class Article {
title: string <<Title>>
content: x-rtf <<Content>>
author: string <<Author>>
publishTime: datetime <<Publish Time>>
status: x-enum = "draft" <<Status>>
tags: string[] <<Tags>>
required() ["title", "content", "author"]
enum_status() ["draft", "published", "archived"]
display_field() "title"
}
These rules will guide AI Agents to generate high-quality, business-requirement-compliant data models during the data modeling process.
1---2name: data-model-creation3description: Optional advanced tool for complex data modeling. For simple table creation, use relational-database-tool directly with SQL statements.4---56## When to use this skill78This is an **OPTIONAL advanced modeling tool** for complex database design. Most simple table creation should use `relational-database-tool` directly with SQL statements.910**ONLY use this skill when you specifically need:**11- Complex multi-table relationships with automatic foreign key management12- Visual ER diagram generation for documentation13- Automated field type mapping and constraint generation14- Enterprise-level data model documentation1516**For most cases, use `rules/relational-database-tool/rule.md` instead:**17- Simple table creation with CREATE TABLE statements18- Basic CRUD operations19- Schema modifications with ALTER TABLE20- Direct SQL execution without Mermaid modeling2122**Do NOT use for:**23- Querying or manipulating existing data (use database skills)24- NoSQL database design (use NoSQL skills)25- Frontend data structures (use appropriate frontend skills)2627---2829## How to use this skill (for a coding agent)3031**⚠️ NOTE: This is OPTIONAL. For simple tasks, skip this and use `relational-database-tool` directly.**3233When you do use this advanced modeling approach:34351. **Optional modeling workflow** (only when complexity justifies it)36 - Business analysis phase: Analyze user requirements, identify core entities and relationships37 - Mermaid modeling phase: Create mermaid classDiagram following generation rules38 - Model validation phase: Check completeness, consistency, and correctness39402. **Apply generation rules strictly** (when using this tool)41 - Use correct type mappings (string, number, boolean, x-enum, etc.)42 - Convert Chinese to English naming (PascalCase for classes, camelCase for fields)43 - Define required(), unique(), display_field() functions when needed44 - Use proper relationship notation with field names45463. **Use tools correctly** (only when you choose this approach)47 - Call data model creation tools only for complex multi-entity business requirements48 - Use `mermaidDiagram` parameter with complete mermaid classDiagram code49 - Set `publish` to false initially, create then publish separately50 - Choose appropriate `updateMode` for new or existing models5152---5354## Quick Decision Guide5556**Most Database Tasks → `rules/relational-database-tool/rule.md`**57- ✅ Simple table creation58- ✅ Data queries and modifications59- ✅ Schema changes60- ✅ Direct SQL execution6162**Complex Modeling Only → This rule (`rules/data-model-creation/rule.md`)**63- 🎯 Multi-entity relationship modeling64- 🎯 Automated foreign key management65- 🎯 Visual ER diagram generation66- 🎯 Enterprise documentation6768---6970# Data Model AI Modeling Professional Rules7172## ⚠️ IMPORTANT: Simplified Workflow Recommendation7374**For most database table creation tasks, use `rules/relational-database-tool/rule.md` directly:**7576- Simple table creation: `CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255))`77- Schema modifications: `ALTER TABLE users ADD COLUMN email VARCHAR(255)`78- Data operations: `INSERT`, `UPDATE`, `SELECT`, `DELETE`7980**Only use this advanced Mermaid modeling approach when:**81- You need automated relationship management82- Complex multi-table schemas with foreign keys83- Enterprise documentation requirements84- Visual ER diagram generation8586**This rule exists for complex modeling scenarios, but most development should use direct SQL execution.**8788## AI Modeling Expert Prompt8990As an expert in data modeling and a senior architect in software development, you are proficient in Mermaid. Your main task is to provide model structures in mermaid classDiagram format based on user descriptions, following the detailed rules below:9192### Generation Rules93941. **Type Mapping Priority**: When user-described fields match the mapping relationship, prioritize using type as the field type. Mapping relationships are as follows:95 | Business Field | type |96 | --- | --- |97 | Text | string |98 | Number | number |99 | Boolean | boolean |100 | Enum | x-enum |101 | Email | email |102 | Phone | phone |103 | URL | url |104 | File | x-file |105 | Image | x-image |106 | Rich Text | x-rtf |107 | Region | x-area-code |108 | Time | time |109 | Date | date |110 | DateTime | datetime |111 | Object | object |112 | Array | string[] |113 | Location | x-location |1141152. **Naming Convention**: Convert Chinese descriptions to English naming (except enum values). Use PascalCase for class names, camelCase for field names.1161173. **Field Visibility**: Use default visibility for fields, do not add "+" or "-".1181194. **Array Types**: When descriptions include array types, use specific array formats such as string[], number[], x-rtf[], etc.1201215. **Chinese Administrative Regions**: When involving Chinese administrative regions like "province/city/district", use x-area-code field type.1221236. **Required Fields**: When descriptions explicitly mention required fields, define a required() parameterless function, return value as string array of required field names, e.g., `required() ["name", "age"]`. By default, fields are not required.1241257. **Unique Fields**: When descriptions explicitly mention unique fields, define a unique() parameterless function, return value as string array of unique field names, e.g., `unique() ["name", "age"]`. By default, fields are not unique.1261278. **Default Values**: When descriptions explicitly require field default values, use "= default value" format after field definition, e.g., `age: number = 0`. By default, fields have no default values.1281299. **Field Descriptions**: For each field definition in user descriptions, use `<<description>>` format at the end of the definition line, e.g., `name: string <<Name>>`.13013110. **Display Field**: Each entity class should have a field for display when being referenced. Usually a human-readable name or unique identifier. Define display_field() parameterless function, return value is a field name representing the main display field, e.g., `display_field() "name"` means the main display field is name. Otherwise, default to the implicit _id of the data model.13213311. **Class Notes**: After all class definitions are complete, use note to describe class names. First use "%% Class naming" to anchor the area, then provide Chinese table names for each class.13413512. **Relationships**: When descriptions contain relationships, relationship label LabelText should not use original semantics, but use relationship field names. For example, `A "n" <-- "1" B: field1` means A has many-to-one relationship with B, data exists in A's field1 field. Refer to examples for specifics.13613713. **Naming**: Field names and descriptions in Mermaid should be concise and accurately expressed.13813914. **Complexity Control**: Unless user requires, control complexity, e.g., number of classes should not exceed 5, control field complexity.140141### Standard Example142143```mermaid144classDiagram145 class Student {146 name: string <<Name>>147 age: number = 18 <<Age>>148 gender: x-enum = "Male" <<Gender>>149 classId: string <<Class ID>>150 identityId: string <<Identity ID>>151 course: Course[] <<Courses>>152 required() ["name"]153 unique() ["name"]154 enum_gender() ["Male", "Female"]155 display_field() "name"156 }157 class Class {158 className: string <<Class Name>>159 display_field() "className"160 }161 class Course {162 name: string <<Course Name>>163 students: Student[] <<Students>>164 display_field() "name"165 }166 class Identity {167 number: string <<ID Number>>168 display_field() "number"169 }170171 %% Relationships172 Student "1" --> "1" Identity : studentId173 Student "n" --> "1" Class : student2class174 Student "n" --> "m" Course : course175 Student "n" <-- "m" Course : students176 %% Class naming177 note for Student "Student Model"178 note for Class "Class Model"179 note for Course "Course Model"180 note for Identity "Identity Model"181```182183## Data Model Creation Workflow184185### 1. Business Analysis Phase186- Carefully analyze user's business requirement descriptions187- Identify core entities and business objects188- Determine relationships between entities189- Clarify required fields, unique constraints, and default values190191### 2. Mermaid Modeling Phase192- Strictly follow the above generation rules to create mermaid classDiagram193- Ensure field type mappings are correct194- Properly handle relationship directions and cardinalities195- Add complete Chinese descriptions and comments196197### 3. Model Validation Phase198- Check model completeness and consistency199- Verify relationship rationality200- Confirm field constraint correctness201- Check naming convention compliance202203## MySQL Data Type Support204205### Basic Type Mappings206- `string` → VARCHAR/TEXT207- `number` → INT/BIGINT/DECIMAL208- `boolean` → BOOLEAN/TINYINT209- `date` → DATE210- `datetime` → DATETIME211- `time` → TIME212213### Extended Type Mappings214- `x-enum` → ENUM type215- `x-file`/`x-image` → File path storage216- `x-rtf` → LONGTEXT rich text217- `x-area-code` → Region code218- `x-location` → Geographic location coordinates219- `email`/`phone`/`url` → VARCHAR with validation220221### Relationship Implementation222- One-to-one: Foreign key constraints223- One-to-many: Foreign key associations224- Many-to-many: Intermediate table implementation225- Self-association: Same table foreign key226227## Tool Usage Guidelines228229### Tool Call Timing (RARE - Use Sparingly)2301. **Only when user explicitly requests advanced data modeling with Mermaid diagrams**2312. **Only for complex enterprise applications with multi-entity relationships**2323. **Only when user provides detailed business requirement descriptions requiring automated modeling**2334. **Only when you need to update existing data model structure AND want visual ER diagrams**234235### When to SKIP this tool (Most Cases)236- Simple table creation → Use `executeWriteSQL` with CREATE TABLE237- Schema changes → Use `executeWriteSQL` with ALTER TABLE238- Basic CRUD → Use appropriate SQL statements directly239- Data queries → Use `executeReadOnlySQL`240241### Parameter Usage Guide242- `mermaidDiagram`: Complete mermaid classDiagram code243- `publish`: Whether to publish model immediately (recommend default to false, create then publish)244- `updateMode`: Create new model or update existing model245246### Error Handling Strategy247- Syntax errors: Check Mermaid syntax format248- Field type errors: Verify type mapping relationships249- Relationship errors: Check relationship directions and cardinalities250- Naming conflicts: Provide renaming suggestions251252## Best Practices253254### Model Design Principles2551. **Single Responsibility**: Each entity class is responsible for only one business concept2562. **Minimize Dependencies**: Reduce unnecessary relationships2573. **Extensibility**: Reserve field space for future expansion2584. **Consistency**: Maintain consistency in naming and type usage259260### Performance Considerations2611. **Index Design**: Create indexes for commonly queried fields2622. **Field Length**: Reasonably set string field lengths2633. **Relationship Optimization**: Avoid excessive many-to-many relationships2644. **Data Sharding**: Consider table sharding strategies for large tables265266### Security Standards2671. **Sensitive Fields**: Encrypt storage for sensitive information like passwords2682. **Permission Control**: Clarify read/write permissions for fields2693. **Data Validation**: Set appropriate field constraints2704. **Audit Logs**: Add operation records for important entities271272## Common Business Scenario Templates273274### User Management System275```mermaid276classDiagram277 class User {278 username: string <<Username>>279 email: email <<Email>>280 password: string <<Password>>281 avatar: x-image <<Avatar>>282 status: x-enum = "active" <<Status>>283 required() ["username", "email"]284 unique() ["username", "email"]285 enum_status() ["active", "inactive", "banned"]286 display_field() "username"287 }288```289290### E-commerce System291```mermaid292classDiagram293 class Product {294 name: string <<Product Name>>295 price: number <<Price>>296 description: x-rtf <<Product Description>>297 images: x-image[] <<Product Images>>298 category: string <<Category>>299 stock: number = 0 <<Stock>>300 required() ["name", "price"]301 display_field() "name"302 }303 class Order {304 orderNo: string <<Order Number>>305 totalAmount: number <<Total Amount>>306 status: x-enum = "pending" <<Order Status>>307 createTime: datetime <<Create Time>>308 required() ["orderNo", "totalAmount"]309 unique() ["orderNo"]310 enum_status() ["pending", "paid", "shipped", "completed", "cancelled"]311 display_field() "orderNo"312 }313```314315### Content Management System316```mermaid317classDiagram318 class Article {319 title: string <<Title>>320 content: x-rtf <<Content>>321 author: string <<Author>>322 publishTime: datetime <<Publish Time>>323 status: x-enum = "draft" <<Status>>324 tags: string[] <<Tags>>325 required() ["title", "content", "author"]326 enum_status() ["draft", "published", "archived"]327 display_field() "title"328 }329```330331These rules will guide AI Agents to generate high-quality, business-requirement-compliant data models during the data modeling process.332