zakariaf/flutter-skills/flutter-architecture
Claude Code and agent skill by zakariaf/flutter-skills
- community
Checking that the SKILL.md file is still in the repository.
Enforces a right-sized feature-first layered MVVM Flutter architecture — features are folders and cross-cutting foundations become packages only when a compile wall earns it, a strict downward-only dependency DAG, dumb Views over one Notifier/AsyncNotifier ViewModel per feature, repositories as the single source of truth and single write path returning immutable domain values, abstractions only where something genuinely can't run in a test, and Riverpod 3.x as the one context-free DI+state mechanism (no get_it/injectable/package:provider container). Use when creating a Flutter feature or file, deciding folder-vs-package or where a class belongs, naming a Screen/Notifier/Repository/Service, wiring providers or a composition-root/bootstrap.dart, adding a use-case/domain layer, resisting over-engineering on a small app, or reviewing whether a change respects the layer boundaries.
Install
npx vskill@latest install zakariaf/flutter-skills/flutter-architectureSKILL.md
The same SKILL.md was published earlier as zakariaf/flutter-skills/flutter-architecture.
Flutter Architecture
Structure every Flutter app as a layered, feature-first MVVM system, sized to the app. You must always answer "where does this code belong?" in one second. Based on Flutter's official Guide to app architecture, with Riverpod 3.x as the one mechanism for both state and dependency injection.
Two failure modes kill an architecture: under-structure (a widget touching a database) and over-structure (a *UseCase wrapping one repository call, an interface over code that already runs in a test). This skill fights both. Start small; add a layer only when it carries a load you can name.
Read the reference for the task at hand:
references/module-and-layers.md— the layer model, folder-vs-package continuum, the DAG, barrels, feature-folder anatomy, and the "when multi-package (workspace)" note.references/right-sizing.md— the reject-over-engineering table, "abstract only what you can't test", and how architecture scales with app size.references/state-di-riverpod.md— provider graph, keepAlive vs autoDispose, placeholder-override composition root, isolate-safe factories,ProviderContainertests.
Run scripts/check_architecture.sh before opening a PR.
Non-negotiable rules
- Answer "where does this belong?" in one second. Group by feature first, layer second. No
giant app-wide screens/, models/, or widgets/ bucket — those smear one feature across the tree and force a name lookup on every edit.
- **Two layers minimum: UI and Data. A domain/use-case layer only when logic spans multiple
repositories** (projection, aggregation, a multi-step workflow). A *UseCase that forwards one repository call is a rename, not a boundary — Flutter's own guidance rates the domain layer conditional and says most apps don't need it.
- Abstract exactly what cannot run in a test — name what the abstraction makes testable. A
platform channel, network client, or plugin that can't execute in flutter test earns an interface + a fake. Code that already runs headless (an in-memory DB, a pure calculator, a repository over it) stays concrete. "It's cleaner" is not a load; if you can't name the seam it buys, don't add it.
- Data flows one way; never skip or reverse a hop. Data down: `Service → Repository → ViewModel →
View. Events up: View → ViewModel → Repository`. A widget calls its ViewModel only; a ViewModel calls repositories only. No two-way binding, no widget reaching a data source.
- The View is dumb. A View does layout,
if/switchon state, animation, and navigation —
nothing else. No business logic, no formatting/number math, no try/catch, no data access. If a widget computes or fetches, it's in the wrong layer.
- One ViewModel per feature, over immutable state. The ViewModel holds private mutable state
and exposes intent methods (load(), add(...)); every transition assigns a new immutable value with value equality. No public setters, no mutable field the UI edits in place.
- Repositories are the single source of truth AND the single write path. Every mutation is one
named repository method that persists first, then publishes (one transaction where the store supports it). Never persist-after-publish — a crash in between credits state that never saved.
- Derive, don't store. Counts, totals, streaks, filtered lists are **computed from the source of
truth** (a stream/derived provider), never a second stored counter that can drift out of sync.
- Map at the boundary; keep domain types out of the edges. Repositories map storage rows / JSON
DTOs → immutable domain value objects. A generated Drift row or a Map never reaches a ViewModel or widget; unit math and locale formatting never happen in a widget.
- Inject through providers; depend on the abstraction where it earns one. No globals, no
singletons, no service locator reached from a widget, no DateTime.now() outside an injected Clock. A composition root wires the object graph once.
- Features are FOLDERS; foundations become PACKAGES only when a compile wall is load-bearing.
Default to a single package. A feature never imports another feature — share via a foundation layer or navigate by route ID. The dependency graph is a strict downward-only DAG.
- Errors are typed values at boundaries. Repositories/use-cases return a sealed
Result/Failure
rather than throwing across a layer; the UI switches exhaustively. See error-handling-typed-results.
The layered shape (single package, the default)
project-structure-and-packages OWNS the physical tree; this is the feature-first layout it defines, shown here for the layer semantics. Features are FOLDERS under lib/features/; a feature's Views and its one ViewModel live in presentation/.
Rules of thumb: core/ depends on nothing above it and stays free of BuildContext; data/ has no Flutter UI imports; a feature depends on core/data/services, never on a sibling feature. Add a feature-local domain/ + application/ (use-cases) folder only when logic spans repositories.
The feature slice (Riverpod-first "how")
A dumb View reads one ViewModel; the ViewModel holds private state and exposes intent methods.
The repository behind it is the single source of truth AND single write path — a watchTasks() stream plus an add() that persists first, then the stream re-emits. Give it an abstract interface only when the real impl can't run in a test (rule 3); over an in-memory DB a concrete class is fine.
Providers ARE the dependency injection. Wire deps via ref.watch, key per-entity state with family, and use autoDispose for per-screen controllers. See state-management-riverpod for the full API discipline (watch/read/listen split, .select, stale-closure hazards).
The composition root (single write of the object graph)
Infra that constructs asynchronously (a database, dirs, a key store) is injected via placeholder providers that throw until overridden in bootstrap.dart — the same seam tests use.
Keep infra (DB, repositories, clock) keepAlive; never autoDispose a singleton that can be torn down mid-operation. See app-startup-and-bootstrap for main() ordering and error handlers.
Right-sizing: folder vs package, and what to abstract
Scale the architecture to the app. The three questions, in order:
- Does this need a new folder or a new file? Almost always a file in an existing feature/layer.
- Does this need a domain/use-case layer? Only if logic spans multiple repositories. One-repo CRUD
does not.
- Does this need an interface? Only if the real implementation can't run in
flutter test, or you
genuinely swap dev/prod impls. Name the fake it enables.
- Does this need a separate package? Only when a compile-time wall is load-bearing — divergence
would be a correctness bug (canonical units/money math, the whole data layer, a scheduler). See the reject-over-engineering table in references/right-sizing.md.
When multi-package (workspace). A large app (many teams, a pure-Dart core you golden-test, areusable design system) may split foundations into packages under a Dart pub workspace. Then:each member setsresolution: workspacewith one rootpubspec.lock; each package exposes **onebarrel** (core.dart) over a privatesrc/— never import another package'ssrc/; the pure-Dartcorepackage declares noflutterdependency so a stray import is a compile error; the DAG staysacyclic (core→ nothing internal; everything →core; the app shell → all). This is an option a bigapp grows into, never a requirement for a small one — a single package with folders is the default.
Anti-patterns
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/flutter-architecture/SKILL.md
Popularity
- Repository stars
- 22
- Repository forks
- 4
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/zakariaf/flutter-skills/flutter-architecture)