How m-ahmedsajid/cartzi works
Purpose and Runtime
Cartzi is a Next.js 15 App Router fashion-commerce application. It combines a Sanity headless CMS for catalog/content, Clerk authentication, Stripe checkout/payment events, and a persistent browser cart. The primary application shell is src/app/(client)/layout.jsx; storefront entry routes begin at src/app/(client)/page.jsx.
Storefront Routing and Composition
Route groups separate customer storefront concerns from embedded CMS administration. Product, collection/filter, search, cart, order, checkout-success, and informational pages are server/client route compositions under src/app/(client).
• src/app/(client)/product/[slug]/page.jsx
• src/app/(client)/(filter)/shop/page.jsx
• src/app/(client)/cart/page.jsx
The shared header/footer and navigation mediate discovery, search, cart access, and responsive navigation.
• src/components/layout/Header/Header.jsx
• src/components/layout/Footer.jsx
Catalog Read Model and Sanity Boundary
Sanity is the system of record for products, categories, variants, orders, reviews, discounts, shipping rules, and marketing/navigation content. App-facing query and transformation helpers isolate CMS access from route/component rendering.
• src/sanity/lib/client.js
• src/sanity/helpers/product.js
• src/sanity/schemaTypes/productType.js
The embedded Studio is served inside the Next application, while Studio configuration and custom publishing/sync behavior live outside storefront components.
• src/app/studio/[[...tool]]/page.jsx
• sanity.config.js
• src/sanity/structure.js
Seed/importable CMS data is supplied as NDJSON rather than application-owned database migrations.
• data/products.ndjson
• data/categories.ndjson
Product Discovery and Detail Flow
Home, category hierarchy, shop, and keyword-search routes obtain catalog data through Sanity helpers, then render reusable filter/grid/card surfaces. Product-detail routes resolve a slug and hand the product model to gallery, variant, pricing, review, and action modules.
• src/components/filters/FilterClient.jsx
• src/components/filters/ProductGrid.jsx
• src/components/product/ProductView.jsx
Variant selection determines SKU, price override, and inventory constraints before an item enters the cart.
• src/components/product/VariantsSelection.jsx
• src/components/product/ProductActions.jsx
• src/components/product/PriceDisplay.jsx
Client Commerce State
A root Zustand store owns persisted cart state, quantity mutations, variant-distinct line items, subtotal calculation, and stock validation. Interactive cart indicators, product actions, cart page, and reset behavior consume this client-side boundary rather than directly editing Sanity.
• store.js
• src/components/product/CartIcon.jsx
• src/app/(client)/cart/CartPage.jsx
Wishlist and search are storefront interaction surfaces; the README establishes cart persistence but does not establish a separate durable wishlist backend.
• src/components/product/WishlistButton.jsx
• src/components/SearchDialog.jsx
Checkout, Orders, and Payment Reconciliation
Checkout begins with a server action that converts cart/order context into a Stripe Checkout session. Stripe then calls the webhook route, which is the payment-provider trust boundary; discount synchronization has a separate API route. Orders are rendered under authenticated user-oriented routes and include client-side order actions/invoice support.
• src/actions/createCheckoutSession.js
• src/app/api/stripe/webhook/route.js
• src/app/api/sync-discount/route.js
• src/app/(client)/orders/[id]/page.jsx
• src/lib/generate-invoice.js
• src/lib/stripe.js
Infrastructure and Presentation
Next.js provides SSR/route handling and API endpoints; React client components power cart, gallery, filters, and order interactions. Tailwind/shadcn/Radix provide the UI foundation, with Framer Motion and Embla used for motion/gallery-carousel experiences. Sanity image tooling bridges CMS assets to optimized storefront rendering.
• src/app/globals.css
• src/components/product/ImageGallery.jsx
• src/sanity/lib/image.js
Main entry points: client.js Sanity query boundary · store.js Persisted cart store · productType.js Sanity content store · layout.jsx Client shell
Components 20
Storefront
- Client shell
src/app/(client)/layout.jsx - Storefront routes · Home, product, shop, cart, search, and customer pages.
src/app/(client)/page.jsx - Header and footer
src/components/layout/Header/Header.jsx - Product detail route
src/app/(client)/product/[slug]/page.jsx - Shop and filters route
src/app/(client)/(filter)/shop/page.jsx - Filter and product grid
src/components/filters/FilterClient.jsx - Product view · Composes gallery, variants, pricing, reviews, and actions.
src/components/product/ProductView.jsx - Variant selection · Selects SKU, price override, and inventory constraints.
src/components/product/VariantsSelection.jsx - Cart page
src/app/(client)/cart/page.jsx - Order detail route · Renders orders with client actions and invoice support.
src/app/(client)/orders/[id]/page.jsx
Sanity CMS
- Sanity query boundary · Queries and transforms CMS data for app consumers.
src/sanity/lib/client.js - Sanity content store · System of record for catalog, orders, discounts, and content.
src/sanity/schemaTypes/productType.js - Embedded Sanity Studio
src/app/studio/[[...tool]]/page.jsx - Sanity image bridge · Builds CMS image assets for storefront rendering.
src/sanity/lib/image.js
Commerce
- Persisted cart store · Owns variant line items, quantities, totals, and stock validation.
store.js - Checkout session action · Converts cart and order context into Stripe Checkout.
src/actions/createCheckoutSession.js - Stripe
src/lib/stripe.js - Stripe webhook · Payment-provider trust boundary for reconciliation.
src/app/api/stripe/webhook/route.js - Discount sync API
src/app/api/sync-discount/route.js
Other components
- Next.js App Router · Serves SSR routes, route handlers, and server actions.
Connections 22
- Next.js App Router → Client shell: serves
- Client shell → Storefront routes: wraps
- Client shell → Header and footer: composes
- Header and footer → Shop and filters route: discovery navigation
- Storefront routes → Product detail route: links to
- Shop and filters route → Filter and product grid: renders
- Filter and product grid → Sanity query boundary: loads catalog
- Product detail route → Sanity query boundary: resolves slug
- Product detail route → Product view: renders
- Product view → Variant selection: selects
- Product view → Sanity image bridge: renders assets
- Variant selection → Persisted cart store: adds valid variant
- Header and footer → Persisted cart store: cart indicator
- Cart page → Persisted cart store: reads and mutates
- Persisted cart store → Checkout session action: checkout context
- Checkout session action → Stripe: creates session
- Stripe → Stripe webhook: payment event
- Stripe webhook → Sanity content store: reconciles order
- Order detail route → Sanity query boundary: loads order
- Sanity query boundary → Sanity content store: queries
- Embedded Sanity Studio → Sanity content store: administers
- Discount sync API → Sanity content store: synchronizes discounts