architectdata-api-design
Featured数据模型和API设计方法论,包含ERD设计、数据字典、RESTful API规范
Data & Documents 547 stars
50 forks Updated 4 days ago MIT
Install
Quality Score: 94/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# 数据模型与API设计方法论
## 适用场景
在系统架构确定后,需要设计:
- 数据库表结构和关系
- 数据字典和约束
- API接口规范
- 请求/响应格式
## 数据模型设计
### 1. 实体识别
从PRD中识别核心实体(名词):
**示例**:
- 用户系统:User(用户)、Role(角色)、Permission(权限)
- 博客系统:User(用户)、Post(文章)、Comment(评论)、Tag(标签)
- 电商系统:User(用户)、Product(商品)、Order(订单)、OrderItem(订单项)
### 2. 关系识别
确定实体之间的关系:
| 关系类型 | 说明 | 示例 |
|----------|------|------|
| **一对一 (1:1)** | 一个A对应一个B | User - Profile |
| **一对多 (1:N)** | 一个A对应多个B | User - Post |
| **多对多 (M:N)** | 多个A对应多个B | Post - Tag |
**关系表示**:
- `||--o{`: 一对多
- `||--||`: 一对一
- `}o--o{`: 多对多
### 3. 实体关系图 (ERD)
使用 Mermaid 绘制 ERD:
```mermaid
erDiagram
User ||--o{ Post : creates
User ||--o{ Comment : writes
Post ||--o{ Comment : has
Post }o--o{ Tag : has
User {
uuid id PK
string email UK
string name
string passwordHash
enum role
datetime createdAt
datetime updatedAt
}
Post {
uuid id PK
uuid authorId FK
string title
text content
enum status
datetime publishedAt
datetime createdAt
datetime updatedAt
}
Comment {
uuid id PK
uuid postId FK
uuid userId FK
text content
datetime createdAt
}
Tag {
uuid id PK
string name UK
}
```
### 4. 数据字典
为每个表定义详细的字段信息:
#### User 表
| 字段 | 类型 | 约束 | 默认值 | 说明 |
|------|------|------|--------|------|
| id | UUID | PK | uuid_generate_v4() | 主键 |
| email | VARCHAR(255) | UNIQUE, NOT NULL | ...
Details
- Author
- echoVic
- Repository
- echoVic/boss-skill
- Created
- 7 months ago
- Last Updated
- 4 days ago
- Language
- TypeScript
- License
- MIT
Integrates with
Similar Skills
Semantically similar based on skill content — not just same category
AI & Automation Listed
database-design
Design a safe, query-aware database schema from business entities, access patterns, consistency needs, and operational constraints. Use whenever the user asks for database design, schema design, table modeling, ERD, indexing, query optimization, data partitioning, multi-tenancy, migration planning, backups, or relational-versus-document tradeoffs—even if they only say "design the data model." Produce a reviewable schema specification before SQL execution; do not silently run migrations or modify a database.
1 Updated 2 weeks ago
AVA-2568 AI & Automation Listed
model-design
当用户要求"设计模型/建表/设计实体/加字段/设计 DTO/设计 VO"时触发。 产出领域模型与数据模型设计文档,融入当前变更提案。 MUST 按 DDD Entity/PO/DTO/VO 分层规范设计。
1 Updated 1 weeks ago
structure-projects AI & Automation Listed
pdlc-db-design
数据库设计
10 Updated 1 weeks ago
kanfu-panda