Skip to content
Skills Library
Programming · Building & coding

clean-arch-data

/clean-arch-data

Use when creating or editing the data layer of a Flutter feature (features/<feature>/data): DTOs, mappers, remote/local data sources, repository implementations, caching, and converting exceptions to failures.

Licence
MIT
Last repository change
31.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 31.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use when creating or editing the data layer of a Flutter feature (features/<feature>/data): DTOs, mappers, remote/local data sources, repository implementations, caching, and converting exceptions to failures.

Original author description

Use when creating or editing the data layer of a Flutter feature (features/<feature>/data): DTOs, mappers, remote/local data sources, repository implementations, caching, and converting exceptions to failures.

How it works

  1. Contents
  2. Hard rules
  3. DTOs
  4. Mappers
  5. Data sources
  6. Repository implementation
  7. Error mapping
  8. Mock implementation
  9. Checklist before finishing
  10. Bundled files
Original SKILL.md headings · 87 lines, 543 words
SKILL.md preview
---
name: clean-arch-data
description: Use when creating or editing the data layer of a Flutter feature (features/<feature>/data): DTOs, mappers, remote/local data sources, repository implementations, caching, and converting exceptions to failures.
---

# Data layer rules

The data layer implements the domain's repository interfaces and owns everything about the outside world: API shape, JSON, storage, caching. A feature has a `data/` layer only when it has a repository (caching, merging sources, complex mapping). A thin feature has none: its cubit calls the API client directly.

## Contents

```
data/
├── dtos/                       # wire/storage models
├── mappers/                    # dto <-> entity
├── sources/                    # remote_*_data_source.dart, local_*_data_source.dart
└── <feature>_repository_impl.dart
```

## Hard rules

- Imports `domain` (entities, repository interfaces, failures). Never imports `presentation`.
- **DTOs never leave `data/`.** Repository methods return domain entities.
- All API traffic goes through a **strongly typed API client** in `core/http` (typed requests and responses, for example CQRS-style). Prefer **generated contracts** from the API specification over hand-written ones; hand-written DTOs and mappers are for cases where the generated model does not fit the app.
- Exceptions never leave `data/`. Catch them and return `Failure`.
- No business rules here (limits, eligibility, calculations). That is domain.
- No Flutter widgets or `BuildContext`.

## DTOs

- Named `<Thing>Dto`, mirror the API/storage shape exactly (field names, nullability).
- Use `json_serializable` (`@JsonSerializable`) with generated `fromJson`/`toJson`. No hand-written parsing unless unavoidable.
- Immutable, `final` fields.

## Mappers

- Extension methods or small classes: `extension AccountDtoX on AccountDto { Account toEntity() => ... }` and `Account.toDto()` where writes are needed.
- All parsing of formats (dates, money strings, enums from strings) happens here. Unknown enum values map to a safe default or a failure, never a crash.
- Pure functions, unit-tested with round trips.

## Data sources

- Remote source: wraps the HTTP/API client. Returns DTOs, throws typed `ApiException`s.
- Local source: wraps storage (`SharedPreferences`, secure storage, DB) using typed keys. Returns DTOs or primitives.
- Use sources when you cache or support offline. For a trivial single-call repository you may call the client directly; stay consistent within the feature.
- Depend on `core` abstractions (`HttpClient`, `KeyValueStorage`), not on a concrete plugin type scattered through code.

## Repository implementation

- `class <Feature>RepositoryImpl implements <Feature>Repository`.
- Receives sources through the constructor.
- Responsibilities: choose source (cache vs network), map DTO to entity, map exceptions to `Failure`.

```dart
class AccountsRepositoryImpl implements AccountsRepository {
  AccountsRepositoryImpl(this._remote);
  final RemoteAccountsDataSource _remote;

  @override
  Future<Result<List<Account>>> getAccounts() async {
    try {
      final dtos = await _remote.fetchAccounts();
      return Success(dtos.map((d) => d.toEntity()).toList());
    } on ApiException catch (e) {
      return Failure(e.toFailure());
    }
  }
}
```

## Error mapping

- One place (`ApiException.toFailure()` in `core/error`) maps status codes/exceptions to `NetworkFailure`, `UnauthorizedFailure`, `ServerFailure`, etc.
- Only catch what you can map. Do not use bare `catch (e)` that swallows programming errors; let unexpected errors surface to the global error handler/Sentry.
- Log with the shared logger (see `clean-arch-observability`); never `print`. Catch-and-log expected exceptions where you catch them.

## Mock implementation

- Provide `Mock<Feature>Repository implements <Feature>Repository` for dev flavors and demos, returning entities directly. Selected in DI via `AppConfig.useMocks` (see `clean-arch-di-routing`).

## Checklist before finishing

- [ ] No DTO or exception type appears in any domain or presentation signature
- [ ] Mapper tests cover null/unknown values
- [ ] Repository impl tested with fake sources, covering success and each failure branch
- [ ] No business rule inside data

## Bundled files

- `references/error-mapping.md`: exception to failure table, `toFailure()`, caching pattern
Files in this package (2)
  • SKILL.md 4 KB
  • references/error-mapping.md 2 KB

Versions

The database has no other skills named clean-arch-data.

Database snapshot: 13.11.2026 · package version 183b1503292d (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100clean-arch-domain
    Use when creating or editing the domain layer of a Flutter feature (features/<feature>/domain): entities, abstract repository interfaces, use cases, domain failures. Rules for what belongs in domain, naming, and what it must never import.
  • 100clean-arch-new-feature
    Use when asked to add a new feature, screen, or flow to a Flutter app using Clean Architecture with Bloc/Cubit. Chooses the feature shape (thin, with repository, full domain), then gives the ordered workflow across domain, data, presentation, UI, forms, analytics, DI/routing and…
  • 100uw-analyze-service
    Use when analyzing business logic, use cases, service orchestration, and data transformation including DTOs and mappers
  • 100flutter-clean-arch
    Flutter Clean Architecture skill for building scalable mobile apps. Use when creating new Flutter projects, implementing BLoC pattern, setting up Dio networking, or following clean architecture patterns with model_view/views structure.
  • 100flutter-clean-arch
    Use when creating or auditing the layers of a Flutter feature or package - where a use case, repository, datasource, entity or model belongs; whether domain may import Flutter; whether a dependency between layers is inverted. Triggers on "where does this go?" in a feature, or a…
  • 100ffca-feature
    Scaffold and extend FFCA features: the three-package domain, data, and presentation structure, models, repositories, Commands and Queries, DTOs, mappers, Cubits, and Modules. Use in an FFCA monorepo, a features/ folder whose packages are named {feature}_domain, {feature}_data,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.