Communitygithub.com

YepAPI/skills

Zustand 기반 장바구니 상태 관리 (localStorage 지속성), 제품 변형, Stripe 체크아웃, 재고 관리 및 주문 생애주기.

skills란 무엇인가요?

이 스킬은 Zustand와 localStorage를 활용한 장바구니 상태 관리부터 Stripe 체크아웃, 재고 관리, 주문 생애주기까지 전자상거래의 핵심 기능을 구현합니다. 제품 변형은 개별 SKU로 모델링되며 각 변형마다 고유한 가격, 재고, 이미지를 가집니다. 주문 생애주기는 `pending` → `paid` → `shipped` → `delivered` 순서로 진행되며, Stripe 웹훅을 통해 안전하게 업데이트됩니다. 가격은 센트 단위 정수로 저장하여 정확성을 보장하고, `Intl.NumberFormat`으로 사용자에게 표시합니다. 서버 측에서 재고를 검증한 후에만 체크아웃 세션을 생성하여 경쟁 조건을 방지하며, 데이터베이스 트랜잭션을 통해 데이터 무결성을 유지합니다. 이 스킬은 Next.js, React, TypeScript 환경에서 Claude Code, Cursor, Codex 등과 함께 사용하기에 적합합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/e-commerce

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

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

문서

전자상거래

규칙

  • 장바구니 상태: localStorage 지속성을 가진 Zustand 스토어 — 페이지 새로고침 및 탭 닫기 시에도 유지됨
  • 제품 변형: 공유 부모 제품을 가진 별도 SKU로 모델링 — 각 변형에는 자체 가격, 재고, 이미지가 있음
  • 체크아웃: Stripe Checkout Sessions (서버 측) — 클라이언트에서 가격을 전송하지 않음
  • 재고: 체크아웃 세션 생성 전 서버 측에서 재고 확인 — 데이터베이스 트랜잭션으로 경쟁 조건 보호
  • 주문 생애주기: pending → paid → shipped → delivered — 클라이언트 동작이 아닌 웹훅 이벤트를 통해 업데이트
  • 제품 목록: 서버 측 필터링/정렬/페이지네이션 — 공유 가능한 필터링된 뷰를 위한 URL 검색 매개변수
  • 가격: 센트(정수)로 저장 — Intl.NumberFormat 및 통화 코드로 표시
  • 장바구니 작업: 추가, 제거, 수량 업데이트, 비우기 — 모든 장바구니 작업 시 재고 검증

패턴

// 지속성이 있는 Zustand 장바구니 스토어
import { create } from "zustand";
import { persist } from "zustand/middleware";

interface CartItem { productId: string; variantId: string; quantity: number; price: number; }
interface CartStore {
  items: CartItem[];
  addItem: (item: CartItem) => void;
  removeItem: (variantId: string) => void;
  updateQuantity: (variantId: string, quantity: number) => void;
  clear: () => void;
  total: () => number;
}

export const useCart = create<CartStore>()(
  persist(
    (set, get) => ({
      items: [],
      addItem: (item) => set((state) => {
        const existing = state.items.find((i) => i.variantId === item.variantId);
        if (existing) {
          return { items: state.items.map((i) =>
            i.variantId === item.variantId ? { ...i, quantity: i.quantity + item.quantity } : i
          )};
        }
        return { items: [...state.items, item] };
      }),
      removeItem: (variantId) => set((s) => ({ items: s.items.filter((i) => i.variantId !== variantId) })),
      updateQuantity: (variantId, quantity) => set((s) => ({
        items: quantity <= 0
          ? s.items.filter((i) => i.variantId !== variantId)
          : s.items.map((i) => (i.variantId === variantId ? { ...i, quantity } : i)),
      })),
      clear: () => set({ items: [] }),
      total: () => get().items.reduce((sum, i) => sum + i.price * i.quantity, 0),
    }),
    { name: "cart-storage" }
  )
);

피해야 할 것

  • 클라이언트에서 가격을 보내 체크아웃 생성 — 항상 데이터베이스에서 서버 측 가격을 확인
  • 장바구니를 React 상태에만 저장 — 지속성이 있는 Zustand 또는 localStorage를 사용하여 새로고침 시 장바구니 유지
  • "장바구니에 추가" 시 재고 차감 — 체크아웃 시에만 재고 예약, 세션 만료 시 해제
  • 클라이언트에서 주문 상태 업데이트 — checkout.session.completed에 대해 Stripe 웹훅 사용
  • 돈에 부동 소수점 사용 — 정수(센트)로 저장, 표시용으로만 포맷

Individual skills in this repo

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

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

관련 스킬