agentleFS
Zulut30Zulut30/dart-mobile-game-studio/.cursor/rules/dart-flutter-architecture.mdc

dart-mobile-game-studio / rules

Cursor rule1 starsChanged 5 months agoMITView on GitHub

Architecture rules for Dart/Flutter game source — separate game logic from rendering, state machine, modular layout, mode decision.

The file

We split this dart-flutter-architecture.mdc into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is 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.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Don't mix Flutter-UI and Flame in one screen without this decision (flutter-game-architecture.md).

    line 24

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
dart-flutter-architecture.mdc
---
description: Architecture rules for Dart/Flutter game source — separate game logic from rendering, state machine, modular layout, mode decision.
globs: **/*.dart
alwaysApply: false
---

# Dart/Flutter game architecture rules

Applies to Dart source. Keep games testable, adaptable, and small.

## Separate logic from rendering (3 layers)
- **Game logic** lives in pure Dart with **no `package:flutter` import** (`lib/models/`,
  `lib/systems/`). It runs and is unit-tested on the Dart VM with `dart test` — no device, no widget
  pump. A `package:flutter` import in `lib/models/` is a bug.
- **UI** (`lib/widgets/`) and the **engine layer** (Flame in `lib/game/`) are **thin**: they render
  the model and translate input into model intents. No game rules in widgets/components.

## Mode decision (pick one; justify)
- **Flutter-widgets-only** — static/turn-based; `CustomPainter`/`Canvas`, `GestureDetector`/`Draggable`,
  repaint via `ValueNotifier`/`ListenableBuilder`.
- **Flame** — continuous motion/physics; `FlameGame` + `Component`/`PositionComponent`,
  `update(dt)`/`render`, `HasGameReference<MyGame>`, `CollisionCallbacks`; Forge2D for real physics.
- **Hybrid** — `GameWidget` + overlays for menus/HUD over Flame gameplay.
Don't mix Flutter-UI and Flame in one screen without this decision (`flutter-game-architecture.md`).

## State machine & state management
- Explicit `menu → playing → paused → won/lose → menu` as an `enum`/sealed class; transitions are
  pure methods returning the next state. Test every transition.
- Shell state: `ValueNotifier`/`ChangeNotifier` is enough for most games; Provider/Riverpod/Bloc only
  if genuinely needed. The model holds truth; the notifier republishes it.

## Time, determinism, layout
- Advance by a **clamped** `dt` (`dt.clamp(0.0, 1/30)`); Flame does NOT cap `dt` for you.
- Inject a seeded `Random` (`assets/seeded_random.dart`); never global `Random()` in game logic.
- Layout with `LayoutBuilder`/`MediaQuery`/`SafeArea` for phones + tablets; support both orientations.

## Code shape
- `const` constructors; immutable value-typed models (`final`, `==`/`hashCode`, `copyWith`); small
  single-purpose files; dispose controllers/notifiers/subscriptions; `flutter analyze`-clean.
- Levels are JSON **data**, not code (validate vs `assets/level-schema-template.json`).
- Dependencies via `references/package-policy.md` — justify each; default to none.

Reference: `references/flutter-game-architecture.md`, `references/flutter-flame-patterns.md`,
`references/dart/README.md`, `references/quality-policy.md`.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.