---
name: svelte-store-documenter
description: "Turns a Svelte store into reference documentation a teammate can use without reading the source: contract, default state, every exported method with its signature, and a copy-paste usage example. Use when a Svelte store needs reference docs covering its value shape, default state, exported methods, and usage so teammates stop reading the source. Do not use for debugging a store that misbehaves or documenting a Vue or React state module. Related topics: coding, svelte."
---

# Svelte Store Documenter

Turns a Svelte store into reference documentation a teammate can use without reading the source: contract, default state, every exported method with its signature, and a copy-paste usage example.

## When to use

Use this skill when a Svelte store needs reference docs covering its value shape, default state, exported methods, and usage so teammates stop reading the source. Do not use it for debugging a store that misbehaves or documenting a Vue or React state module.

## 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. Read the store source and write a one-paragraph Overview that names what state it holds and who should read or write it.
3. Infer the value type and default from the initial value and the code, and record them as a TypeScript type in the Definition section.
4. Document each exported function with its signature, effect, and sync or async nature; every exported name has an entry.
5. For derived or custom stores, list the inputs or the hidden internals so the recompute and visibility rules are explicit.
6. Add runnable examples with exact imports when requested, then a Notes section with SSR, persistence, and mutation gotchas.

## Inputs

- **Store name** (free text, e.g. "sessionStore")
- **Store type** (choose one: writable, readable, derived, custom)
- **Store source code** (longer free text)
- **Initial value** (longer free text)
- **Exported functions** (choose any: set, update, reset, subscribe, custom helpers)
- **Usage context** (choose one: component, page, layout, shared library)
- **Include examples** (choose one: Yes, No)

## Output

One markdown file with Overview, Definition, API (a subsection per exported function), Example Usage when requested, and Notes, in that order and nothing outside it.

## Prompt template

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

### Svelte Store Documenter

Write the reference documentation for the store below as a single markdown file.

- Store name: {{Store name}}
- Store type: {{Store type}}
- Store source code: {{Store source code}}
- Initial value: {{Initial value}}
- Exported functions: {{Exported functions}}
- Usage context: {{Usage context}}
- Include examples: {{Include examples}}

Document what the store promises, not how it is implemented. Start with one paragraph on what state it holds and who should read or write it. Describe the value shape as a TypeScript type (infer it from the initial value when the source has no types) and state the default. Then list each exported function with its signature, what it changes, and whether it is synchronous. For derived stores, list the input stores and say when the value recomputes. For custom stores, document the public surface only and mention any internal state that is deliberately hidden.

When examples are requested, give one component example using the $ prefix and, for a shared library, one manual subscribe with cleanup. Keep every example runnable with the exact imports. Add a Notes section for gotchas such as SSR behavior, persistence, or values that must not be mutated in place.

### Output
Return one markdown document with sections in this order: Overview, Definition (value type and default), API (one subsection per exported function), Example Usage (only when requested), Notes. No text outside the document.

## Pitfalls

- Documenting implementation details such as internal variables, which go stale with the next refactor.
- Omitting subscribe from the API list because it is inherited, leaving library users without the cleanup contract.
- Writing examples that mutate the value in place, which teaches readers a pattern that silently skips updates.
