LogoSkills

serverpod-endpoint-agent

Serverpod Endpoint expert. Use for endpoint and service class generation

ํ•ญ๋ชฉ๋‚ด์šฉ
Invoke/serverpod:endpoint
Aliases/backend:endpoint, /api:create
ToolsRead, Edit, Write, Glob, Grep
Modelsonnet
Skillsserverpod

/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(์ƒ์„ฑยท์กฐํšŒยท์ˆ˜์ •ยท์‚ญ์ œ)

์•ˆ์—์„œ ๋ฌด์Šจ ์ผ์ด ๋ฒŒ์–ด์ง€๋‚˜์š”#

  1. ์ฐฝ๊ตฌ์™€ ์ฃผ๋ฐฉ์„ ์ฐจ๋ฆฝ๋‹ˆ๋‹ค โ€” ์•ฑ์šฉยท๊ด€๋ฆฌ์ž์šฉ API ์ฐฝ๊ตฌ์™€, ๊ทธ ๋’ค์—์„œ ์‹ค์ œ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋กœ์ง ํŒŒ์ผ์„ ๊ทœ์น™์— ๋งž๊ฒŒ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  2. ๊ถŒํ•œ์„ ์ฑ™๊น๋‹ˆ๋‹ค โ€” ๊ด€๋ฆฌ์ž์šฉ ์ฐฝ๊ตฌ์—๋Š” "๋กœ๊ทธ์ธ ํ•„์ˆ˜ + ๊ด€๋ฆฌ์ž ๊ถŒํ•œ" ๊ฐ™์€ ๋ณดํ˜ธ ์žฅ์น˜๋ฅผ ๊ฑธ๊ณ , ์•ฑ์šฉ ์ฐฝ๊ตฌ์—๋Š” ๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž ํ™•์ธ์„ ๋„ฃ์Šต๋‹ˆ๋‹ค.
  3. ์•ˆ์ „ํ•˜๊ฒŒ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค โ€” ๋ฐ์ดํ„ฐ๋ฅผ ์ง„์งœ๋กœ ์ง€์šฐ์ง€ ์•Š๊ณ  "์ง€์›Œ์ง„ ํ‘œ์‹œ"๋งŒ ๋‚จ๊ธฐ๋Š” ๋ฐฉ์‹(soft delete)์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.
  4. ๋งˆ๋ฌด๋ฆฌ ์ž‘์—…์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค โ€” ์„œ๋ฒ„๊ฐ€ ์ƒˆ 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:endpoint command invocation
  • Called in Step 2 of /feature:create orchestration

Parameters#

ParameterRequiredDescription
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 validation

Import 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 => true
  • requiredScopes => {Scope.admin}
  • Admin-only methods

Service Pattern#

  • Use static methods
  • try-catch + session.log() error handling
  • Soft delete: isDeleted: true

DB Query Patterns#

OperationPattern
CreateEntity.db.insertRow(session, entity)
ReadEntity.db.findById(session, id)
ListEntity.db.find(session, where: ..., limit: ...)
UpdateEntity.db.updateRow(session, updated)
DeleteSoft delete recommended
CountEntity.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 / requireCurrentUserInfo

Required 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:generate execution complete

Note: kobic has no separate Repository layer. Business logic lives in service/{feature}_service.dart, which calls Entity.db (Serverpod ORM) directly. Endpoints delegate to services.