Communitygithub.com

lobehub/store-data-structures

LobeHub Zustand 스토어 데이터 구조 패턴입니다. 스토어 상태, 리스트/세부 정보 분할, 정규화된 맵, 리듀서, messagesMap, topicsMap을 설계하거나 공유 타입 소스를 선택할 때 사용하세요.

store-data-structures란 무엇인가요?

이 스킬은 LobeHub 프로젝트에서 Zustand를 사용할 때 스토어 데이터 구조를 설계하는 패턴을 정의합니다. 주로 리스트와 세부 정보를 분할하여 저장하거나, 정규화된 맵을 사용하여 데이터 중복을 방지하고 효율적으로 관리하는 방법을 제공합니다. 또한 messagesMap이나 topicsMap과 같은 특수한 맵 구조를 통해 채팅 메시지나 주제와 같은 복잡한 데이터를 관리하는 리듀서 패턴을 포함합니다. 이 스킬은 Claude Code, Cursor, Codex 등 다양한 AI 에이전트 환경에서 사용할 수 있으며, SKILL.md 문서를 통해 구체적인 구현 예시와 함께 설명되어 있어 개발자가 일관된 데이터 구조를 빠르게 적용할 수 있도록 돕습니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lobehub/lobehub/tree/main/skills/store-data-structures

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

store-data-structures은(는) 무엇을 하나요?

LobeHub Zustand 스토어 데이터 구조 패턴입니다. 스토어 상태, 리스트/세부 정보 분할, 정규화된 맵, 리듀서, messagesMap, topicsMap을 설계하거나 공유 타입 소스를 선택할 때 사용하세요.

주요 개념

  • 리스트/세부 정보 분할 (List/Detail Split): 데이터 목록과 개별 항목의 세부 정보를 분리하여 저장합니다. 이를 통해 목록 조회 시 필요한 최소한의 데이터만 가져오고, 세부 정보는 필요할 때 개별적으로 로드할 수 있습니다.

    • 예시: list: Item[], detailMap: Record<Id, Detail>
  • 정규화된 맵 (Normalized Map): 중복을 제거하고 ID 기반으로 데이터를 저장하여 빠른 조회와 업데이트를 가능하게 합니다.

    • 예시: entities: Record<Id, Entity>
  • 리듀서 (Reducer): 복잡한 상태 업데이트 로직을 순수 함수로 분리하여 스토어의 예측 가능성을 높입니다.

    • Zusstand의 set 함수와 함께 사용됩니다.
  • messagesMap / topicsMap: 채팅 메시지와 주제를 관리하기 위한 특수한 맵 구조입니다. 각각의 키는 세션 ID나 사용자 ID가 될 수 있습니다.

    • 예시: messagesMap: Record<SessionId, Message[]>

사용 예시 (TypeScript)

import { create } from 'zustand';

interface StoreState {
  list: string[];
  detailMap: Record<string, Detail>;
  messagesMap: Record<string, Message[]>;
  topicsMap: Record<string, Topic[]>;
  setList: (list: string[]) => void;
  addDetail: (id: string, detail: Detail) => void;
  addMessage: (sessionId: string, message: Message) => void;
}

const useStore = create<StoreState>((set) => ({
  list: [],
  detailMap: {},
  messagesMap: {},
  topicsMap: {},
  setList: (list) => set({ list }),
  addDetail: (id, detail) =>
    set((state) => ({
      detailMap: { ...state.detailMap, [id]: detail },
    })),
  addMessage: (sessionId, message) =>
    set((state) => ({
      messagesMap: {
        ...state.messagesMap,
        [sessionId]: [
          ...(state.messagesMap[sessionId] || []),
          message,
        ],
      },
    })),
}));

공유 타입 소스

타입 정의는 src/types 디렉토리에 공유하여 프로젝트 전체에서 일관성을 유지합니다. 예시:

// src/types/store.ts
export interface Detail {
  id: string;
  name: string;
  description?: string;
}

