agentleFS
ArenukvernArenukvern/mcp_flutter/.cursor/rules/command_resource.pattern.md

mcp_flutter / rules

Cursor rule385 starsChanged 5 months agoMITView on GitHub

When writing commands or resources

The file

We split this command_resource.pattern.md into the rules it gives an agent

12 rules. About 0 are common, 7 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    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
  1. Distinctive:

    Do not rely on strings, use enums.

    line 12
  2. Distinctive:

    Use context.read/context.select to subscribe to observable state in build methods.

    line 13
  3. Distinctive:

    Call one or more Services to perform the necessary work.

    line 32
  4. Distinctive:

    Update one or more Resources with the result of the operation.

    line 33
  5. Distinctive:

    Place ResourceData (BLoC models, see below) and support types to {snake_case}.src.data.dart

    line 60
  6. Distinctive:

    Use for all Flutter UI Widget related data.

    line 63
  7. Very specific:

    Use BLoC Style, see explanation below.

    line 64
  8. Very specific:

    If the domain scope is similar: KeyboardSetting, MusicSettings, GridSettings etc..

    line 67
  9. Very specific:

    If it is related to one model, like Apple has properties: color, shape etc..

    line 68
  10. Very specific:

    If that's the case, always create ResourceData.

    line 69
  11. Distinctive:

    Use for scenarios demanding ultra-fast, in-place updates: e.g., animation buffers, real-time game state, or any data structure where …

    line 75
  12. Very specific:

    Create separate 'Data', if no models exists.

    line 78

≈ “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
command_resource.pattern.md

Writing Code Protocol

  • Export files from its folders using barrel file (resources/resources.dart, commands/commands.dart etc.).
  • Do not rely on strings, use enums.
  • Use context.read/context.select to subscribe to observable state in build methods.

Intent and Implementation Consistency

Command-Resource Pattern

The relationship between Commands, Resources, and Services is the backbone of the application's architecture, ensuring a clean separation of concerns.

  • Commands: Execute atomic transactions.
  • Services: Provide reusable capabilities.
  • Resources: Hold and expose UI state.

A typical data flow is: UI -> Command -> Service -> Resource -> UI.

  • Commands: Pure business logic containers
    • Role: To execute a single, discrete business transaction (e.g., "Save Character") in response to a UI event. Commands are the only part of the application allowed to orchestrate state changes.
    • Responsibilities:
      • Translate a UI event into a state change.
      • Validate input for a specific action.
      • Call one or more Services to perform the necessary work.
      • Update one or more Resources with the result of the operation.
    • Characteristics:
      • Short-lived & Stateless: A Command is created, executed, and discarded for a single action. It holds no state itself.
      • Triggered by UI: They are the bridge between user intent (a button click, a debounced text change) and the system's reaction.
    • Expose logic via execute() method. Create private methods if needed for clarity
    • Named as {Action}{Resource}Command
    • File named as {snake_case}.cmd.dart
    • The Dart class name within a command file must be the PascalCase version of the file name. For example, load_nutrients.cmd.dart must contain class LoadNutrientsCommand.
    • Can read/update multiple resources
    • Contain all transformative logic
    • Commands are executed based on user or other actions
  • Services: High-level capability providers
    • Role: To encapsulate a major area of application functionality and provide a stable, reusable API for a core domain concern (e.g., WorkspaceService).
    • Responsibilities:
      • Interacting with the Data API (file system I/O, parsing).
      • Managing long-running processes (e.g., watching a directory).
      • Encapsulating complex, multi-step business workflows.
    • Characteristics:
      • Long-lived: Often instantiated once and used throughout the application's lifecycle.
      • Called by Commands: Services should never be called directly from the UI.
      • Dependencies: Depend on the Data API and other low-level utilities. They do not depend on Commands or UI.
  • Resources: Pure data containers
    • Role: To hold, manage, and expose UI state. They notify listeners when their data changes, enabling the UI to be reactive.
    • Named as {Domain}Resource
    • File named as {snake_case}.src.dart
    • Place ResourceData (BLoC models, see below) and support types to {snake_case}.src.data.dart
    • Minimal business logic related to state management. Focus on holding and managing state, not complex domain logic.
    • Immutable Resources
      • Use for all Flutter UI Widget related data.
      • Use BLoC Style, see explanation below.
      • For resources representing collections (lists, maps), always extend OrderedMapNotifier/OrderedListNotifier from xsoulspace_state_utils.
      • Protocol defining ResourceData class:
        • If the domain scope is similar: KeyboardSetting, MusicSettings, GridSettings etc..
        • If it is related to one model, like Apple has properties: color, shape etc..
        • If that's the case, always create ResourceData.
        • Otherwise create for every primitive different Resource, like GameStatusResource extends ValueNotifier etc.
        • In the context of Immutable Resources, BLoC style refers to the practice of separating the immutable data structure (the "State" in BLoC terminology) into its own Data class (Model). This Data class is then held and managed by the Resource class (which acts as a simplified "BLoC"), using ValueNotifier, OrderedMapNotifier, or OrderedListNotifier to notify listeners of state changes. This promotes a clear separation of concerns and improves the manageability of immutable state.
    • Mutable Resources
      • Pure classes with mutable structures.
      • Use for scenarios demanding ultra-fast, in-place updates: e.g., animation buffers, real-time game state, or any data structure where mutation speed is critical.
      • Optimized for high-frequency, low-latency changes—ideal for render loops, simulations, or transient, performance-sensitive state.
      • For resources representing collections (lists, maps), always extend OrderedMap/OrderedList from xsoulspace_state_utils.
      • Create separate 'Data', if no models exists. Bloc style files for complex data structures. When using in Mutable Resource, Data should have prefix Mut and be mutable.
      • Data can be changed in place; updates mutate the existing instance.
    • Resources should provide a clear way to define their initial state. Use factory constructors like initial() within the state class for this purpose.
    • Cannot have any dependencies!

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.