Django Domain Delivery
Overview
Django Domain Delivery keeps Django and DRF changes inside clear framework
boundaries: models/managers own persistence shape, services or forms own domain
rules, serializers own API contracts, viewsets own request orchestration, tasks
own async side effects, and migrations own reversible schema evolution. It is
for shipping one safe Django slice with tests, query discipline, auth checks,
observability, and rollback evidence.
When to Use
Use for Django models, managers, querysets, ModelForms, CBVs, DRF serializers,
viewsets, permissions, migrations, transactions, Celery/async jobs, admin
behavior, API tests, deployment checks, or rollback planning.
Expert Operating Standard
Follow <resolved-supervibe-plugin-root>/docs/references/skill-expert-operating-standard.md: read local source
first, preserve evidence, keep scope narrow, verify before completion claims,
and lower confidence when migrations, query counts, auth paths, or rollback are
not proven.
Step 0 - Read source of truth
- Read the user request,
AGENTS.md, task graph item, and owned write set.
- Inspect
manage.py, settings, installed apps, app layout, migrations,
serializers, viewsets, permissions, factories, and nearest pytest or Django
test cases.
- Search for existing transaction, manager, queryset, serializer, permission,
Celery, logging, and deployment patterns before adding new ones.
- Use CodeGraph for unfamiliar apps and CodeGraph or symbol search before
changing model fields, public serializers, URLs, task signatures, or shared
querysets.
When not to use
- Do not use for non-Django Python work unless the change enters through a
Django app, ORM model, DRF API, or Django-managed job.
- Do not choose app boundaries, Celery topology, API versioning policy, or auth
architecture when a narrower implementation decision is enough; hand off to
the relevant architect or specialist.
- Do not perform broad migrations or serializer rewrites without a scoped plan.
Decision tree
Schema changes? -> migration up/down, data compatibility, deploy order, rollback.
API payload changes? -> serializer contract, viewset action, permission, schema/test.
Business rule changes? -> form/service/model method, not hidden in view or serializer save.
Query traverses relations? -> select_related/prefetch_related/query count test.
Multiple writes must be atomic? -> transaction.atomic around one unit of work + rollback test.
Side effect can outlive request? -> Celery/task boundary, idempotency key, retry policy.
Auth-sensitive path? -> permission class, object permission, ownership test, audit log.
Procedure
Define the slice: app, entry point, input, output, old behavior preserved,
verification command, deploy concern, and rollback path.
Map boundaries. Keep request orchestration in views/viewsets, API shape in
serializers, domain validation in forms/services/model methods, persistence
in managers/querysets, and side effects in tasks or explicit service calls.
Shape ORM access. Use existing managers/querysets, add select_related or
prefetch_related only for proven traversal, avoid wildcard prefetch, and
add query-count or regression tests where the project supports them.
Design migrations. Add reversible schema migrations, separate data migrations
from risky deploys when needed, keep nullable/backfill/constraint sequencing
compatible with rolling deploys, and document rollback for irreversible data
choices.
Apply transaction rules. Use transaction.atomic() around one business unit,
avoid network calls inside transactions, and test rollback on validation,
permission, and repository failure paths.
Implement DRF contracts deliberately. Serializer fields are explicit, writes
use validated_data, viewsets choose the smallest action, permissions cover
object ownership, and schema impacts are tested or documented.
Isolate async/job work. Task arguments are IDs or primitive snapshots, tasks
are idempotent, retries are bounded, and request code records enqueue
failure instead of silently losing work.
Add observability. Use existing logging/metrics/tracing for request IDs,
model identifiers, permission denials, task retry/drop decisions, migration
risk, and external side effects without logging secrets.
Write focused tests first when behavior changes. Cover success, validation
failure, auth/permission denial, object-level access, transaction rollback,
query budget, serializer contract, migration behavior, and async retry or
idempotency when relevant.
Verify with the active scoped command, such as pytest <app>/tests/...,
python manage.py test <app>, python manage.py check, migration up/down
checks, or schema generation checks. If policy defers commands, record the
exact final gate and non-test evidence.
Repair loop: on failure, localize to serializer/viewset/service/query/task
boundary, fix the smallest cause, rerun the same command, and stop with a
blocker if the repair requires app-boundary, auth, API-version, or deploy
strategy approval.
Read the source artifact, owned file paths, graph/task scope, and current project convention; record the evidence path, command, receipt, or runtime state that proves the starting point.
If required source, owner, dependency, runtime boundary, or approval is missing, stop and return BLOCKED with the missing field, impacted artifact, and next action instead of guessing.
After edits or reviewer findings, repair the smallest changed slice, rerun the same scoped command, and record command, exit code, pass/fail status, artifact path, confidence, and remaining blocker before completion.
Worked example
Add a DRF endpoint to approve an invoice:
- Viewset action checks authentication and object permission, then calls
approve_invoice(user, invoice_id).
- Service loads the invoice with
select_related("account"), verifies account
ownership, wraps status update and audit row in transaction.atomic(), and
enqueues a task after commit.
- Serializer exposes explicit response fields and never uses
fields = "__all__".
- Tests cover approve success, wrong account 403, already-approved 409,
transaction rollback on audit failure, query count, and task idempotency.
Good and bad delivery paths
Good delivery path: deliver through DRF viewset action, explicit serializer,
permission class, service boundary, queryset/manager access,
transaction.atomic, post-commit task enqueue, and audit row. Runtime-specific
tests include DRF API auth and object-permission tests, serializer errors,
query-count assertions, transaction rollback on audit or enqueue failure,
Celery retry/idempotency, and migration up/down where schema changes. Rollback
removes or flags the route/action and uses compatible migration revert or
unused nullable fields until cleanup. Failure boundaries are wrong account,
already-approved state, serializer validation, query explosion, task enqueue
failure, migration incompatibility, and partial audit write.
Bad unsafe path: hide approval rules in serializer.save or the viewset, use
fields-all serializers, enqueue before commit, and verify only the happy API
path. That path has no runtime-specific tests for the changed stack surface,
no concrete rollback beyond hope or manual cleanup, and weak failure
boundaries for wrong account, already-approved state, serializer validation,
query explosion, task enqueue failure, migration incompatibility, and partial
audit write.
Common rationalizations
- "The serializer can do the business rule" fails when the same rule is needed
from admin, task, management command, or service code.
- "This query is small" fails when list endpoints or nested serializers can
turn one fixture into an N+1 production incident.
- "A data migration is one-way anyway" fails unless rollback, backup, or
release waiver is explicit.
Red flags
fields = "__all__" on externally consumed serializers.
- Viewset action mutates multiple models without
transaction.atomic().
- Permission tests cover authentication but not object ownership.
- Celery task accepts a full model dict or performs non-idempotent external
calls without retry/drop policy.
- Migration changes a non-null field on a populated table without deploy order
or backfill evidence.
Checklist
- ORM/query boundary and query-budget risk are handled.
- Migrations are reversible or the irreversible decision is documented.
- Serializer/viewset/permission behavior is explicit and tested.
- Transactions wrap one business unit and exclude slow network calls.
- Async jobs are idempotent and observable.
- Deployment and rollback path are named.
Failure modes
- Nested serializer creates an N+1 list endpoint.
- Permission is checked at list level but not object level.
- Data migration locks a hot table during deploy.
- Task retry duplicates side effects.
- Rollback reverts code but leaves incompatible schema or data.
Output contract
status: PASS, BLOCKED, PARTIAL, or DEFERRED.
slice: app, view/form/task/model behavior changed.
boundaries: model/manager/service/serializer/viewset/task files touched.
queryAndTransactionEvidence: query plan, count, transaction, and rollback
proof or gap.
authAndContractEvidence: serializer fields, permissions, schema/API tests.
tests: exact commands, case list, exit code, or final-gate deferral reason.
deploymentRollback: migration order, feature flag, revert, backup, or
waiver.
confidence: score with any cap from missing migration/auth/query proof.
nextAction: repair, handoff, A026 binding, or final gate.
Guard rails
- Prefer Django and DRF conventions already present in the project.
- Do not hide business logic in signals unless the project already owns that
pattern and tests the side effect.
- Do not log secrets, credentials, tokens, or full sensitive payloads.
- Do not claim production readiness without focused verification or a recorded
final-gate deferral.
Verification
Run the scoped Django/pytest command required by the active graph and rerun it
after repairs.
For migrations, run or document migration up/down, deploy-order, and rollback
evidence.
For DRF endpoints, verify serializer contract, permission denial, object
ownership, and schema generation when the project owns schema output.
For ORM-sensitive changes, include query-count evidence or a stated reason it
is unavailable.
If any scoped check fails or new evidence appears, repair the smallest changed slice, rerun the same scoped command, and record command, exit code, pass/fail status, blockers, and final-gate deferrals before claiming completion.
Supporting references
Use local support files through progressive disclosure; keep the main SKILL.md as the operating contract and load deeper resources only when the active task needs them:
- Read
references/practice-pack.md when django-domain-delivery needs deeper practice guidance, source evidence anchors, risk checks, or a final checklist beyond the core procedure.
- Run
scripts/self-check.mjs --check --json after editing this django-domain-delivery resource tree or before claiming deterministic support-file readiness; use --help for options and --dry-run for read-only preview semantics.
- Use
evals/regression.json when calibrating django-domain-delivery trigger boundaries, happy-path/failure-path coverage, boundary rollback behavior, or resource-tree regressions.
- Open
examples/workflow.md when a concrete django-domain-delivery workflow example is needed for sequencing, evidence selection, or anti-example comparison.
- Use
templates/output-contract.md when emitting django-domain-delivery-report so status, evidence, confidence, blockers, risks, rollback, and nextAction stay consistent.
Related
supervibe:source-driven-development
supervibe:tdd
supervibe:test-strategy
supervibe:auth-flow-design
supervibe:error-envelope-design
supervibe:verification
Source: vTRKA/supervibe — distributed by TomeVault.
1---2name: django-domain-delivery3description: Use WHEN implementing or reviewing Django and DRF service work that touches ORM/query boundaries, migrations, serializers, viewsets, transactions, async jobs, auth/permissions, observability, tests, deployment, or rollback. TO deliver stack-specific production changes with framework-native practices, verification evidence, and rollback discipline.4---56# Django Domain Delivery78## Overview910Django Domain Delivery keeps Django and DRF changes inside clear framework11boundaries: models/managers own persistence shape, services or forms own domain12rules, serializers own API contracts, viewsets own request orchestration, tasks13own async side effects, and migrations own reversible schema evolution. It is14for shipping one safe Django slice with tests, query discipline, auth checks,15observability, and rollback evidence.1617## When to Use1819Use for Django models, managers, querysets, ModelForms, CBVs, DRF serializers,20viewsets, permissions, migrations, transactions, Celery/async jobs, admin21behavior, API tests, deployment checks, or rollback planning.2223## Expert Operating Standard2425Follow `<resolved-supervibe-plugin-root>/docs/references/skill-expert-operating-standard.md`: read local source26first, preserve evidence, keep scope narrow, verify before completion claims,27and lower confidence when migrations, query counts, auth paths, or rollback are28not proven.2930## Step 0 - Read source of truth31321. Read the user request, `AGENTS.md`, task graph item, and owned write set.332. Inspect `manage.py`, settings, installed apps, app layout, migrations,34 serializers, viewsets, permissions, factories, and nearest pytest or Django35 test cases.363. Search for existing transaction, manager, queryset, serializer, permission,37 Celery, logging, and deployment patterns before adding new ones.384. Use CodeGraph for unfamiliar apps and CodeGraph or symbol search before39 changing model fields, public serializers, URLs, task signatures, or shared40 querysets.4142## When not to use4344- Do not use for non-Django Python work unless the change enters through a45 Django app, ORM model, DRF API, or Django-managed job.46- Do not choose app boundaries, Celery topology, API versioning policy, or auth47 architecture when a narrower implementation decision is enough; hand off to48 the relevant architect or specialist.49- Do not perform broad migrations or serializer rewrites without a scoped plan.5051## Decision tree5253```text54Schema changes? -> migration up/down, data compatibility, deploy order, rollback.55API payload changes? -> serializer contract, viewset action, permission, schema/test.56Business rule changes? -> form/service/model method, not hidden in view or serializer save.57Query traverses relations? -> select_related/prefetch_related/query count test.58Multiple writes must be atomic? -> transaction.atomic around one unit of work + rollback test.59Side effect can outlive request? -> Celery/task boundary, idempotency key, retry policy.60Auth-sensitive path? -> permission class, object permission, ownership test, audit log.61```6263## Procedure64651. Define the slice: app, entry point, input, output, old behavior preserved,66 verification command, deploy concern, and rollback path.672. Map boundaries. Keep request orchestration in views/viewsets, API shape in68 serializers, domain validation in forms/services/model methods, persistence69 in managers/querysets, and side effects in tasks or explicit service calls.703. Shape ORM access. Use existing managers/querysets, add `select_related` or71 `prefetch_related` only for proven traversal, avoid wildcard prefetch, and72 add query-count or regression tests where the project supports them.734. Design migrations. Add reversible schema migrations, separate data migrations74 from risky deploys when needed, keep nullable/backfill/constraint sequencing75 compatible with rolling deploys, and document rollback for irreversible data76 choices.775. Apply transaction rules. Use `transaction.atomic()` around one business unit,78 avoid network calls inside transactions, and test rollback on validation,79 permission, and repository failure paths.806. Implement DRF contracts deliberately. Serializer fields are explicit, writes81 use `validated_data`, viewsets choose the smallest action, permissions cover82 object ownership, and schema impacts are tested or documented.837. Isolate async/job work. Task arguments are IDs or primitive snapshots, tasks84 are idempotent, retries are bounded, and request code records enqueue85 failure instead of silently losing work.868. Add observability. Use existing logging/metrics/tracing for request IDs,87 model identifiers, permission denials, task retry/drop decisions, migration88 risk, and external side effects without logging secrets.899. Write focused tests first when behavior changes. Cover success, validation90 failure, auth/permission denial, object-level access, transaction rollback,91 query budget, serializer contract, migration behavior, and async retry or92 idempotency when relevant.9310. Verify with the active scoped command, such as `pytest <app>/tests/...`,94 `python manage.py test <app>`, `python manage.py check`, migration up/down95 checks, or schema generation checks. If policy defers commands, record the96 exact final gate and non-test evidence.9711. Repair loop: on failure, localize to serializer/viewset/service/query/task98 boundary, fix the smallest cause, rerun the same command, and stop with a99 blocker if the repair requires app-boundary, auth, API-version, or deploy100 strategy approval.1011021. Read the source artifact, owned file paths, graph/task scope, and current project convention; record the evidence path, command, receipt, or runtime state that proves the starting point.1032. If required source, owner, dependency, runtime boundary, or approval is missing, stop and return BLOCKED with the missing field, impacted artifact, and next action instead of guessing.1043. After edits or reviewer findings, repair the smallest changed slice, rerun the same scoped command, and record command, exit code, pass/fail status, artifact path, confidence, and remaining blocker before completion.105106## Worked example107108Add a DRF endpoint to approve an invoice:1091101. Viewset action checks authentication and object permission, then calls111 `approve_invoice(user, invoice_id)`.1122. Service loads the invoice with `select_related("account")`, verifies account113 ownership, wraps status update and audit row in `transaction.atomic()`, and114 enqueues a task after commit.1153. Serializer exposes explicit response fields and never uses `fields = "__all__"`.1164. Tests cover approve success, wrong account 403, already-approved 409,117 transaction rollback on audit failure, query count, and task idempotency.118119## Good and bad delivery paths120121Good delivery path: deliver through DRF viewset action, explicit serializer,122permission class, service boundary, queryset/manager access,123transaction.atomic, post-commit task enqueue, and audit row. Runtime-specific124tests include DRF API auth and object-permission tests, serializer errors,125query-count assertions, transaction rollback on audit or enqueue failure,126Celery retry/idempotency, and migration up/down where schema changes. Rollback127removes or flags the route/action and uses compatible migration revert or128unused nullable fields until cleanup. Failure boundaries are wrong account,129already-approved state, serializer validation, query explosion, task enqueue130failure, migration incompatibility, and partial audit write.131132Bad unsafe path: hide approval rules in serializer.save or the viewset, use133fields-all serializers, enqueue before commit, and verify only the happy API134path. That path has no runtime-specific tests for the changed stack surface,135no concrete rollback beyond hope or manual cleanup, and weak failure136boundaries for wrong account, already-approved state, serializer validation,137query explosion, task enqueue failure, migration incompatibility, and partial138audit write.139140## Common rationalizations141142- "The serializer can do the business rule" fails when the same rule is needed143 from admin, task, management command, or service code.144- "This query is small" fails when list endpoints or nested serializers can145 turn one fixture into an N+1 production incident.146- "A data migration is one-way anyway" fails unless rollback, backup, or147 release waiver is explicit.148149## Red flags150151- `fields = "__all__"` on externally consumed serializers.152- Viewset action mutates multiple models without `transaction.atomic()`.153- Permission tests cover authentication but not object ownership.154- Celery task accepts a full model dict or performs non-idempotent external155 calls without retry/drop policy.156- Migration changes a non-null field on a populated table without deploy order157 or backfill evidence.158159## Checklist160161- ORM/query boundary and query-budget risk are handled.162- Migrations are reversible or the irreversible decision is documented.163- Serializer/viewset/permission behavior is explicit and tested.164- Transactions wrap one business unit and exclude slow network calls.165- Async jobs are idempotent and observable.166- Deployment and rollback path are named.167168## Failure modes169170- Nested serializer creates an N+1 list endpoint.171- Permission is checked at list level but not object level.172- Data migration locks a hot table during deploy.173- Task retry duplicates side effects.174- Rollback reverts code but leaves incompatible schema or data.175176## Output contract177178- `status`: PASS, BLOCKED, PARTIAL, or DEFERRED.179- `slice`: app, view/form/task/model behavior changed.180- `boundaries`: model/manager/service/serializer/viewset/task files touched.181- `queryAndTransactionEvidence`: query plan, count, transaction, and rollback182 proof or gap.183- `authAndContractEvidence`: serializer fields, permissions, schema/API tests.184- `tests`: exact commands, case list, exit code, or final-gate deferral reason.185- `deploymentRollback`: migration order, feature flag, revert, backup, or186 waiver.187- `confidence`: score with any cap from missing migration/auth/query proof.188- `nextAction`: repair, handoff, A026 binding, or final gate.189190## Guard rails191192- Prefer Django and DRF conventions already present in the project.193- Do not hide business logic in signals unless the project already owns that194 pattern and tests the side effect.195- Do not log secrets, credentials, tokens, or full sensitive payloads.196- Do not claim production readiness without focused verification or a recorded197 final-gate deferral.198199## Verification200201- Run the scoped Django/pytest command required by the active graph and rerun it202 after repairs.203- For migrations, run or document migration up/down, deploy-order, and rollback204 evidence.205- For DRF endpoints, verify serializer contract, permission denial, object206 ownership, and schema generation when the project owns schema output.207- For ORM-sensitive changes, include query-count evidence or a stated reason it208 is unavailable.209210- If any scoped check fails or new evidence appears, repair the smallest changed slice, rerun the same scoped command, and record command, exit code, pass/fail status, blockers, and final-gate deferrals before claiming completion.211212## Supporting references213214Use local support files through progressive disclosure; keep the main SKILL.md as the operating contract and load deeper resources only when the active task needs them:215- Read `references/practice-pack.md` when django-domain-delivery needs deeper practice guidance, source evidence anchors, risk checks, or a final checklist beyond the core procedure.216- Run `scripts/self-check.mjs --check --json` after editing this django-domain-delivery resource tree or before claiming deterministic support-file readiness; use `--help` for options and `--dry-run` for read-only preview semantics.217- Use `evals/regression.json` when calibrating django-domain-delivery trigger boundaries, happy-path/failure-path coverage, boundary rollback behavior, or resource-tree regressions.218- Open `examples/workflow.md` when a concrete django-domain-delivery workflow example is needed for sequencing, evidence selection, or anti-example comparison.219- Use `templates/output-contract.md` when emitting django-domain-delivery-report so status, evidence, confidence, blockers, risks, rollback, and nextAction stay consistent.220221## Related222223- `supervibe:source-driven-development`224- `supervibe:tdd`225- `supervibe:test-strategy`226- `supervibe:auth-flow-design`227- `supervibe:error-envelope-design`228- `supervibe:verification`229230---231> Source: [vTRKA/supervibe](https://github.com/vTRKA/supervibe) — distributed by [TomeVault](https://tomevault.io).232<!-- tomevault:4.0:skill_md:2026-06-15 -->