Django DTO Mapper
Implement explicit, testable representation boundaries from the approved API contract.
Required Context
Read AGENTS.md, docs/architecture/api-contract.md, docs/architecture/security-contract.md, docs/architecture/backend-implementation-contract.md, .codex/references/dto-controller-policy.md, .codex/references/mapping-policy.md, and .codex/references/module-documentation.md.
Require an approved implementation contract. Stop if payload fields, nullability, sensitive-field exposure, or mapping ownership are unresolved.
Workflow
- Identify request DTO, Service input, Service result, and response DTO shapes for the use case.
- Implement structural and field-level validation in
dtos/<use_case>.py.
- Implement explicit request-to-input and result-to-response functions in
mappers/<use_case>.py.
- Use allowlists for response and sensitive-field mapping.
- Add meaningful opening module docstrings and trace behavioral mappings to approved contracts or
BR-### rules.
- Add focused DTO and mapper tests for valid, invalid, omitted, nullable, and sensitive fields.
Boundaries
- Do not authorize users or enforce business invariants in DTOs or Mappers.
- Do not import ORM Models, Repositories, QuerySets, HTTP request objects, or Service implementations.
- Do not query, persist, call integrations, or use reflection-based AutoMapper dependencies.
- Keep ORM/record conversion inside
repositories/mappers.py, owned by $django-repository.
Finish only when Controller payloads are DTO-defined, conversions are explicit, sensitive fields are intentional, and tests cover the contract.
1---2name: django-dto-mapper3description: Implement approved Django backend DTOs and explicit representation Mappers. Use when defining Controller request or response payloads, Service inputs or results, structural validation, request-to-Service conversion, result-to-response conversion, or repository-neutral record shapes. Do not use for endpoints, business rules, ORM queries, persistence, or implicit AutoMapper-style mapping.4---56# Django DTO Mapper78Implement explicit, testable representation boundaries from the approved API contract.910## Required Context1112Read `AGENTS.md`, `docs/architecture/api-contract.md`, `docs/architecture/security-contract.md`, `docs/architecture/backend-implementation-contract.md`, `.codex/references/dto-controller-policy.md`, `.codex/references/mapping-policy.md`, and `.codex/references/module-documentation.md`.1314Require an approved implementation contract. Stop if payload fields, nullability, sensitive-field exposure, or mapping ownership are unresolved.1516## Workflow17181. Identify request DTO, Service input, Service result, and response DTO shapes for the use case.192. Implement structural and field-level validation in `dtos/<use_case>.py`.203. Implement explicit request-to-input and result-to-response functions in `mappers/<use_case>.py`.214. Use allowlists for response and sensitive-field mapping.225. Add meaningful opening module docstrings and trace behavioral mappings to approved contracts or `BR-###` rules.236. Add focused DTO and mapper tests for valid, invalid, omitted, nullable, and sensitive fields.2425## Boundaries2627- Do not authorize users or enforce business invariants in DTOs or Mappers.28- Do not import ORM Models, Repositories, QuerySets, HTTP request objects, or Service implementations.29- Do not query, persist, call integrations, or use reflection-based AutoMapper dependencies.30- Keep ORM/record conversion inside `repositories/mappers.py`, owned by `$django-repository`.3132Finish only when Controller payloads are DTO-defined, conversions are explicit, sensitive fields are intentional, and tests cover the contract.