---
name: svelte-store-analyzer
description: "A diagnostic read of a Svelte store file: the state it holds, who reads and writes it, derived stores and side effects, leaks and race conditions, and refactors ranked by impact, for Svelte 3 through 5. Use when a Svelte store file has grown confusing and needs its state shape, readers, writers, derived stores, and leaks mapped out with refactoring advice. Do not use for creating a new store from scratch or reviewing Svelte components that merely use the store. Related topics: coding, svelte."
---

# Svelte Store Analyzer

A diagnostic read of a Svelte store file: the state it holds, who reads and writes it, derived stores and side effects, leaks and race conditions, and refactors ranked by impact, for Svelte 3 through 5.

## When to use

Use this skill when a Svelte store file has grown confusing and needs its state shape, readers, writers, derived stores, and leaks mapped out with refactoring advice. Do not use it for creating a new store from scratch or reviewing Svelte components that merely use the store.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Write the state shape as a type, including any optional or union fields the code implies.
3. Trace every read and write of the store and note async writes that can land stale results.
4. Review derived stores and manual subscriptions for excess recomputation and missing unsubscribes.
5. For Svelte 5, mark which state belongs in runes inside a .svelte.js module and which still needs a store for sharing.
6. Rank recommendations by impact and provide the code change for the top three.

## Inputs

- **Store file path** (free text, e.g. "src/lib/store.js")
- **Store source** (longer free text)
- **Include derived stores** (choose one: Yes, No)
- **Detail level** (choose one: Summary, Moderate, Deep)
- **Svelte version** (choose one: 3, 4, 5)
- **Output format** (choose one: Markdown, JSON)
- **Notes** (longer free text)

## Output

A report in Markdown or JSON with Overview, State schema, Subscriptions, Derived stores (optional), and Recommendations, at the requested depth.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Svelte Store Review

Review this Svelte store.

- Store file path: {{Store file path}}
- Store source: {{Store source}}
- Include derived stores: {{Include derived stores}}
- Detail level: {{Detail level}}
- Svelte version: {{Svelte version}}
- Output format: {{Output format}}
- Notes: {{Notes}}

Start by writing down the state shape as a type, since most store problems are a shape nobody wrote down. Trace every place the store is read (subscribe, the $store syntax, get) and written (set, update), and note which writes happen inside async code without guarding against stale results. Review derived stores for recomputation on every tick and for subscriptions that are never unsubscribed, which leak in long-lived components. For Svelte 5, say which parts belong in runes ($state, $derived) in a .svelte.js module and which still need a store for cross-component sharing. Flag mutation of objects inside update without returning a new reference, which skips reactivity. Rank the recommendations by impact and give the code change for the top three.

Return a report in the chosen format with the sections Overview, State schema, Subscriptions, Derived stores (when included), and Recommendations, at the chosen detail level.

## Pitfalls

- Mutating an object inside update and returning the same reference, which Svelte treats as unchanged.
- Calling subscribe manually in a component without storing and calling the unsubscribe function, which leaks on every mount.
- Recommending runes for cross-component shared state in Svelte 5 when the project still needs a store for that case.
