flutter-ai-starter / rules
Cursor rule0 starsChanged 5 months agoMITView on GitHub
Architecture, folder layout, layering, and dependency rules
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 4,183 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository26 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/000-project.mdcCursor rule
- .cursor/rules/accessibility.mdcCursor rule
- .cursor/rules/api-integration.mdcCursor rule
- .cursor/rules/dart-style.mdcCursor rule
- .cursor/rules/design-system.mdcCursor rule
- .cursor/rules/flutter-ui.mdcCursor rule
- .cursor/rules/security.mdcCursor rule
- .cursor/rules/state-management.mdcCursor rule
- .cursor/rules/testing.mdcCursor rule
- doubt-reviewSkill
- fix-dependenciesSkill
- flutter-componentSkill
- flutter-implementSkill
- generate-mocksSkill
- grind-until-greenSkill
- implement-tddSkill
- monitor-terminalSkill
- plan-featureSkill
- repo-navigatorSkill
- review-codeSkill
- save-contextSkill
- suggest-ruleSkill
- write-commitSkill
- write-readmeSkill
The file
We split this architecture.mdc into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 20
Use build_runner for codegen only — freezed, json_serializable, and Mockito mocks (generate-mocks skill).
- Very specific: line 22
Do not introduce other state managers (Riverpod, Bloc, GetX, GetIt) or ORMs without user approval and an entry in docs/DECISIONS.md.
- Very specific: line 72
Create GoRouter in app/router.dart.
- Distinctive: line 75
Do not rebuild the entire router reactively on every frame.
- Distinctive: line 83
No AI vendor SDK on client — backend Edge Functions when AI is enabled.
- Very specific: line 84
No singletons via static.
- Very specific: line 85
No business logic in build().
- Distinctive: line 90
Check for duplicate functionality and reuse opportunities.
≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule 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
---
description: Architecture, folder layout, layering, and dependency rules
globs: ["lib/**/*.dart", "test/**/*.dart", "supabase/**/*.{sql,ts}"]
alwaysApply: false
---
# Architecture
## Stack (company default — pin versions in each app's `pubspec.yaml`)
| Layer | Choice |
|---|---|
| Mobile | Flutter stable, Dart 3.x |
| State & DI | **`package:provider`** + **`ChangeNotifier`** ViewModels |
| Routing | **go_router** (declarative; `context.go` / `context.push`) |
| Models | **freezed** + **json_serializable** (sealed unions for errors/states) |
| HTTP | dio + supabase_flutter (when backend enabled) |
| Local | hive_ce, flutter_secure_storage |
Use `build_runner` for **codegen only** — freezed, json_serializable, and Mockito mocks (`generate-mocks` skill). Not for state management (no Riverpod/codegen DI).
Do not introduce other state managers (Riverpod, Bloc, GetX, GetIt) or ORMs without user approval and an entry in `docs/DECISIONS.md`.
## Pattern: feature-first MVVM (Flutter official)
Organize by **feature**, not by file type. Matches [Flutter app architecture](https://docs.flutter.dev/app-architecture):
| Layer | Folder | Role |
|---|---|---|
| View | `presentation/screens`, `widgets` | UI only — observes ViewModel |
| ViewModel | `presentation/view_models` | `ChangeNotifier` — screen state & commands |
| Model | `data/` + optional `domain/` | Repositories, services, DTOs, entities |
**Domain layer (`domain/`)** — optional; see `docs/ARCHITECTURE.md` for when to skip vs add.
## Folder layout
```
lib/
main.dart # entrypoint — calls bootstrap(), then runApp
bootstrap.dart # binding init, zone/error handling, flavor setup
app/ app.dart, router.dart, theme.dart, dependencies.dart
core/ config/ errors/ logging/ network/ storage/ utils/
design_system/ tokens/ theme/ components/
features/<feature>/
data/ repositories/, services/, models/
domain/ entities/, use_cases/ # optional
presentation/ view_models/, screens/, widgets/
services/ analytics/ crash/ push/
l10n/
```
## Dependency injection
- Wire dependencies in `app/dependencies.dart` with `MultiProvider` at the root (`runApp`).
- Expose **services** and **repositories** as `Provider<T>`.
- Expose **ViewModels** as `ChangeNotifierProvider<T>` (or `.value` in tests).
- Inject into ViewModels via constructor — use `context.read()` in `create:` callbacks, not globals.
- ViewModels receive repositories as **private** constructor params — views must not call repositories directly.
## Layering
- **Direction:** `presentation → domain (optional) → data`. Never the reverse.
- **Services** wrap one data source each. No state.
- **Repositories** orchestrate services. **Must not depend on each other.**
- Widgets never import `data/` directly.
- Cross-cutting services in `lib/services/` registered in `dependencies.dart`.
- Feature A never imports `features/feature_b/`.
## go_router + provider
- Create `GoRouter` in `app/router.dart`.
- Inject repositories/ViewModels in route `builder`s via `context.read()`.
- Auth redirect: pass a `ChangeNotifier` (or `Listenable`) as `refreshListenable` on `GoRouter` — call `notifyListeners()` when auth state changes.
- Do not rebuild the entire router reactively on every frame.
## Rules
- One screen / ViewModel / repository per file.
- `freezed` for DTOs, entities, sealed `Failure` / UI state unions.
- Repositories return `Future<Result<T, Failure>>`.
- No `Supabase.instance.client` from widgets — inject via `Provider`.
- No AI vendor SDK on client — backend Edge Functions when AI is enabled.
- No singletons via `static`.
- No business logic in `build()`.
- `setState` only for local ephemeral UI (focus, animation controllers).
## Before implementing
- Check for duplicate functionality and reuse opportunities.
- Files: `snake_case.dart`; classes: `PascalCase`; ViewModels: `<Feature>ViewModel`.
See `docs/ARCHITECTURE.md` and `docs/DECISIONS.md`.
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.

