flutter-feature-scaffold
Skill10 starsChanged 42 days agoMITView on GitHub
Use when adding a new feature or module to a Flutter app that follows feature-first Clean Architecture (data / domain / presentation) with Riverpod 3 and no code generation for providers, when deciding which layer or folder a file belongs in, or when reviewing dependency direction between layers. Provides the folder layout, per-layer rules, barrel conventions, build order and a scaffold script.
In this repository5 other files it gives its agents.
- flutter-result-errorsSkill
- flutter-riverpod3Skill
- flutter-sdk-contractsSkill
- flutter-testingSkill
- flutter-ui-side-effectsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 40
Every folder has a barrel named after it (entities.dart, datasources.dart, …) that exports its files.
- Very specific: line 63
If two features need the same model, promote it to core/ instead of reaching into another feature's data/ or presentation/.
- Very specific: line 73
Call chain: Widget → (Async)Notifier → Repository contract → RepositoryImpl → RemoteDataSource → ApiClient.
- Distinctive: line 95
No provider in this file.
- Distinctive: line 194
Run it after every scaffold, and in CI so the boundary cannot erode.
≈ “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
Feature-first Clean Architecture for Flutter
Layout
lib/
├── app/ bootstrap, root widget, environment
├── core/ cross-cutting contracts + adapters (network, analytics,
│ error_tracking, storage, errors, config, logging…)
├── shared/ reusable UI & utils with no business meaning
│ (routing, theme, widgets, extensions)
├── features/ one folder per business capability
└── l10n/
features/<feature>/
├── <feature>.dart barrel: exports domain, di, presentation (NOT data)
├── data/ no Riverpod, no Flutter widgets
│ ├── datasources/ <x>_remote_data_source.dart, <x>_endpoints.dart
│ ├── models/ JSON-aware classes (fromJson / toEntity)
│ └── repositories/ <x>_repository_impl.dart
├── di/
│ └── <feature>_providers.dart dataSource + repository providers
├── domain/
│ ├── entities/ immutable value classes (Equatable)
│ ├── repositories/ abstract interface class contracts
│ ├── services/ pure domain logic spanning entities
│ └── usecases/ only when logic is shared or non-trivial
└── presentation/
├── pages/
├── widgets/ includes <Feature>Listeners (side effects)
├── providers/ Notifier / AsyncNotifier / FutureProvider
└── state/ state classes when a notifier needs more than a valueEvery folder has a barrel named after it (entities.dart,
datasources.dart, …) that exports its files. Import barrels, not files,
across folders.
Dependency direction
presentation ──▶ di ──▶ data
│ │ │
└──────▶ domain ◀───┘- Domain imports nothing from Flutter, Dio, Firebase, Riverpod or any
platform SDK. Plain Dart +
equatable. - Data implements domain contracts. It is the only layer that knows JSON,
endpoints and the
ApiClient. It does not import Riverpod: wiring is not its job, so it stays testable in plain Dart. di/is the composition point: the only place that seesdata/anddomain/together. It builds the data source and repository and exposes the repository as its contract type (Provider<FavoriteRepository>).- Presentation imports
domain/anddi/, neverdata/. It does not call anApiClient, parse JSON or touch SDKs. - Between features, depend on the other feature's domain (or
di/) only. If two features need the same model, promote it tocore/instead of reaching into another feature'sdata/orpresentation/.
Why di/ and not "a provider next to the impl": a provider in data/ forces
presentation to import data/ just to ref.watch it, and the rule
"presentation never imports data" gains an exception that people stretch
(first the provider, then "just this one model"). A dedicated file keeps the
rule absolute, so a script can check it. It also keeps data/ free of
Riverpod.
Call chain: Widget → (Async)Notifier → Repository contract → RepositoryImpl
→ RemoteDataSource → ApiClient. Never skip a layer.
Per-layer rules
Entities — immutable, extends Equatable, const constructor, no JSON.
Drop wire-only fields (userId the client already knows) in toEntity.
Equatable also makes ref.watch(p.select(...)) work by value.
Repository contract — abstract interface class, methods return
AsyncResult<Entity> / AsyncResult<Unit> (see flutter-result-errors).
Signatures use entities and value objects, never models or SDK types.
Models — live only in data/models/. Factory fromJson (via
json_serializable), toEntity(), and fromEntity when the model is sent
back. Entities never import models. Models never leave the repository.
Endpoints — one abstract final class <X>Endpoints of path constants and
path-building static methods, so URLs are not string literals in data sources.
Remote data source — abstract interface class + Impl that
with RemoteDataSourceGuard, takes an ApiClient, returns AsyncResult<Model>.
No provider in this file.
Repository impl — takes the data source, converts models → entities with
result.map(...), passes failures through. No provider in this file.
di/<feature>_providers.dart — the providers for the two above:
final favoriteRemoteDataSourceProvider = Provider<FavoriteRemoteDataSource>(
(ref) => FavoriteRemoteDataSourceImpl(ref.watch(apiClientProvider)),
);
/// Exposes the CONTRACT, never the implementation. Tests override this.
final favoriteRepositoryProvider = Provider<FavoriteRepository>(
(ref) => FavoriteRepositoryImpl(ref.watch(favoriteRemoteDataSourceProvider)),
);In a test, override the contract and data/ is never touched:
ProviderContainer(overrides: [
favoriteRepositoryProvider.overrideWithValue(FakeFavoriteRepository()),
]);Providers (presentation) — one responsibility each. Pick by role:
| Need | Use |
| Immutable dependency (repo, service, client) | Provider |
| Async read-only data | FutureProvider |
| Continuous stream (auth state, connectivity) | StreamProvider |
| Mutable sync state (filters, selected tab) | NotifierProvider |
| Mutable async state (a screen's store, a session) | AsyncNotifierProvider |
| One user action in flight | SubmissionNotifier + autoDispose |
Declare providers explicitly. No riverpod_generator, no @riverpod, no
StateNotifier. Business rules that belong in the domain do not live in
providers.
Pages and widgets — no JSON, no SDKs, no business rules. Side effects
(navigation, snackbars, analytics) are declared with ref.listen in a
<Feature>Listeners widget with a child parameter that wraps the page;
widgets only watch declarative state.
Build order for a new feature
- Entity (
domain/entities) - Repository contract (
domain/repositories) - Model with
toEntity(data/models) — thendart run build_runner build - Endpoints class (
data/datasources) - Remote data source
- Repository impl
di/providers (data source + repository, exposed as the contract)- Presentation provider (
AsyncNotifierwhosebuildreads the repository throughdi/and callsgetOrThrow()) - Submission notifier for each user action
<Feature>Listenerswidget- Page + widgets, registered in the router
- Tests: data source with a fake
ApiClient, repository mapping, notifier with the repository contract overridden, widget test with fakes - Run
scripts/check_boundaries.sh
Scaffold script
scripts/scaffold_feature.sh creates steps 1–8 as compilable stubs with all
barrels, and never overwrites existing files:
# from the Flutter project root
bash <path-to-skill>/scripts/scaffold_feature.sh favorites --entity Favorite- First argument: feature folder name,
snake_case. --entity Name: PascalCase entity (default: the feature name in PascalCase).--package name: override the package name (default: read frompubspec.yaml).
Afterwards: add fields to the entity and model, fill the endpoints, run
dart run build_runner build and dart fix --apply (the stubs' import order
is not lint-sorted), then continue from step 9.
Checking the boundaries
scripts/check_boundaries.sh is plain grep, so it needs no Dart toolchain
and fits in any CI step. Run it from the project root:
bash <path-to-skill>/scripts/check_boundaries.sh # default: lib/featuresIt exits 1 and lists every violation of these rules, or prints OK:
presentation/never importsdata/domain/imports no framework or SDK, nordata/,presentation/,di/data/imports neitherpresentation/,di/nor Riverpod- A feature never imports another feature's
data/orpresentation/ - Feature code imports no third-party SDK directly
Run it after every scaffold, and in CI so the boundary cannot erode.
Review checklist
check_boundaries.shprintsOKdomain/has no imports fromflutter,dio,flutter_riverpod, SDKsdi/exposes the repository as its contract type, not theImpl- Repositories return entities, not models; no thrown exceptions
- Each folder has a barrel; cross-folder imports use barrels
- Providers are explicit (no codegen) and each has one job
- Side effects live in the feature's
Listenerswidget
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.