export interface Message {
  id: string;
  role: 'user' | 'assistant';
  content: string;
  timestamp: number;
}

export interface Topic {
  id: string;
  title: string;
  messages: Message[];
}

관련 리소스

Individual skills in this repo

This repo contains 19 individual skills — each has its own dedicated page.

lobehub/add-provider-doc

Add documentation for a new AI provider — usage docs, env vars, Docker config, image resources.

lobehub/add-setting-env

Add server-side environment variables that control default values for user settings.

lobehub/debug

Debug package usage guide. Use when adding debug logging, understanding log namespaces, or implementing debugging features. Triggers on debug logging requests or logging implementation.

lobehub/desktop

Electron desktop development guide — IPC handlers, controllers, preload scripts, window/menu management.

lobehub/drizzle

LobeHub Drizzle ORM schema and query style. Use for pgTable schemas, indexes, joins, inferred types, db.select/db.query, schema fields, foreign keys, junction tables, or postgres query patterns.

lobehub/hotkey

Add or edit LobeHub keyboard shortcuts. Use for HotkeyEnum, HOTKEYS_REGISTRATION, combineKeys, useHotkeyById, tooltip hotkeys, shortcut scope, conflicts, or Cmd/Ctrl key combos.

lobehub/i18n

LobeHub i18n with react-i18next. Use for user-facing strings, locale keys, namespaces, useTranslation, t(), interpolation, zh-CN/en-US previews, hardcoded UI copy, or pnpm i18n.

lobehub/linear

Linear issue management. Use for LOBE-xxx issues, Linear links, PRs referencing Linear, retrieving issues, updating status, completion comments, or sub-issue trees.

lobehub/lobehub

Use for public LobeHub website documentation under docs/**, including self-hosting, deployment, migration, and configuration guides. Excludes product changelogs and source-code API docs.

lobehub/microcopy

UI copy and microcopy guidelines. Use for user-facing copy, buttons, errors, empty states, onboarding, i18n wording, translation, or copy improvements in Chinese or English.

lobehub/modal

LobeHub imperative modal conventions. Use when creating or migrating modals, dialogs, popups, confirm flows, ModalHost wiring, createModal, confirmModal, useModalContext, or base-ui modal APIs.

lobehub/pr

Create a PR for the current branch (targets `canary` by default), including splitting one cross-layer branch into ordered stacked PRs so a lower layer (db / shared package / server TRPC) merges before its callers (desktop / CLI / UI). Use when the user asks to create / submit a PR, or to split a branch because clients call a server contract that isn't on the trunk yet. Triggers on 'pr', 'create pr', 'submit pr', 'open a PR', 'pull request', 'split this PR', 'stacked PR', 'backend should merge first', '提 PR', '提个 PR', '新建 PR', '拆 PR', '后端先合', '分层合并'.

lobehub/project-overview

LobeHub open-source monorepo architecture map. Use when locating code layers, understanding apps/packages/src layout, business stubs, project structure, or onboarding to the repository.

lobehub/react

LobeHub React component conventions. Use when editing TSX UI, choosing base-ui vs @lobehub/ui vs antd, styling with antd-style, routing, desktop variants, layouts, or component state.

lobehub/testing

Vitest testing guide. Use when writing or updating tests, fixing failing tests, improving coverage, debugging test issues, or setting up mocks.

lobehub/typescript

LobeHub TypeScript style and type-safety guide. Use when editing TS/TSX/MTS, fixing types, choosing interface vs type, avoiding any/object, import type, async flow, or ts-expect-error.

lobehub/upstash-workflow

LobeHub Upstash Workflow and QStash guide. Use for async workflows, process/paginate/execute fan-out, serve handlers, context.run/call/sleep, or workflow triggers.

lobehub/version-release

Version release workflow — release process and GitHub Release notes (not docs/changelog pages).

lobehub/zustand

LobeHub Zustand store conventions. Use when editing src/store, store slices, public/internal actions, dispatch actions, flattenActions, optimistic updates, selectors, maps, or class action migration.

관련 스킬