Communitygithub.com

YepAPI/skills

Zustand + 永続化によるカート状態管理、商品バリアント、Stripe チェックアウト、在庫管理、注文ライフサイクル。

skills とは?

このスキルは、Zustand と localStorage の永続化を利用したカート状態管理、Stripe によるサーバーサイドチェックアウト、在庫管理、そして注文ライフサイクルを実装するための包括的なガイドを提供します。特に、クライアントから価格情報を送信しないセキュアなチェックアウト処理、データベーストランザクションによる競合状態の防止、Stripe の Webhook を利用したサーバーサイドでの注文ステータス更新など、セキュリティと信頼性を重視したパターンを提示します。また、商品バリアントを独立した SKU としてモデル化する方法や、お金の扱いにおける浮動小数点の回避など、実践的な設計原則もカバーしています。このスキルは Claude Code、Cursor、Codex などの AI エージェントプラットフォームで利用でき、開発者が E コマースアプリケーションのコア機能を迅速かつ堅牢に構築するのに役立ちます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/e-commerce

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

E コマース

ルール

  • カートの状態: localStorage 永続化付き Zustand ストア — ページのリフレッシュやタブの閉鎖後も保持されます
  • 商品バリアント: 共有の親商品を持つ独立した SKU としてモデル化 — 各バリアントは自身の価格、在庫、画像を持ちます
  • チェックアウト: Stripe Checkout Sessions (サーバーサイド) — クライアントから価格を送信しないでください
  • 在庫: チェックアウトセッションを作成する前にサーバーサイドで在庫を確認 — データベーストランザクションで競合状態を防止
  • 注文ライフサイクル: pending → paid → shipped → delivered — クライアントのアクションではなく Webhook イベントで更新
  • 商品一覧: サーバーサイドのフィルタリング/ソート/ページネーション — 共有可能なフィルタリング済みビュー用の 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 Webhook を使用してください
  • お金に浮動小数点を使用する — 整数 (セント) として保存し、表示用にのみフォーマットしてください

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.

関連スキル