/swe-guidelines:arch-scaffold-entityfrom swe-guidelines
Scaffolds a full-stack entity (frozen type, Postgres table with migration and RLS policy, in-memory storage, manager, wire types, routes, portal screen, tests) into an existing object-model namespace. Python and TypeScript.
Ships in swe-guidelines. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A path that starts with ../ is read from this skill's folder
as realpath resolves it.
Conventions: ../_shared/scaffold-conventions.md.
Sections of ../../architecture.md: Naming
Entities (Identifiers), The Business Layer (Shape of an Operation), The
Storage Layer (Namespace Shape, Defining ORM Classes, Translation, A
Storage Impl, Database Roles, The Second Fence, Migrations), The Network
Layer (Service Interfaces and Impls, Public Types, Realtime at the
Edge), Documentation as Code (A README at Every Level), Cross-Cutting
Conventions (Exceptions). A section is read with its own introduction.
<namespace> <EntityName> [field:type ...] [--role core|activity|queue|admin] [--scope system|org|identity|both] [--person-column <col>] [--no-api]
Example: inventory Warehouse address:str timezone:str. The role
defaults to core, the scope to org. Ask in one message for the
fields not given and their types, and for the list below; with no one
to answer, decide them as the conventions' step 4 says:
Named? Trackable? SoftDeletable? A mixin is
composed only when an operation exercises it: Trackable needs an
update, SoftDeletable a delete. "Append-only" means neither: the
record is Identifiable and carries its time in a field of its own,
created_at or a name of its own like the change event's produced_at
(om/src/<name>/om/change_events/types/change_event.py), never read out of its id.
Unless --role says otherwise, its role is activity;Trackable entity matter. When they
do, the entity carries a version;The shape of each file is its sibling for the File entity of the
media namespace, unless the row names another.
| File | Holds |
|---|---|
om/src/<name>/om/<ns>/types/<entity>.py | the frozen entity, mixins in house-style order, MANAGER_OWNED_FIELDS (with version in it on a versioned entity) |
om/src/<name>/om/<ns>/storage/tables/<entities>.py | the table over the matching mixins; the sibling by scope is below |
om/migrations/sql/<role>/<stamp>_<entities>.up.sql, .down.sql | the table with its mixin header first, then its policy with ENABLE and FORCE ROW LEVEL SECURITY; the down drops the policy and the table |
om/migrations/versions/<role>/<stamp>_<entities>.py | revision = "<stamp>", down_revision the role's current head, run_sql(DatabaseRole.<ROLE>, ...) |
om/tests/contracts/<entity>_storage.py | the storage contract cases, their CROSS_TENANT_CASES set, and INTERFACE, the storage interface they cover, shape om/tests/contracts/media_storage.py |
om/tests/unit/test_<entity>_storage.py, om/tests/integration/test_<entity>_storage_postgres.py | those cases over memory, and over Postgres under the integration marker |
om/tests/unit/test_<entity>_manager.py | every operation over the memory storage |
services/api/tests/test_<ns>_<entity>_api.py (unless --no-api) | the routes over the in-process app, shape services/api/tests/test_media_api.py |
apps/portal/src/features/<entities>/ (when a portal exists and unless --no-api) | <Entities>Page.tsx, use<Entities>Vm.ts, <entities>Model.ts, and its test, shape apps/portal/src/features/settings/ |
<stamp> is the minute the migration is written, YYYYMMDDHHMM. The
table's sibling by scope, with its policy in its role's first migration:
| Scope | Sibling | The policy |
|---|---|---|
org | media/storage/tables/files.py | on org_id, with the system login's clause |
both | tenancy/storage/tables/api_keys.py | on org_id, narrowed by the person column, user_id unless --person-column names another |
system | tenancy/storage/tables/identities.py | none: no row-level security, and every storage method is declared @tenantless |
identity | none; ScopeKind.IDENTITY in storage/scopes.py | on the identity column against app.identity_id; every storage method takes identity_id in place of org_id and is declared @tenantless |
| File | Change |
|---|---|
om/src/<name>/om/<ns>/storage/__init__.py, impl/postgres.py, impl/memory.py | the storage operations of the conventions' Names, each with its tenant first by the scope, and purge_tenant(org_id, limit) when the namespace gains its first table, which deletes at most limit of the tenant's rows from each table the namespace holds, the new one included, as the leases storage's does over its three |
om/src/<name>/om/<ns>/manager.py, impl/manager.py | the manager operations, or, when the manager delegates the entity's duty, those operations in the delegate's <duty>.py and impl/<duty>.py; and purge_tenant(ctx) over the storage's, always on the manager itself, which the maintenance worker calls, its batch from the namespace's options, as OrchestrationsOptions carries it |
om/src/<name>/om/root.py, workers/maintenance/src/<name>/workers/maintenance/container.py (first table) | the namespace's options taken by build_managers, and the worker's purge batch passed in them, as orchestrations_options is |
om/src/<name>/om/storage/roles.py, scopes.py | the table in TABLE_ROLES and in TABLE_SCOPES |
om/src/<name>/om/<ns>/README.md, om/README.md | the noun, what can happen to it, the rules that hold; in om/README.md, the noun in a paragraph of its own, linked to the namespace's README where it is first named, as the file is |
om/src/<name>/om/exceptions.py (when a leaf is needed) | <Ns>Exception(OmException) once, then leaves that multiply-inherit a shape (NotFound, Conflict) |
workers/maintenance/src/<name>/workers/maintenance/main.py | the namespace in purges, and, for a SoftDeletable entity, its purge past retention in across, as media is |
services/api/src/<name>/services/api/types/<ns>.py, services/<ns>.py, services/impl/<ns>.py, routers/<ns>.py (unless --no-api) | the views and requests, the service interface, its impl, and the routes, shape media: every route tagged <ns>, and the module's docstring the routes by area. An operator route goes in the module's operator router under /admin, as routers/work.py holds, and calls the namespace's own service, so the admin service stays as it is; the operation is the namespace's manager's, which requires OperatorPermission.READ or WRITE of the OperatorContext and reads the org the route names through the tenancy operator manager's get_org, NotFound for an org that is not there |
services/api/src/<name>/services/api/services/__init__.py, services/impl/root.py, gateway/resolve.py (when <ns> is new to the API) | the service interface's name in the __all__ += list and its getter on the root, each below its marker, its impl built over the managers, and its <Ns>Service alias |
services/api/src/<name>/services/api/routers/__init__.py (when <ns> is new to the API, or its operator router is) | the namespace's entry in HOSTED, naming each router routers/<ns>.py holds: its router, and its operator beside it |
clients/typescript/src/types/<ns>.ts, src/index.ts (with the portal screen) | the facade type, which the screen names as <ns>.<Name>; a new module's export type * as <ns> line, in order |
apps/portal/src/queries/keys.ts, queries/<ns>.ts, app/routes.tsx, realtime/router.ts, realtime/router.test.ts (with the portal screen) | a key whose first element is <entity>, the query hooks, the route, and, only when the entity pushes (its writes carry an outbox row, as a core-role entity's do and an activity-role entity's never do), <entity> in PUSHED_ENTITIES and its kinds in SERVER_KINDS |
apps/portal/src/app/AppNav.tsx or features/home/HomePage.tsx (with the portal screen) | a link to the new screen, where the portal links its screens |
org_id declares its compound indexes and sets
__org_id_index__ = False, as files.py does; a feed's is
(org_id, id). A unique key on a
SoftDeletable entity is a partial unique index
WHERE deleted_at IS NULL, and the memory impl refuses a duplicate
only among the living rows.bool, False when the id is already written. With
a second unique key it returns InsertOutcome instead, as
create_item in om/src/<name>/om/work/storage/ does. The manager
reads the row back by the key that collided, and returns it only when
its id is the id the create carried: a retry. A row under another id
holds a business key another request took, and the create raises the
namespace's leaf of Conflict (409), <Entity><Key>Taken. The work
manager returns the row on either, since its second key is an
idempotency key, which only a retry repeats.Permission.READ, writes
Permission.WRITE. A core-role write carries
outbox_row(ctx, "<ns>.<entity>.<created|updated|deleted>", <entity>.id, {}),
and a second row when work follows. A versioned entity's row is
versioned_row(ctx, <kind>, <entity>.id, <entity>.version) instead,
with the version the write left, so the push carries it, as
om/src/<name>/om/orchestrations/steps.py writes it. An activity-role entity is
appended by append_<entity> and carries no outbox row. A list is a
page, after and a clamped limit, like get_files. A get or a
list leaves out a soft-deleted row, in both impls.expected_version. The copy sets version to the expected
version plus one, and a mismatch raises PreconditionFailed (412).
At the edge, the get answers the version as a strong ETag,
"<version>", set by a response type of types/<ns>.py that the
service impl returns: a subclass of FastAPI's JSONResponse whose
constructor takes the view, renders its model_dump(mode="json") as
the body, and sets the header; the route declares the view as its
response_model and returns the response as it is, never setting a
header itself. The PATCH takes the expected version from If-Match
or the body's expected_version, and refuses a request with neither,
or with both and different, as ValidationFailed. The service impl
passes the caller's version through and never fills it from the row
it read, which would make the compare-and-set last writer wins.get_<entity>, copies the request's set
fields onto it (an absent field unchanged, an explicit null cleared
where the field is optional), and hands the whole entity to
update_<entity>. The create builds the entity with the id the
Idem dependency minted. delete_<entity> is a soft delete; the
hard delete is the sweep's purge, never a route's.both, another identity's for identity); for each unique key,
a second row refused by both impls; for a named atomic method, two
callers at once of which exactly one wins, over memory and over
Postgres; an update sent with another created_by, a cleared
deleted_at, or another value of a manager-owned field, which leaves
each as stored; on a versioned entity, a stale version refused and the
row left as it stood, and 412 at the edge; and the other tenant
naming this tenant's row on every route that takes one, answered as
an id that never existed. The row-level security test reads the scope
map, so it holds the new table once its scope is declared.make openapi, so the TypeScript and the Python
clients carry them, then the screen. A namespace new to the API gets
its own document and generated files, each a new file to commit.As ../_shared/scaffold-conventions.md states.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
22 skills in this plugin
/arch-benchmarkRun a benchmark scenario (a skill, a command, or a question) in a declared runtime and have frontier models score it against the rubric. Use to measure a change to a skill or the text./arch-benchmark-browserRun the benchmark prompt in the chatgpt.com, claude.ai, gemini.google.com, and grok.com products, signed in, and save each answer with its conversation URL as proof; in a checkout of this repository, also check the run in, redacted, with its row./arch-deviateRecord a deliberate deviation from the guideline as an ADR under docs/adr/: the rule quoted, the decision, the consequences. Use when a finding is accepted as intentional.npx claudepluginhub baristaze/swe_guidelines --plugin swe-guidelinesOther plugins' skills for the same job