.agents/skills/query-layer/SKILL.md
Query layer patterns for consuming services with TanStack Query, error transformation, and runtime dependency injection. Use when the user mentions createQuery, createMutation, TanStack Query, or when implementing queries/mutations, transforming errors for UI, or adding reactive data management.
npx skillsauth add epicenterhq/epicenter query-layerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
The query layer is the reactive bridge between UI components and the service layer. It wraps pure service functions with caching, reactivity, and state management using TanStack Query and WellCrafted factories.
Related Skills: See
services-layerfor the service layer these queries consume. Seesveltefor Svelte-specific TanStack Query patterns. Seeerror-handlingfor toast-on-error patterns—how errors from Results surface to users viatoastOnErrorandextractErrorMessage.
Use this pattern when you need to:
┌─────────────┐ ┌─────────────┐ ┌──────────────┐
│ UI │ --> │ RPC/Query │ --> │ Services │
│ Components │ │ Layer │ │ (Pure) │
└─────────────┘ └─────────────┘ └──────────────┘
↑ │
└────────────────────┘
Reactive Updates
Query Layer Responsibilities:
.options) and imperative (.execute())Critical: Service errors should be transformed to user-facing error types at the query layer boundary.
Service Layer → Query Layer → UI Layer
TaggedError<'Name'> → UserFacingError → Toast notification
(domain-specific) (display-ready) (display)
import { Err, Ok } from 'wellcrafted/result';
// In query layer - transform service error to user-facing error
const { data, error } = await services.recorder.startRecording(params);
if (error) {
return Err({
title: '❌ Failed to start recording',
description: error.message,
action: { type: 'more-details', error },
});
}
return Ok(data);
Every query/mutation provides two ways to use it:
.optionsUse in Svelte components for automatic state management. Pass .options (a static object) inside an accessor function:
<script lang="ts">
import { createQuery, createMutation } from '@tanstack/svelte-query';
import { rpc } from '$lib/query';
// Reactive query - wrap in accessor function, access .options (no parentheses)
const recorderState = createQuery(() => rpc.recorder.getRecorderState.options);
// Reactive mutation - same pattern
const transformRecording = createMutation(
rpc.transformer.transformRecording.options,
);
</script>
{#if recorderState.isPending}
<Spinner />
{:else if recorderState.error}
<Error message={recorderState.error.description} />
{:else}
<RecorderIndicator state={recorderState.data} />
{/if}
.execute() / .fetch()Use in event handlers and workflows without reactive overhead:
// In an event handler or workflow
async function handleTransform(recordingId: string, transformation: Transformation) {
const { error } = await rpc.transformer.transformRecording({
recordingId,
transformation,
});
if (error) {
notify.error(error);
return;
}
notify.success({ title: 'Transformation complete' });
}
// In a sequential workflow
async function stopAndTranscribe(toastId: string) {
const { data: blobData, error: stopError } =
await rpc.recorder.stopRecording({ toastId });
if (stopError) {
notify.error(stopError);
return;
}
// Continue with transcription...
}
| Use .options with createQuery/createMutation | Use .execute()/.fetch() |
| ---------------------------------------------- | --------------------------- |
| Component data display | Event handlers |
| Loading spinners needed | Sequential workflows |
| Auto-refetch wanted | One-time operations |
| Reactive state needed | Outside component context |
| Cache synchronization | Performance-critical paths |
.options (no parentheses) - It's a static object, wrap in accessor for Svelte.ts files - createMutation requires component contextLoad these on demand based on what you're working on:
If working with error transformation examples and anti-patterns, read references/error-transformation-patterns.md
If working with runtime dependency injection and service selection, read references/runtime-dependency-injection.md
If working with cache management, query definitions, RPC namespace, or notify coordination, read references/advanced-query-patterns.md
See apps/whispering/src/lib/query/README.md for detailed architecture
See the services-layer skill for how services are implemented
See the error-handling skill for trySync/tryAsync patterns and toast-on-error conventions
documentation
Yjs CRDT patterns, shared types (Y.Map, Y.Array, Y.Text), conflict resolution, and document storage. Use when the user mentions Yjs, Y.Doc, CRDTs, collaborative editing, or when handling shared types, implementing real-time sync, or optimizing document storage.
tools
Voice and tone rules for all written content—prose, UI text, tooltips, error messages. Use when the user says "fix the tone", "rewrite this", "sounds like AI", "sounds corporate", or when writing any user-facing text, landing pages, product copy, or open-source documentation.
tools
Workspace API patterns for defineTable, defineKv, versioning, migrations, data access (CRUD + observation), withActions, and extension ordering. Use when the user mentions workspace, defineTable, defineKv, createWorkspace, withActions, withExtension, defineQuery, defineMutation, connectWorkspace, or when defining schemas, reading/writing table data, observing changes, writing migrations, chaining extensions, or attaching actions to a workspace client.
documentation
Standard workflow for implementing features with specs and planning documents. Use when the user says "start a new feature", "how should I plan this", "what's the process", or when starting implementation, planning work, or working on any non-trivial task.