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".
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- scaffold-logic
- description
- 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".
03 SKILL.md 正文
Scaffold ArchiPy Logic
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-logics.mdc../../rules/using-archipy-models.mdc
Before writing files
- Inspect the target domain's DTOs, repository contract, neighboring logics, DI wiring, and tests.
- Infer naming and sync/async style from existing code and installed extras.
- Ask only for an unresolved domain/use-case name or transaction choice. Default to sync for
postgres+sqlalchemyand async forpostgres+sqlalchemy-async. Skip a UoW decorator when the use-case does not own a SQLAlchemy session. - Preserve existing use cases; do not overwrite logic or DTO files.
Prefer ArchiPy
Install a SQLAlchemy extra only when this use-case owns a Postgres UoW:
uv add "archipy[postgres,sqlalchemy]"
# or: uv add "archipy[postgres,sqlalchemy-async]"
Skip this for Redis/Kafka/other logics that do not wrap a SQLAlchemy session.
Generate
logics/<domain>/
└── <name>_logic.py
Stub shape:
- Google-style class/method docstrings; double quotes;
X | Ytyping. - Constructor injects the domain repository (or port) — do not construct adapters.
- Public method: domain
*InputDTOin → domain*OutputDTOout. - Decorate with
postgres_sqlalchemy_atomic(it detectsasync defitself, so one name serves sync and async logics) when Postgres SQLAlchemy is in play. Otherwise omit the UoW decorator.
from archipy.adapters.base.sqlalchemy.atomic import postgres_sqlalchemy_atomic
class UserRegistrationLogic:
"""Handles user registration within a single database transaction."""
def __init__(self, user_repository: UserRepository) -> None:
self._user_repository = user_repository
@postgres_sqlalchemy_atomic
def register_user(self, input_dto: UserRegistrationInputDTO) -> UserRegistrationOutputDTO:
"""Validate and create a user.
Args:
input_dto: Registration data from the service layer.
Returns:
Output DTO for the newly created user.
"""
...
If domain DTOs or errors are missing, follow ../scaffold-models/SKILL.md — do not invent naming.
Do not
- No FastAPI / gRPC imports.
- May call other domain logics; never another domain’s repository.
- No atomic / UoW decorators on repositories or services — only logics.
- Wire via DI in
configs/containers.py. - No FastAPI / gRPC imports in logics.
Verify
- Run the repository's formatter and linter on generated Python.
- Add or run Behave scenarios through the service endpoint that calls this logic (success, business-rule failure,
rollback), with its
@needs-*containers; if no endpoint exists yet, note that the scenario lands with the service. - Confirm DTO boundaries, repository injection, decorator choice, and DI wiring.
- Run the
archipy-reviewersubagent on the changes and fix every Must fix finding it reports. - Report files 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-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".
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-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".