AgentSkillsCN

composable-svelte

Composable Svelte 库的总览。当用户对 composable-svelte 提出一般性问题、想知道使用哪个包或模块,或在深入特定功能前需要了解整体架构时使用。指向 14 个领域特定技能以获取实施细节。

SKILL.md
--- frontmatter
name: composable-svelte
description: "Umbrella overview of the Composable Svelte library. Use when the user asks general questions about composable-svelte, wants to know which package or module to use, or needs the big-picture architecture before diving into a specific feature. Points to the 14 domain-specific skills for implementation details."

Composable Svelte — Overview

Composable Svelte is a state management and UI architecture library for Svelte 5, inspired by The Composable Architecture (TCA) from Swift.

Architecture: Store-Reducer-Effect

Every feature follows this flow:

code
User Action → store.dispatch(action)
                    ↓
              reducer(state, action, deps) → [newState, effect]
                    ↓                              ↓
              State updates (immutable)      Effect executes async
              UI re-renders automatically    May dispatch more actions
  • Reducer: Pure function. No mutations, no side effects. Returns new state + an Effect.
  • Effect: Data structure describing a side effect. Executed by the store after state updates.
  • Store: Runtime that holds reactive state, dispatches actions, executes effects.

Store Reactivity

The store uses $state.raw() internally. Both access patterns work:

svelte
<!-- Rune-based (recommended) -->
const count = $derived(store.state.count);

<!-- Subscription-based (also works) -->
{$store.count}

Packages and When to Use Each Skill

NeedPackageSkill to load
Store, reducers, effects, composition@composable-svelte/corecomposable-svelte-core
UI components (Button, Card, Input, 70+)@composable-svelte/core/components/uicomposable-svelte-components
Forms with Zod validation@composable-svelte/core/components/formcomposable-svelte-forms
Modal, Sheet, Drawer, Alert, navigation@composable-svelte/core/navigation-componentscomposable-svelte-navigation
URL routing, browser history@composable-svelte/core/routingcomposable-svelte-core
HTTP client, interceptors, retries@composable-svelte/core/apicomposable-svelte-core
WebSocket, reconnection, channels@composable-svelte/core/websocketcomposable-svelte-core
Internationalization (i18n)@composable-svelte/core/i18ncomposable-svelte-i18n
Server-side rendering, hydration@composable-svelte/core/ssrcomposable-svelte-ssr
Static site generation@composable-svelte/core/ssr/ssgcomposable-svelte-ssr
TestStore, send/receive testing@composable-svelte/core/testcomposable-svelte-testing
Charts and data visualization@composable-svelte/chartscomposable-svelte-charts
Streaming chat, LLM interfaces@composable-svelte/chatcomposable-svelte-chat
Code editor, syntax highlighting@composable-svelte/codecomposable-svelte-code
3D graphics, WebGL/WebGPU@composable-svelte/graphicscomposable-svelte-graphics
Interactive maps, GeoJSON@composable-svelte/mapscomposable-svelte-maps
Audio, video, voice input@composable-svelte/mediacomposable-svelte-media
Docker, Fly.io deploymentcomposable-svelte-deployment

Quick Patterns

Create a feature

typescript
// 1. Types
interface MyState { items: Item[]; isLoading: boolean; }
type MyAction = { type: 'load' } | { type: 'loaded'; items: Item[] };

// 2. Reducer (pure function)
const myReducer: Reducer<MyState, MyAction, MyDeps> = (state, action, deps) => {
  switch (action.type) {
    case 'load':
      return [{ ...state, isLoading: true }, Effect.run(async (dispatch) => {
        const items = await deps.fetchItems();
        dispatch({ type: 'loaded', items });
      })];
    case 'loaded':
      return [{ ...state, items: action.items, isLoading: false }, Effect.none()];
    default:
      return [state, Effect.none()];
  }
};

// 3. Store
const store = createStore({ initialState, reducer: myReducer, dependencies });

Compose features

typescript
import { scope, combineReducers } from '@composable-svelte/core';

// Embed child reducer into parent
const parentReducer = scope(
  s => s.child, (s, c) => ({ ...s, child: c }),  // state lens
  a => a.type === 'child' ? a.action : null,      // action prism
  ca => ({ type: 'child', action: ca }),           // action wrapper
  childReducer
);

Test a feature

typescript
const store = createTestStore({ initialState, reducer, dependencies: mockDeps });
await store.send({ type: 'load' }, s => expect(s.isLoading).toBe(true));
await store.receive({ type: 'loaded' }, s => expect(s.items).toHaveLength(3));

Project Layout

code
packages/core/src/lib/     — Core library source (store, effects, composition, navigation, components, routing, api, websocket, i18n, ssr)
packages/{chat,charts,code,graphics,maps,media}/  — Satellite packages
examples/                  — 11 example applications
guides/                    — Architecture guides and tutorials
.claude/skills/            — This skill system (14 domain skills + this umbrella)

Key Files

  • packages/core/src/lib/store.svelte.ts — Store implementation ($state.raw)
  • packages/core/src/lib/effect.ts — All 12 effect types
  • packages/core/src/lib/types.ts — Core type definitions
  • packages/core/src/lib/test/test-store.ts — TestStore for testing
  • guides/README.md — Full tutorial and package reference