scaffold-service
Scaffold a thin FastAPI router or gRPC servicer under services/{domain}/v{n}/ with AppUtils bootstrap. Use for "add an endpoint/route/API", "expose via REST/gRPC", or "new API version".
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- scaffold-service
- description
- Scaffold a thin FastAPI router or gRPC servicer under services/{domain}/v{n}/ with AppUtils bootstrap. Use for "add an endpoint/route/API", "expose via REST/gRPC", or "new API version".
03 SKILL.md 正文
Scaffold ArchiPy Service
Read first
Read these plugin rules in full before generating files (paths relative to this skill directory; Claude Code: ${CLAUDE_SKILL_DIR}/../../rules/):
../../rules/architecture-for-apps.mdc../../rules/using-archipy-utils.mdc../../rules/using-archipy-services.mdc../../rules/config-and-di.mdc
Before writing files
- Inspect existing transports, domain DTOs/logics, app bootstrap, DI wiring, and service tests.
- Infer domain, API version, framework, and sync/async style when established by the repository.
- Ask only for unresolved choices. Default to
v1and FastAPI only when no project convention exists. - Preserve existing routes, servicers, and bootstrap code; integrate without overwriting.
Prefer ArchiPy
uv add "archipy[fastapi]" # HTTP
uv add "archipy[grpc]" # gRPC
Generate
services/<domain>/v{n}/
└── <domain>_service.py
FastAPI
- Thin router: request → domain
*InputDTO→ logic →*OutputDTO. - Export
create_<domain>_v{n}_router(container)formanage.py/ app factory. - Paths follow the REST resource rule in
using-archipy-services.mdc:/api/v1/users/{user_uuid}/campaigns/{campaign_uuid}/...— kebab-case literal segments, plural collections,UUID-typedsnake_casepath params,APIRouter(prefix="/api/v1"). - JWT auth (Keycloak or other): compute
actor_uuid= actor (current_actor.id/act) first, else token subject (user_id/sub); pass it in the input DTO forcreated_by*/updated_by*. Never use a path owner uuid (customer, merchant, admin, user…) as the actor (seeusing-archipy-services.mdc). - Map domain errors to HTTP status; no business rules / atomic UoW decorators here.
gRPC
- Thin servicer calling logic; sync servicers with
AppUtils.create_grpc_app, async withcreate_async_grpc_app. - Export
register_<domain>_v{n}_servicers(server, container)that adds the servicers to a server built byAppUtils; the entrypoint and the BDD harness (/scaffold-bdd) both call it, so neither binds a port inside it. - Do not mix sync/async servicer styles on one server.
- Request/response DTOs extend
BaseProtobufDTO(_proto_class,from_proto/to_proto);from_protois the validation boundary. CatchValidationErrorand raiseInvalidArgumentError ... from e; keep proto types out of logics. Seerules/using-archipy-models.mdc.
Bootstrap (entrypoint)
Prefer AppUtils — do not hand-roll bare FastAPI() / grpc.server():
from archipy.helpers.utils.app_utils import AppUtils
from archipy.configs.base_config import BaseConfig
app = AppUtils.create_fastapi_app()
app.include_router(create_<domain>_v1_router(container))
uvicorn in manage.py with **AppUtils.uvicorn_config(config): host and port from config.FASTAPI (SERVE_HOST,
SERVE_PORT), the server settings (RELOAD, PROXY_HEADERS, FORWARDED_ALLOW_IPS, timeouts, workers, TLS) from
config.UVICORN (archipy >= 5.25.0).
Do not
- Version in path (
v1,v2), not in business logic. - Do not re-implement CORS/exception handlers/stock gRPC interceptors AppUtils already wires.
- Wire logic via DI container.
- Never hardcode host/port.
Verify
- Run the repository's formatter and linter on generated Python.
- Run the Behave scenarios that exercise the route/servicer through the BDD harness (
/scaffold-bdd); add one when the endpoint is new. - Confirm route/servicer registration, DTO mapping, domain-error mapping, and DI resolution.
- Run the
archipy-reviewersubagent on the changes and fix every Must fix finding it reports. - Report files, dependency changes, and commands run.
Docs
04 同仓库更多 Skills
scaffold-utils
Add or wire pure helpers/utils, preferring ArchiPy utils (datetime, JWT, password, file, string). Use for "add a helper/util function", "format dates", "hash passwords", or "generate tokens".
scaffold-observability
Configure ArchiPy 5.x OpenTelemetry traces, metrics, logs, and instrumentation. Use for "add tracing/metrics/OTel", "Prometheus/Pushgateway", or migrating off Sentry, Elastic APM, or old Prometheus.
scaffold-models
Scaffold ArchiPy models under models/: domain/repository DTOs, errors, optional entities and types. Use for "add DTO/schema/request/response model", "new error type", or "SQLAlchemy entity".
scaffold-logic
Scaffold an ArchiPy logic (use case) under logics/{domain}/ with a unit-of-work decorator and DTO I/O. Use for "add business logic", "new use case", "transactional operation", or "service layer method".
scaffold-interceptor
Add or wire cross-cutting FastAPI/gRPC interceptors or middleware, preferring ArchiPy's. Use for "add middleware", "request ID/logging/auth interceptor", or "gRPC interceptor".
scaffold-health-checks
Scaffold FastAPI/gRPC liveness, readiness, and startup health checks, graceful shutdown, and optional Kubernetes probes. Use for "health endpoint", "readiness/liveness probe", or "k8s probes".