A storefront with an AI shopping assistant embedded in it, instrumented with Sentry agent tracing.
Built on the Next.js Commerce template
(MIT © Vercel, Inc. — see license.md), keeping its storefront UI intact.
- Storefront — Next.js Commerce on Next 16 (App Router, PPR,
use cache). Its Shopify data layer is replaced bylib/commerce, exposing the same functions and types, so every template component works unchanged. - Database —
lib/dbis Postgres (Neon), queried through Drizzle: 12 products, five collections, six customers, their orders, and payments.lib/db/schema.tsdefines the tables;scripts/db-seed.tsseeds them from the fixed catalog inlib/db/data.ts. - Assistant — a slide-over chat panel (AI Elements +
useChat) streaming fromapp/api/chat, which runsstreamTextagainst Claude Sonnet 5 through OpenRouter with four tools:searchProducts,getProduct,getAccountInfo, andrefundOrder. Tool results render as generative UI — product cards and an account card. The store has no sign-in;lib/demo-useris the one shopper. - The planted bug —
refundOrdercallsselectPaymentinlib/db/index.ts, which throws for orders placed before the payments system launched in June 2026: those orders have no row in thepaymentstable, because the backfill never ran. The debug prompt in../../PROMPTS.mdfinds it from the trace.
Requires Node.js >= 22. From the repo root:
./scripts/setup.shThis installs dependencies, provisions a free Postgres database on Neon (or
reuses DATABASE_URL if already set), seeds it, and asks for an OpenRouter
API key. By hand instead:
npm install
cp .env.example .env.local # fill in DATABASE_URL and OPENROUTER_API_KEY
npm run db:seednpm run devThen click the sparkles button (bottom right) and try "Find me a hoodie", "Where is my order?", "Refund my last order", or "Refund order 1029" (the planted bug above).
Set SENTRY_DSN and NEXT_PUBLIC_SENTRY_DSN in .env.local. One chat turn
becomes one trace: the POST /api/chat request as the root span, the Vercel
AI SDK model call and its tool calls as gen_ai spans with inputs, outputs,
and token counts, and a db span for each Postgres query.
sentry.server.config.ts turns on agent tracing and the pg integration.
app/api/chat/route.ts sets the demo user and the conversation id from the
request body, so the Agents view groups turns by conversation.
instrumentation-client.ts sets the same user in the browser and records a
session replay with the shopper's name and email masked, so a failed turn
links to what the shopper saw.