E-Commerce Agent Skill
Cart state with Zustand + persistence, product variants, Stripe checkout, inventory management, and order lifecycle.
The Skill
Full content, every format. Copy it, download it, or install with one command.
---
description: Cart state with Zustand + persistence, product variants, Stripe checkout, inventory management, and order lifecycle.
homepage: https://yepapi.com/skills/e-commerce
metadata:
tags: [e-commerce, cart, checkout, products]
---
# E-Commerce
## Rules
- Cart state: Zustand store with `localStorage` persistence — survives page refresh and tab close
- Product variants: model as separate SKUs with shared parent product — each variant has its own price, inventory, image
- Checkout: Stripe Checkout Sessions (server-side) — never send prices from the client
- Inventory: check stock server-side before creating checkout session — race condition protection with database transactions
- Order lifecycle: `pending` → `paid` → `shipped` → `delivered` — update via webhook events, not client actions
- Product listing: server-side filtering/sorting/pagination — URL search params for shareable filtered views
- Prices: store in cents (integers) — display with `Intl.NumberFormat` and currency code
- Cart operations: add, remove, update quantity, clear — validate stock on every cart action
## Patterns
\`\`\`ts
// Zustand cart store with persistence
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" }
)
);
\`\`\`
## Avoid
- Sending prices from the client to create checkout — always resolve prices server-side from your database
- Storing cart only in React state — use persisted Zustand or localStorage so cart survives refresh
- Deducting inventory on "add to cart" — only reserve stock at checkout, release on session expiry
- Updating order status from the client — use Stripe webhooks for `checkout.session.completed`
- Floating point for money — store as integers (cents), format for display onlyInstall
Why Use the E-Commerce Skill?
Without this skill, your AI guesses at e-commerce patterns. It might hallucinate deprecated APIs, use outdated conventions, or miss best practices entirely. With it, your AI follows a proven ruleset — every suggestion aligns with current standards.
Drop this skill into your project and your AI instantly knows the rules. Better code suggestions, fewer errors, faster shipping.
Try These Prompts
These prompts work better with the E-Commerce skill installed. Your AI knows the context and writes code that fits.
"Build a Zustand cart store with localStorage persistence and variant support"
"Create a Stripe Checkout integration with server-side price resolution and inventory checks"
"Implement an order lifecycle system with webhook-driven status updates"
Works Great With
E-Commerce skill — FAQ
It provides rules for Zustand cart state with localStorage persistence, product variant modeling, Stripe Checkout integration, inventory management with race condition protection, and order lifecycle tracking.
Run `npx skills add YepAPI/skills --skill e-commerce` in your project root. This copies the skill file into your repo where your AI coding tool can read it automatically.
Floating point arithmetic causes rounding errors with money (e.g., 0.1 + 0.2 !== 0.3). Storing prices as integers in cents avoids this entirely. Format with Intl.NumberFormat for display only.