create-dto
Skill0 starsChanged 56 days agoMITView on GitHub
Create a freezed + json_serializable DTO in packages/api — file location under the owning resource provider, sealed class shape, barrel exports, nullable and default handling, enums, and paginated list responses. Use when adding or changing any *_dto.dart or wiring a new API response type.
In this repository18 other files it gives its agents.
- payload/AGENTS.mdAGENTS.md
- add-design-tokenSkill
- add-localizationSkill
- add-platform-channelSkill
- add-routeSkill
- create-adrSkill
- create-api-providerSkill
- create-ds-componentSkill
- create-featureSkill
- create-pageSkill
- create-storeSkill
- create-use-caseSkill
- handle-errorsSkill
- plan-featureSkill
- qa-featureSkill
- triage-bug-reportSkill
- write-maestro-flowSkill
- write-testsSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 60
Do not put computed values, formatting, or presentation logic in a DTO.
- Very specific: line 90
Create {name}_dto.dart under the resource's models/src/.
- Very specific: line 91
Add it to models/src/models.dart.
- Very specific: line 94
Never edit *.freezed.dart or *.g.dart.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Create a DTO
Governed by ADR-0011. DTOs live in packages/api, never in lib/.
Location
DTOs are owned by the resource provider that returns them:
packages/api/lib/src/providers/{resource}_provider/
{resource}_api_provider.dart
{resource}_provider.dart barrel: exports models + provider
models/
models.dart export 'src/models.dart';
src/
models.dart export every dto in this dir
{name}_dto.dartCross-resource models (ListResponseDto, shared envelopes) go in packages/api/lib/src/models/.
Naming: {name}_dto.dart for responses, {name}_request_dto.dart for request bodies.
Shape
import 'package:freezed_annotation/freezed_annotation.dart';
part 'todo_dto.freezed.dart';
part 'todo_dto.g.dart';
@freezed
sealed class TodoDto with _$TodoDto {
factory TodoDto({
required String id,
required String title,
required bool completed,
}) = _TodoDto;
factory TodoDto.fromJson(Map<String, dynamic> json) =>
_$TodoDtoFromJson(json);
}@freezed sealed class— the repo's freezed 3.x convention.- Both
partdirectives, in this order. fromJsonfactory always present, even on request-only DTOs (cheap, and mock interceptors need it).build.yamlsetsexplicit_to_json: trueandany_map: trueglobally — nested DTOs serialise correctly andMap<dynamic, dynamic>payloads parse. Do not re-declare these per class.
Fields
requiredonly when the server always sends it. Arequiredfield on an optional key throws at parse time on a payload you did not anticipate — a crash instead of a degraded screen.- Optional → nullable (
String? avatarUrl) or defaulted (@Default(false) bool completed). Prefer a default when the absence has an obvious meaning; prefer nullable when "absent" and "false" differ. - Name mismatch →
@JsonKey(name: 'created_at') required DateTime createdAt. - Do not put computed values, formatting, or presentation logic in a DTO. Map to a feature model in
lib/features/{feature}/models/if the UI needs a different shape.
Enums
Annotate the values so an unknown server value does not crash the parse:
@JsonEnum(alwaysCreate: true)
enum TodoStatus {
@JsonValue('open') open,
@JsonValue('done') done,
@JsonValue('archived') archived,
}Where the server may add values, keep an unknown member and use @JsonKey(unknownEnumValue: TodoStatus.unknown) on the field.
Paginated lists
Endpoints returning a page use the shared envelope rather than a bespoke wrapper:
@GET(_Paths.getTodos)
Future<ListResponseDto<TodoDto>> getTodos(@Query('page') int page);See packages/api/lib/src/models/list_response_entity/. A single-resource endpoint returns the DTO directly — no envelope.
Wire it up
- Create
{name}_dto.dartunder the resource'smodels/src/. - Add it to
models/src/models.dart. - Confirm
{resource}_provider.dartexportsmodels/models.dart, andlib/api.dartexports the provider barrel. melos run build(ormelos exec --scope api -- "dart run build_runner build -d").- Never edit
*.freezed.dartor*.g.dart.
Checklist
- Under the owning resource's
models/src/, named*_dto.dart @freezed sealed class, bothpartdirectives,fromJsonfactoryrequiredonly for fields the server always sends; others nullable or defaulted- Enums use
@JsonValue, with an unknown fallback where the server may extend - Exported through
models/src/models.dart→{resource}_provider.dart→lib/api.dart melos run buildrun; generated files untouched- A round-trip
fromJson/toJsontest exists for any non-trivial mapping
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

