State management

From compozy/compozy · View interactive version

State management is an AI agent skill from the GitHub repository compozy/compozy. Model, review, and refactor application state so source state stays minimal, derived state is computed instead of synchronized, impossible states are not representable, and each piece of state lives in the right place. Use this whenever the user mentions state management, reducers, stores, Redux, Zu

How to use this skill

Skill file

State Management

Use this skill for state modeling first and library mapping second.

The goal is not to recommend a favorite library. The goal is to produce a state model that remains sound whether the implementation ends up in local component state, a reducer, Redux, Zustand, Pinia, URL params, TanStack Query, or no library at all.

Your job:

First pass

In an existing codebase:

  1. Inspect local package.json files and imports.
  2. Read the component, store, reducer, and selector/getter code near the problem.
  3. Identify which state is local, global, remote, URL-backed, or external.
  4. Separate current implementation details from the actual domain model before suggesting changes.

If the user wants a new design from scratch, model the domain directly and only then choose implementation.

Task mode

Choose a mode before answering:

Do not jump straight to API advice when the real problem is a broken model.

Core taxonomy

Classify every value before deciding where it belongs.

If a value does not clearly fit, you probably have not understood its role yet.

Core principles

Workflow

Use this sequence unless the user explicitly asks for something narrower.

  1. Inventory all current or proposed state values.
  2. Classify each value using the taxonomy above.
  3. Remove duplication:
  1. Define invariants:
  1. Identify finite modes:
  1. List domain events:
  1. Sketch transitions:
  1. Decide placement:
  1. Map the model to the chosen library.

When requirements are fuzzy, show the model before the code.

Modeling questions

Use these questions before writing or revising code:

Choosing the representation

Prefer the simplest representation that preserves invariants.

Do not recommend a more complex abstraction unless the simpler one cannot enforce the needed invariants.

Placement guidance

Choose where state lives by asking:

Strong defaults:

Anti-patterns

Flag these aggressively in reviews and refactors:

Reference routing

Open only the relevant references for the current task:

If the problem is specifically about XState or actor systems in a codebase that already uses them, prefer the dedicated xstate-v5 skill for implementation details.

Output format

Prefer this answer shape:

  1. State inventory: what exists now or what must exist.
  2. Findings or invariants: duplication, impossible states, and design constraints.
  3. Recommended model:
  1. Library mapping: only if the user asked for implementation in a specific stack.
  2. Code: only after the model is clear enough.

For reviews, lead with concrete problems first. For design tasks, lead with the model first.

Final self-check

Before answering, verify:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.