# m-ahmedsajid/cartzi architecture

> Architecture diagram of the GitHub repository m-ahmedsajid/cartzi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/m-ahmedsajid/cartzi
- Repository: https://github.com/m-ahmedsajid/cartzi

## Overview

#### 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: [`src/sanity/lib/client.js`](https://github.com/m-ahmedsajid/cartzi/blob/master/src/sanity/lib/client.js) (Sanity query boundary), [`store.js`](https://github.com/m-ahmedsajid/cartzi/blob/master/store.js) (Persisted cart store), [`src/sanity/schemaTypes/productType.js`](https://github.com/m-ahmedsajid/cartzi/blob/master/src/sanity/schemaTypes/productType.js) (Sanity content store), [`src/app/(client)/layout.jsx`](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/layout.jsx) (Client shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Storefront"]
  node_shell["Client shell<br/>layout<br/>[layout.jsx]"]
  node_entry["Storefront routes<br/>[page.jsx]"]
  node_header["Header and footer<br/>navigation<br/>[Header.jsx]"]
  node_product_route["Product detail route<br/>[page.jsx]"]
  node_shop_route["Shop and filters route<br/>[page.jsx]"]
  node_discovery["Filter and product grid<br/>catalog UI<br/>[FilterClient.jsx]"]
  node_product_view["Product view<br/>product UI<br/>[ProductView.jsx]"]
  node_variants["Variant selection<br/>product UI"]
  node_cart_route["Cart page<br/>route<br/>[page.jsx]"]
  node_orders["Order detail route<br/>authenticated route<br/>[page.jsx]"]
end

subgraph group_cms["Sanity CMS"]
  node_sanity_client["Sanity query boundary<br/>CMS client<br/>[client.js]"]
  node_sanity[("Sanity content store<br/>headless CMS<br/>[productType.js]")]
  node_studio["Embedded Sanity Studio<br/>admin route<br/>[page.jsx]"]
  node_images["Sanity image bridge<br/>asset helper<br/>[image.js]"]
end

subgraph group_commerce["Commerce"]
  node_cart_store[("Persisted cart store<br/>Zustand state<br/>[store.js]")]
  node_checkout["Checkout session action<br/>server action"]
  node_stripe{{"Stripe<br/>payment provider<br/>[stripe.js]"}}
  node_webhook["Stripe webhook<br/>API route<br/>[route.js]"]
  node_discount_sync["Discount sync API<br/>API route<br/>[route.js]"]
end

node_next{{"Next.js App Router<br/>runtime"}}

node_next -->|"serves"| node_shell
node_shell -->|"wraps"| node_entry
node_shell -->|"composes"| node_header
node_header -->|"discovery navigation"| node_shop_route
node_entry -->|"links to"| node_product_route
node_shop_route -->|"renders"| node_discovery
node_discovery -->|"loads catalog"| node_sanity_client
node_product_route -->|"resolves slug"| node_sanity_client
node_product_route -->|"renders"| node_product_view
node_product_view -->|"selects"| node_variants
node_product_view -->|"renders assets"| node_images
node_variants -->|"adds valid variant"| node_cart_store
node_header -->|"cart indicator"| node_cart_store
node_cart_route -->|"reads and mutates"| node_cart_store
node_cart_store -->|"checkout context"| node_checkout
node_checkout -->|"creates session"| node_stripe
node_stripe -->|"payment event"| node_webhook
node_webhook -->|"reconciles order"| node_sanity
node_orders -->|"loads order"| node_sanity_client
node_sanity_client -->|"queries"| node_sanity
node_studio -->|"administers"| node_sanity
node_discount_sync -->|"synchronizes discounts"| node_sanity

