src/renderer/data/README.md
This directory contains the renderer process data services.
src/renderer/data/
├── DataApiService.ts # User Data API service
├── PreferenceService.ts # Preferences management
├── CacheService.ts # Three-tier caching system
└── hooks/
├── useDataApi.ts # useQuery, useMutation, useInfiniteQuery, useInfiniteFlatItems, usePaginatedQuery, useDataChange, useReadCache, useWriteCache, useInvalidateCache, prefetch
├── useReorder.ts # optimistic drag-and-drop reordering
├── usePreference.ts # usePreference, usePreferences
└── useCache.ts # useCache, useSharedCache, useSharedCacheValue, usePersistCache
// Data API
import { useQuery, useMutation } from '@data/hooks/useDataApi'
const { data } = useQuery('/topics')
const { trigger: createTopic } = useMutation('/topics', 'POST')
// Preferences
import { usePreference } from '@data/hooks/usePreference'
const [theme, setTheme] = usePreference('app.theme.mode')
// Cache (three-tier renderer cache)
import { useCache, useSharedCache, usePersistCache } from '@data/hooks/useCache'
const [counter, setCounter] = useCache('ui.counter', 0)
// Non-reactive DataApi cache control (snapshot read / overlay write / invalidate)
import { useReadCache, useWriteCache, useInvalidateCache } from '@data/hooks/useDataApi'
For any resource that exposes drag-and-drop ordering, use useReorder — it
handles optimistic updates, PATCH dispatch, revalidation, and rollback on top
of useMutation.
const { data } = useQuery('/mcp-servers')
const { applyReorderedList } = useReorder('/mcp-servers')
return <DraggableList items={data?.items ?? []} onReorder={applyReorderedList} />
The full end-to-end design — database schema helpers, API endpoint composition,
service-layer helpers (insertWithOrderKey / insertManyWithOrderKey / applyMoves /
resetOrder), migrator helpers, renderer integration, migration checklist, FAQ
— lives in the Reorder Guide.
The guide is the canonical reference for both main- and renderer-side work.