| ํญ๋ชฉ | ๋ด์ฉ |
|---|---|
| Invoke | /serverpod:endpoint |
| Aliases | /backend:endpoint, /api:create |
| Tools | Read, Edit, Write, Glob, Grep |
| Model | sonnet |
| Skills | serverpod |
/serverpod:endpoint โ ๋ฐฑ์๋ API ๋ง๋ค์ด์ฃผ๋ ์ผ๊พผ#
ํ๋ง๋๋ก#
์ฑ ํ๋ฉด์ด ์๋ฒ์ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์ ๋ ์ฐ๋ "์ฐฝ๊ตฌ(API)"๋ฅผ ์๋์ผ๋ก ๋ง๋ค์ด์ฃผ๋ ๋์ฐ๋ฏธ์ ๋๋ค. ์๋น์ ๋น์ ํ๋ฉด, ์๋ ์ฃผ๋ฌธ์ ๋ฐ์ ์ฃผ๋ฐฉ์ ์ ๋ฌํ๋ "์ฃผ๋ฌธ ์ฐฝ๊ตฌ"์ ๊ทธ ๋ค์์ ์ค์ ๋ก ์๋ฆฌํ๋ "์ฃผ๋ฐฉ"์ ํ ๋ฒ์ ์ฐจ๋ ค์ฃผ๋ ์ ์ด์์.
๋๊ฐยท์ธ์ ์ฐ๋์#
- ์ ๊ธฐ๋ฅ์ ํ์ํ ์๋ฒ API(๋ฐ์ดํฐ๋ฅผ ๋ง๋ค๊ณ ยท์ฝ๊ณ ยท๊ณ ์น๊ณ ยท์ง์ฐ๋ ๊ธฐ๋ฅ)๋ฅผ ๋ง๋ค์ด์ผ ํ ๋
-
์ง์
/serverpod:endpoint๋ช ๋ น์ ์คํํ๊ฑฐ๋, ์ ์ฒด ๊ธฐ๋ฅ์ ํ ๋ฒ์ ๋ง๋๋/feature:create์์ ์ ํ ๋จ๊ณ๋ก ์๋ ํธ์ถ๋ ๋
๋ฌด์์ ํด์ฃผ๋์#
๊ธฐ๋ฅ ์ด๋ฆ๊ณผ ๋ฐ์ดํฐ ์ด๋ฆ๋ง ์๋ ค์ฃผ๋ฉด, ์๋ ํ์ผ๋ค์ ์ผ์ ํ ๊ท์น์ ๋ง์ถฐ ๋ง๋ค์ด ์ค๋๋ค.
- ์ฑ์ฉ ์ฐฝ๊ตฌ(
{feature_name}_endpoint.dart) โ ์ผ๋ฐ ์ฌ์ฉ์ ์ฑ์ด ์ฐ๋ API - ๊ด๋ฆฌ์์ฉ ์ฐฝ๊ตฌ(
{feature_name}_console_endpoint.dart) โ ๊ด๋ฆฌ์ ์ ์ฉ API (๊ถํ ํ์ธ ํฌํจ) - ์ค์ ์ฒ๋ฆฌ ๋ก์ง(
{feature_name}_service.dart) โ ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฃจ๋ ํต์ฌ ์ ๋ฌด ์ฒ๋ฆฌ - ์
๋ ฅ๊ฐ ๊ฒ์ฆ(
{feature_name}_validator.dart) โ ์๋ชป๋ ์ ๋ ฅ์ ๊ฑธ๋ฌ๋ด๋ ์ฅ์น
๋ง๋ค๊ธฐ๋ง ํ๊ณ ๋๋๋ ๊ฒ ์๋๋ผ, ์๋ฒ๊ฐ ์ด ์ ์ฐฝ๊ตฌ๋ฅผ ์ธ์ํ๋๋ก ๋ง๋ฌด๋ฆฌ ์์ (์ฝ๋ ์์ฑ)๊น์ง ์๋์ผ๋ก ์คํํฉ๋๋ค. ์ด ๋ง๋ฌด๋ฆฌ๋ฅผ ๋น ๋จ๋ฆฌ๋ฉด ์ API๋ฅผ ์ฑ์์ ๋ถ๋ฅผ ์ ์์ผ๋ ๊ผญ ํ์ํ ๋จ๊ณ์์.
์ด๋ป๊ฒ ์ฐ๋์#
# ๊ธฐ๋ณธ (์ฑ์ฉ API, ์ ์ฒด CRUD ์๋ ์์ฑ)
/serverpod:endpoint
# ๊ฐ์ ์ผ์ ํ๋ ๋ค๋ฅธ ์ด๋ฆ(๋ณ์นญ)์ผ๋ก๋ ํธ์ถ ๊ฐ๋ฅ
/backend:endpoint
/api:create
์ ๋ฌํ ์ ์๋ ๊ฐ:
feature_name(ํ์) โ ๊ธฐ๋ฅ ๋ชจ๋ ์ด๋ฆ (snake_case, ์:banner)entity_name(ํ์) โ ๋ฐ์ดํฐ ์ด๋ฆ (PascalCase, ์:Banner)-
endpoint_type(์ ํ) โapp(์ฑ์ฉ) /console(๊ด๋ฆฌ์์ฉ) /both(๋ ๋ค), ๊ธฐ๋ณธ๊ฐ์app methods(์ ํ) โ ๋ง๋ค ๊ธฐ๋ฅ ๋ชฉ๋ก, ๊ธฐ๋ณธ๊ฐ์ ์ ์ฒด CRUD(์์ฑยท์กฐํยท์์ ยท์ญ์ )
์์์ ๋ฌด์จ ์ผ์ด ๋ฒ์ด์ง๋์#
- ์ฐฝ๊ตฌ์ ์ฃผ๋ฐฉ์ ์ฐจ๋ฆฝ๋๋ค โ ์ฑ์ฉยท๊ด๋ฆฌ์์ฉ API ์ฐฝ๊ตฌ์, ๊ทธ ๋ค์์ ์ค์ ๋ก ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ๋ ๋ก์ง ํ์ผ์ ๊ท์น์ ๋ง๊ฒ ์์ฑํฉ๋๋ค.
- ๊ถํ์ ์ฑ๊น๋๋ค โ ๊ด๋ฆฌ์์ฉ ์ฐฝ๊ตฌ์๋ "๋ก๊ทธ์ธ ํ์ + ๊ด๋ฆฌ์ ๊ถํ" ๊ฐ์ ๋ณดํธ ์ฅ์น๋ฅผ ๊ฑธ๊ณ , ์ฑ์ฉ ์ฐฝ๊ตฌ์๋ ๋ก๊ทธ์ธ ์ฌ์ฉ์ ํ์ธ์ ๋ฃ์ต๋๋ค.
- ์์ ํ๊ฒ ์ญ์ ํฉ๋๋ค โ ๋ฐ์ดํฐ๋ฅผ ์ง์ง๋ก ์ง์ฐ์ง ์๊ณ "์ง์์ง ํ์"๋ง ๋จ๊ธฐ๋ ๋ฐฉ์(soft delete)์ ์ ์ฉํฉ๋๋ค.
-
๋ง๋ฌด๋ฆฌ ์์
์ ์คํํฉ๋๋ค โ ์๋ฒ๊ฐ ์ API๋ฅผ ์ธ์ํ๋๋ก ์ฝ๋ ์์ฑ(
backend:pod:generate)์ ์๋์ผ๋ก ๋๋ฆฌ๊ณ , ๋ณ๊ฒฝ ์ฌํญ์ ์ปค๋ฐํฉ๋๋ค.
โ๏ธ ์์ธ ์ต์ ยท์คํ ๋ช ์ธ (๊ฐ๋ฐ์ / AI ์์ด์ ํธ์ฉ)
Role#
Generates Serverpod Endpoint and Service classes. Consistently implements App/Console endpoint separation, CRUD method patterns, and error handling.
Activation Conditions#
- Activated on
/serverpod:endpointcommand invocation - Called in Step 2 of
/feature:createorchestration
Parameters#
| Parameter | Required | Description |
|---|---|---|
feature_name | โ | Feature module name (snake_case) |
entity_name | โ | Entity name (PascalCase) |
endpoint_type | โ | app, console, both (default: app) |
methods | โ | List of methods to generate (default: full CRUD) |
Generated Files#
backend/kobic_server/lib/src/feature/{feature_name}/
โโโ endpoint/
โ โโโ {feature_name}_endpoint.dart # App endpoint
โ โโโ {feature_name}_console_endpoint.dart # Console endpoint
โโโ service/
โ โโโ {feature_name}_service.dart # Business logic
โโโ validation/
โโโ {feature_name}_validator.dart # Input validationImport Order (Required)#
// 1. Serverpod framework
import 'package:serverpod/server.dart';
// 2. Generated protocol (models)
import 'package:kobic_server/src/generated/protocol.dart';
// 3. Feature internal services
import 'package:kobic_server/src/feature/{feature}/service/{service}.dart';
// 4. Common utilities
import 'package:kobic_server/src/common/authenticated_mixin.dart';
Core Pattern Summary#
App Endpoint#
- Use
AuthenticatedMixin - Call
requireCurrentUserInfo(session) - Delegate logic to Service classes
Console Endpoint#
requireLogin => truerequiredScopes => {Scope.admin}- Admin-only methods
Service Pattern#
- Use static methods
- try-catch +
session.log()error handling - Soft delete:
isDeleted: true
DB Query Patterns#
| Operation | Pattern |
|---|---|
| Create | Entity.db.insertRow(session, entity) |
| Read | Entity.db.findById(session, id) |
| List | Entity.db.find(session, where: ..., limit: ...) |
| Update | Entity.db.updateRow(session, updated) |
| Delete | Soft delete recommended |
| Count | Entity.db.count(session, where: ...) |
Reference Files#
backend/kobic_server/lib/src/feature/banner/endpoint/banners_endpoint.dart
backend/kobic_server/lib/src/feature/banner/endpoint/banners_console_endpoint.dart
backend/kobic_server/lib/src/feature/banner/service/banner_service.dart
backend/kobic_server/lib/src/common/authenticated_mixin.dart
backend/kobic_server/lib/src/utils/auth.dart # getCurrentUserInfo / requireCurrentUserInfoRequired Post-Generation Steps#
After generating endpoint/service files, you must run the following commands:
# 1. [Required] Code generation - Update Protocol and endpoint registration
melos run backend:pod:generate
# 2. Commit
git add .
git commit -m " chore(backend): code generation "Important#
If backend:pod:generate is skipped:
- New endpoints will not be registered in routing
- Cannot call new API methods from kobic_client
- Frontend build errors will occur
This agent automatically runs backend:pod:generate after endpoint generation.
Checklist#
- Follow import order
- KDoc comments on all methods
- Apply AuthenticatedMixin (for authenticated methods)
- Set permissions on Console endpoints
- Separate business logic into Services
- Implement error handling and logging
- Apply soft delete pattern
backend:pod:generateexecution complete
Related Documents#
Note: kobic has no separate Repository layer. Business logic lives in
service/{feature}_service.dart, which callsEntity.db(Serverpod ORM) directly. Endpoints delegate to services.