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".
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- scaffold-models
- description
- 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".
03 SKILL.md 正文
Scaffold ArchiPy Models
Scope
Only models/. Do not create repositories, logics, services, or helpers here.
Read first
Read these plugin rules in full before generating files (paths relative to this skill directory; Claude Code: ${CLAUDE_SKILL_DIR}/../../rules/):
../../rules/using-archipy-models.mdc../../rules/architecture-for-apps.mdc../../rules/using-archipy-utils.mdc
Before writing files
- Inspect existing
models/(DTOs, errors, entities, types), neighboring domains, and the installed ArchiPy version. - Infer domain name, DTO naming, and error grouping from existing modules.
- Ask only for unresolved domain / operation names.
- Preserve existing model modules; do not overwrite.
Generate
models/
├── dtos/<domain>/
│ ├── domain/v{n}/
│ │ ├── <op>_input_dto.py
│ │ └── <op>_output_dto.py
│ └── repository/
│ ├── <action>_command_dto.py
│ └── <action>_query_dto.py
├── errors/
│ └── <domain>_errors.py
├── entities/ # optional
│ └── <domain>_entity.py
└── types/ # optional
└── <domain>_types.py
Naming: *InputDTO / *OutputDTO for domain (versioned under domain/v{n}/); *CommandDTO / *QueryDTO /
*ResponseDTO for repository (never versioned). Any repository method with two or more parameters takes a single
*CommandDTO (write) / *QueryDTO (read) instead of positional arguments. Entities/DTOs for JWT-authenticated writes carry an explicit actor_uuid that fills created_by*/updated_by*
(actor from current_actor/act first, token user_id/sub second; never a path owner uuid).
Prefer ArchiPy BaseDTO and the exported BaseError hierarchy.
Verify imports against the app's installed ArchiPy version before writing.
Example shapes (order → rename):
# models/dtos/order/domain/v1/order_create_input_dto.py
from pydantic import Field, PositiveInt
from archipy.models.dtos.base_dtos import BaseDTO
class OrderCreateInputDTO(BaseDTO):
"""Domain input crossing the service → logic boundary."""
customer_id: str = Field(min_length=1)
sku: str = Field(min_length=1)
quantity: PositiveInt
# models/dtos/order/domain/v1/order_create_output_dto.py
from archipy.models.dtos.base_dtos import BaseDTO
class OrderCreateOutputDTO(BaseDTO):
"""Domain output returned to the service layer."""
order_id: str
status: str
# models/dtos/order/repository/order_create_command_dto.py
from pydantic import PositiveInt
from archipy.models.dtos.base_dtos import BaseDTO
class OrderCreateCommandDTO(BaseDTO):
"""Repository write command — mapped from domain input inside the logic."""
customer_id: str
sku: str
quantity: PositiveInt
# models/errors/order_errors.py
from archipy.models.errors import InvalidArgumentError, NotFoundError
class OrderNotFoundError(NotFoundError):
"""Raised when an order cannot be located."""
class OrderInvalidArgumentError(InvalidArgumentError):
"""Raised when order input fails domain validation."""
Prefer Pydantic's constrained types over int = Field(gt=0) / bare str: PositiveInt, NonNegativeInt,
NonNegativeFloat, SecretStr (tokens, passwords, API keys — never log or serialize the raw value), HttpUrl,
EmailStr, UUID4, StringConstraints, and the specific date/time types: NaiveDatetime (default for
timestamps; no timezone-aware fields), PastDatetime, FutureDatetime, PastDate, FutureDate — never bare datetime / date
when a stricter type fits. Reach for pydantic-extra-types (PhoneNumber,
Country, Currency, Coordinate, …) before hand-rolled validators; add it to the app's dependencies first. Read raw
secrets only at the boundary with .get_secret_value(). Reference: https://docs.pydantic.dev/latest/api/types/
Make DTOs reject invalid states at construction so downstream code and tests only see valid inputs: use
@field_validator for single-field rules and @model_validator(mode="after") for cross-field rules (ranges,
exactly-one-of, conditionally required fields). Prefer a type over a validator, and a discriminated union /
Literal / StrEnum over optional fields plus runtime ifs. Validators are pure (no I/O; uniqueness and existence
checks stay in logics). Cover each validator with one invalid example at the DTO boundary.
For gRPC payloads extend BaseProtobufDTO instead of BaseDTO and set _proto_class. Unset proto3 scalars arrive
as "" / 0, so constrain them (PositiveInt, StringConstraints(min_length=1)); to_proto masks SecretStr, so
keep secrets out of response DTOs.
BaseDTO is frozen — do not mutate instances after validation. Prefer existing ArchiPy errors over near-duplicates.
Export public app errors from models/errors/__init__.py when other layers consume them. Use the ArchiPy
pagination / sort / search DTOs before inventing page or cursor shapes: PaginationDTO, SortDTO, SearchInputDTO for
inputs, and SearchOutputDTO (total from execute_search_query, adds total_count_estimated) or ExactSearchOutputDTO
(total counted by the repository) for outputs — never hand-write total_count, page, page_size or offset.
Page depth comes from PAGINATION__MAX_ITEMS; do not hard-code a page limit.
Do not
- Data structures only — no I/O, no business rules, no adapters, no DB sessions, no HTTP/gRPC types.
- Never import repositories, logics, or services from models.
- Do not version repository DTOs.
- Double quotes, Google-style docstrings, Python 3.14+ typing.
- No I/O, business rules, adapters, DB sessions, or HTTP/gRPC types in models.
- Do not mutate frozen
BaseDTOinstances after validation.
Verify
- Run the repository's formatter and linter on generated Python.
- Confirm DTO naming, versioned domain vs unversioned repository layout, and error subclassing.
- Import the new modules without constructing infrastructure.
- Run the
archipy-reviewersubagent on the changes and fix every Must fix finding it reports. - Report files and commands run.
Docs
- https://syntaxarc.github.io/ArchiPy/getting-started/project_structure/
- https://syntaxarc.github.io/ArchiPy/tutorials/error_handling/
- Bundled:
../archipy-docs/reference.md(DTO naming)
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-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".