| ํญ๋ชฉ | ๋ด์ฉ |
|---|---|
| Invoke | /serverpod:model |
| Category | kobic-workflow |
| Complexity | moderate |
| MCP Servers | serena, context7 |
/serverpod:model โ ๋ฐฑ์๋ ๋ฐ์ดํฐ ์ค๊ณ๋ ๋ง๋ค๊ธฐ#
ํ๋ง๋๋ก#
์๋ฒ๊ฐ ๋ค๋ฃฐ ๋ฐ์ดํฐ์ "์ค๊ณ๋"๋ฅผ ์๋์ผ๋ก ๊ทธ๋ ค์ฃผ๋ ๋จ๊ณ์ ๋๋ค. ์๋ฅผ ๋ค์ด "๋ฐฐ๋"๋ผ๋ ๋ฐ์ดํฐ๋ฅผ ๋ง๋ ๋ค๋ฉด, ๋ฐฐ๋์ ์ด๋ค ์ ๋ณด(์ ๋ชฉ, ์ด๋ฏธ์ง ์ฃผ์ ๋ฑ)๊ฐ ๋ค์ด๊ฐ๋์ง ์ ํด์ง ์์์ ํ์ผ๋ก ํ ๋ฒ์ ๋ง๋ค์ด ์ค๋๋ค. ์ง์ ์ง๊ธฐ ์ ์ ๋ฐฉยท์ฐฝ๋ฌธ ์์น๋ฅผ ์ ํ ๋๋ฉด์ ๊ทธ๋ฆฌ๋ ๊ฒ๊ณผ ๊ฐ์์.
๋๊ฐยท์ธ์ ์ฐ๋์#
- ์๋ก์ด ๋ฐ์ดํฐ ์ข ๋ฅ(๋ฐฐ๋, ์ฑ , ๊ฒฐ์ ๋ด์ญ ๋ฑ)๋ฅผ ์๋ฒ์ ์ถ๊ฐํด์ผ ํ ๋
- ๋ฐฑ์๋(์๋ฒ)๊ฐ ์ ์ฅํ๊ณ ์ฃผ๊ณ ๋ฐ์ ๋ฐ์ดํฐ ํํ๋ฅผ ์ฒ์ ์ ์ํ ๋
- ์ ์ฒด ๊ธฐ๋ฅ์ ํ ๋ฒ์ ๋ง๋๋
/feature:create์์ ์ 1๋จ๊ณ๋ก ์๋ ํธ์ถ๋ ๋
๋ฌด์์ ํด์ฃผ๋์#
๋ฐ์ดํฐ ์ค๊ณ๋ ํ์ผ(.spy.yaml)๋ค์ ์ ํด์ง ํด๋์ ๋ง๋ค์ด ์ค๋๋ค. ๊ธฐ๋ฅ ์ด๋ฆ์ด banner๋ผ๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์๊น๋๋ค.
- ๋ณธ์ฒด ์ ์ (
entities/{์ด๋ฆ}.spy.yaml) โ ์ด ๋ฐ์ดํฐ๊ฐ ๊ฐ์ง ํญ๋ชฉ๋ค(์ ๋ชฉ, ์์ฑ์, ์์ฑ์ผ์ ๋ฑ) -
์์ฒญ์ฉ ์์ (
dto/{์ด๋ฆ}_create_request.spy.yaml,..._update_request.spy.yaml) โ ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค๊ฑฐ๋ ์์ ํ ๋ ์ฃผ๊ณ ๋ฐ๋ ํ์ -
์๋ต์ฉ ์์ (
dto/{์ด๋ฆ}_list_response.spy.yaml) โ ๋ชฉ๋ก์ ๋๋ ค์ค ๋์ ํ์(๋ชฉ๋ก, ์ ์ฒด ๊ฐ์, ๋ค์ ํ์ด์ง ์ ๋ฌด) - ๋ถ๋ฅ๊ฐ ์ ์ (
enum/{์ด๋ฆ}_category.spy.yaml) โ ์ ํด์ง ์ ํ์ง ๋ชฉ๋ก(์: ์ผ๋ฐยท๊ณต์งยท์ด๋ฒคํธ)
๋ชจ๋ ํญ๋ชฉ์๋ ํ๊ตญ์ด ์ค๋ช ์ด ๋ถ๊ณ , ์์ฑ์ผ์ยท์์ ์ผ์ ๊ฐ์ ํ์ ํญ๋ชฉ๊ณผ ๊ฒ์์ ๋น ๋ฅด๊ฒ ํ๋ ์์ธ(index)์ด ์๋์ผ๋ก ๋ค์ด๊ฐ๋๋ค.
์ด๋ป๊ฒ ์ฐ๋์#
# ๋ฐฐ๋ ๋ชจ๋ธ ๋ง๋ค๊ธฐ
/serverpod:model banner Banner
--fields " title:String, imageUrl:String, linkUrl:String?, sortOrder:int, isActive:bool "
# ์ฑ
๋ชจ๋ธ ๋ง๋ค๊ธฐ
/serverpod:model books Book
--fields " title:String, authorId:int, categoryId:int, price:double, coverUrl:String? "
# ๊ฒฐ์ ๋ด์ญ ๋ชจ๋ธ ๋ง๋ค๊ธฐ
/serverpod:model payments Transaction
--fields " amount:double, type:TransactionType, description:String?, balanceAfter:double "
-
์ฒซ ๋ฒ์งธ ๊ฐ์ ๊ธฐ๋ฅ ์ด๋ฆ(์๋ฌธ์, ์:
banner), ๋ ๋ฒ์งธ ๊ฐ์ ๋ฐ์ดํฐ ์ด๋ฆ(๋๋ฌธ์ ์์, ์:Banner)์ ๋๋ค. ๋ ๋ค ๋ฐ๋์ ํ์ํฉ๋๋ค. --fields๋ก ๋ค์ด๊ฐ ํญ๋ชฉ๋ค์ ์ ์ต๋๋ค. ์ด๋ฆ ๋ค์?๋ "์์ด๋ ๋๊ณ ์์ด๋ ๋๋ ํญ๋ชฉ"์ด๋ผ๋ ๋ป์ ๋๋ค.--has-crud,--has-enum์ ๊ฐ๊ฐ ์์ฑ/์์ ์์๊ณผ ๋ถ๋ฅ๊ฐ ํ์ผ์ ํจ๊ป ๋ง๋ค์ง ์ ํฉ๋๋ค(๊ธฐ๋ณธ๊ฐ์ ๋ ๋ค ๋ง๋ฆ).
์์์ ๋ฌด์จ ์ผ์ด ๋ฒ์ด์ง๋์#
- ๊ธฐ์กด ๋ฐฉ์ ์ดํด๋ณด๊ธฐ โ ์ด๋ฏธ ๋ง๋ค์ด ๋ ๋น์ทํ ๋ฐ์ดํฐ(๋ฐฐ๋ยท์ฑ ๋ฑ)์ ๊ตฌ์กฐ๋ฅผ ์ฐธ๊ณ ํด ๊ฐ์ ์คํ์ผ๋ก ๋ง์ถฅ๋๋ค.
- ์ค๊ณ๋ ํ์ผ ์์ฑ โ ๋ณธ์ฒด, ์์ฒญยท์๋ต ์์, ๋ถ๋ฅ๊ฐ ํ์ผ์ ํ ๋ฒ์ ๋ง๋ค๊ณ ๊ฐ ํญ๋ชฉ์ ํ๊ตญ์ด ์ค๋ช ์ ๋ถ์ ๋๋ค.
- ์ ๊ฒ โ ๋ชจ๋ ํญ๋ชฉ์ ์ค๋ช ์ด ๋ฌ๋ ธ๋์ง, ์์ฑ์ผ์ยท์์ ์ผ์๊ฐ ๋ค์ด๊ฐ๋์ง, ๊ฒ์์ฉ ์์ธ์ด ์ ์ ์๋๋์ง ํ์ธํฉ๋๋ค.
ํ์ผ์ด ๋ง๋ค์ด์ง ๋ค์๋ ์ค์ ์ฝ๋์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ฐ์ํ๊ธฐ ์ํ ๋ช ๋ น(์ฝ๋ ์์ฑ, ๋ณ๊ฒฝ๋ถ ๋ง๋ค๊ธฐ, ๋ณ๊ฒฝ๋ถ ์ ์ฉ)์ ์ด์ด์ ์คํํฉ๋๋ค.
โ๏ธ ์์ธ ์ต์ ยท์คํ ๋ช ์ธ (๊ฐ๋ฐ์ / AI ์์ด์ ํธ์ฉ)
Triggers#
- When a new Serverpod model (Entity, DTO, Enum) is needed
- When backend data model definition is needed
- Called in Step 1 of
/feature:createorchestration
Context Trigger Pattern#
/serverpod:model {feature_name} {entity_name} [--options]Parameters#
| Parameter | Required | Description | Example |
|---|---|---|---|
feature_name | โ | Feature module name (snake_case) | banner, books, payments |
entity_name | โ | Entity name (PascalCase) | Banner, Book, Transaction |
--fields | โ | Field definition list | "title:String, content:String" |
--has-crud | โ | Auto-generate CRUD DTOs | true (default) |
--has-enum | โ | Generate Enum file | true (default) |
Behavioral Flow#
1. Analyze Existing Patterns#
Use Serena MCP to analyze existing model patterns:
- backend/kobic_server/lib/src/feature/banner/model/ (entities, dto, enum)
- backend/kobic_server/lib/src/feature/books/model/entities/2. Generate Model Files#
Entity File (entities/{entity_name}.spy.yaml):
### {Entity description}
class: {EntityName}
table: {table_name}
fields:
### Unique identifier
id: int?
### {Field1 description}
{field1}: {Type}
### {Field2 description}
{field2}: {Type}?
### Author ID
authorId: int
### Author name
authorName: String
### Author profile image URL
authorProfileUrl: String?
### Created timestamp
createdAt: DateTime
### Updated timestamp
updatedAt: DateTime?
indexes:
{entity}_author_idx:
fields: authorId
{entity}_created_idx:
fields: createdAtRequest DTO (dto/{entity_name}_create_request.spy.yaml):
### {Entity} creation request
class: {EntityName}CreateRequest
fields:
### {Field description}
{requiredField}: {Type}
### {Optional field description}
{optionalField}: {Type}?Response DTO (dto/{entity_name}_list_response.spy.yaml):
### {Entity} list response
class: {EntityName}ListResponse
fields:
### {Entity} list
items: List < {EntityName} >
### Total count
total: int
### Whether next page exists
hasMore: boolEnum (enum/{entity_name}_category.spy.yaml):
### {Entity} category
enum: {EntityName}Category
serialized: byName
values:
- general
- notice
- event3. Verification#
- Verify Korean comments on all fields
- Verify required fields (createdAt, updatedAt) included
- Verify index definitions
Output Files#
backend/kobic_server/lib/src/feature/{feature_name}/model/
โโโ entities/
โ โโโ {entity_name}.spy.yaml
โโโ dto/
โ โโโ {entity_name}_create_request.spy.yaml
โ โโโ {entity_name}_update_request.spy.yaml
โ โโโ {entity_name}_list_response.spy.yaml
โโโ enum/
โโโ {entity_name}_category.spy.yamlPost-Generation Commands#
# Model code generation
melos run backend:pod:generate
# Create migration (for Entity changes)
melos run backend:pod:create-migration
# Apply migration
melos run backend:pod:run-migrationMCP Integration#
- Serena: Analyze existing model patterns, symbol search
- Context7: Serverpod model definition documentation reference
Examples#
Create banner model#
/serverpod:model banner Banner
--fields " title:String, imageUrl:String, linkUrl:String?, sortOrder:int, isActive:bool "Create book model#
/serverpod:model books Book
--fields " title:String, authorId:int, categoryId:int, price:double, coverUrl:String? "Create payments transaction model#
/serverpod:model payments Transaction
--fields " amount:double, type:TransactionType, description:String?, balanceAfter:double "Reference Agent#
See ${CLAUDE_PLUGIN_ROOT}/commands/agents/backend/serverpod-model-agent.md for detailed implementation rules
Core Rules Summary#
- Korean comments (
###) required on all fields - createdAt, updatedAt fields required
- Appropriate index definitions required
- Foreign key relation definitions (when needed)
- Default value settings (counters, status fields)