click node_shell "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/layout.jsx"
click node_entry "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/page.jsx"
click node_header "https://github.com/m-ahmedsajid/cartzi/blob/master/src/components/layout/Header/Header.jsx"
click node_product_route "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/product/%5Bslug%5D/page.jsx"
click node_shop_route "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/(filter)/shop/page.jsx"
click node_discovery "https://github.com/m-ahmedsajid/cartzi/blob/master/src/components/filters/FilterClient.jsx"
click node_product_view "https://github.com/m-ahmedsajid/cartzi/blob/master/src/components/product/ProductView.jsx"
click node_variants "https://github.com/m-ahmedsajid/cartzi/blob/master/src/components/product/VariantsSelection.jsx"
click node_cart_store "https://github.com/m-ahmedsajid/cartzi/blob/master/store.js"
click node_cart_route "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/cart/page.jsx"
click node_checkout "https://github.com/m-ahmedsajid/cartzi/blob/master/src/actions/createCheckoutSession.js"
click node_stripe "https://github.com/m-ahmedsajid/cartzi/blob/master/src/lib/stripe.js"
click node_webhook "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/api/stripe/webhook/route.js"
click node_orders "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/orders/%5Bid%5D/page.jsx"
click node_sanity_client "https://github.com/m-ahmedsajid/cartzi/blob/master/src/sanity/lib/client.js"
click node_sanity "https://github.com/m-ahmedsajid/cartzi/blob/master/src/sanity/schemaTypes/productType.js"
click node_studio "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/studio/%5B%5B...tool%5D%5D/page.jsx"
click node_discount_sync "https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/api/sync-discount/route.js"
click node_images "https://github.com/m-ahmedsajid/cartzi/blob/master/src/sanity/lib/image.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shell,node_entry,node_header,node_product_route,node_shop_route,node_discovery,node_product_view,node_variants,node_cart_route,node_orders toneBlue
class node_sanity_client,node_sanity,node_studio,node_images toneAmber
class node_cart_store,node_checkout,node_stripe,node_webhook,node_discount_sync toneMint
class node_next toneNeutral
```

## Components

### Storefront

- [Client shell](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/layout.jsx): layout · `src/app/(client)/layout.jsx`
- [Storefront routes](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/page.jsx): routes · Home, product, shop, cart, search, and customer pages. · `src/app/(client)/page.jsx`
- [Header and footer](https://github.com/m-ahmedsajid/cartzi/blob/master/src/components/layout/Header/Header.jsx): navigation · `src/components/layout/Header/Header.jsx`
- [Product detail route](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/product/%5Bslug%5D/page.jsx): route · `src/app/(client)/product/[slug]/page.jsx`
- [Shop and filters route](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/(filter)/shop/page.jsx): route · `src/app/(client)/(filter)/shop/page.jsx`
- [Filter and product grid](https://github.com/m-ahmedsajid/cartzi/blob/master/src/components/filters/FilterClient.jsx): catalog UI · `src/components/filters/FilterClient.jsx`
- [Product view](https://github.com/m-ahmedsajid/cartzi/blob/master/src/components/product/ProductView.jsx): product UI · Composes gallery, variants, pricing, reviews, and actions. · `src/components/product/ProductView.jsx`
- [Variant selection](https://github.com/m-ahmedsajid/cartzi/blob/master/src/components/product/VariantsSelection.jsx): product UI · Selects SKU, price override, and inventory constraints. · `src/components/product/VariantsSelection.jsx`
- [Cart page](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/cart/page.jsx): route · `src/app/(client)/cart/page.jsx`
- [Order detail route](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/(client)/orders/%5Bid%5D/page.jsx): authenticated route · Renders orders with client actions and invoice support. · `src/app/(client)/orders/[id]/page.jsx`

### Sanity CMS

- [Sanity query boundary](https://github.com/m-ahmedsajid/cartzi/blob/master/src/sanity/lib/client.js): CMS client · Queries and transforms CMS data for app consumers. · `src/sanity/lib/client.js`
- [Sanity content store](https://github.com/m-ahmedsajid/cartzi/blob/master/src/sanity/schemaTypes/productType.js): headless CMS · System of record for catalog, orders, discounts, and content. · `src/sanity/schemaTypes/productType.js`
- [Embedded Sanity Studio](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/studio/%5B%5B...tool%5D%5D/page.jsx): admin route · `src/app/studio/[[...tool]]/page.jsx`
- [Sanity image bridge](https://github.com/m-ahmedsajid/cartzi/blob/master/src/sanity/lib/image.js): asset helper · Builds CMS image assets for storefront rendering. · `src/sanity/lib/image.js`

### Commerce

- [Persisted cart store](https://github.com/m-ahmedsajid/cartzi/blob/master/store.js): Zustand state · Owns variant line items, quantities, totals, and stock validation. · `store.js`
- [Checkout session action](https://github.com/m-ahmedsajid/cartzi/blob/master/src/actions/createCheckoutSession.js): server action · Converts cart and order context into Stripe Checkout. · `src/actions/createCheckoutSession.js`
- [Stripe](https://github.com/m-ahmedsajid/cartzi/blob/master/src/lib/stripe.js): payment provider · `src/lib/stripe.js`
- [Stripe webhook](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/api/stripe/webhook/route.js): API route · Payment-provider trust boundary for reconciliation. · `src/app/api/stripe/webhook/route.js`
- [Discount sync API](https://github.com/m-ahmedsajid/cartzi/blob/master/src/app/api/sync-discount/route.js): API route · `src/app/api/sync-discount/route.js`

### Other components

- **Next.js App Router**: runtime · Serves SSR routes, route handlers, and server actions.

## Connections

- 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
