How ajmalajjuca/storefront works
Purpose and Runtime
This is a server-rendered, headless Shopify storefront built with Next.js App Router and React Server Components. It is intended for Vercel deployment, with Shopify Storefront API credentials and revalidation secret supplied through environment variables. The main application shell begins at app/layout.tsx; storefront entry routes include app/(browser)/page.tsx and product, collection, editorial, and policy routes under app/.
Routing, Rendering, and SEO
App Router pages render catalog and content views on the server, with client islands where interaction is required. Key route families are product detail at app/products/[handle]/page.tsx, collections/products indexes at app/indexes/collections/page.tsx and app/indexes/products/page.tsx, and editorial stories at app/story/[slug]/page.tsx. Search-engine discovery is generated by app/sitemap.ts and app/robots.ts; global failures are handled by app/error.tsx.
Commerce Provider Boundary
lib/shopify/ is the provider adapter boundary: it contains the Shopify client and domain-facing types in lib/shopify/index.ts and lib/shopify/types.ts, reusable GraphQL fragments in lib/shopify/fragments/, and operation definitions in lib/shopify/queries/ and lib/shopify/mutations/. Pages and components should consume this layer rather than issue Storefront API calls directly, enabling a provider replacement without broadly changing UI code.
Catalog and Content Flow
Route handlers/pages resolve a product handle, collection, page, policy, or metaobject; query modules retrieve it from Shopify; server components transform that data into catalog and editorial UI. Product-facing rendering is centered on app/products/[handle]/page.tsx with interactive variant/purchase behavior in app/products/[handle]/product-client.tsx. Shared product display primitives include components/product-card/index.tsx, components/product-rail/index.tsx, and components/collection-showcase/index.tsx.
Cart and Checkout State
The cart is a client-side context backed by Shopify cart mutations. components/cart/cart-context.tsx owns cart state and optimistic updates, while components/cart/actions.ts invokes server-side cart operations represented in lib/shopify/mutations/cart.ts. The drawer UI at components/cart/drawer.tsx consumes that state; Shopify remains authoritative for cart identity, lines, prices, and checkout progression.
Personalization and Browser-State Features
Client contexts manage preferences that should not alter Shopify source data: currency selection/exchange-rate display is implemented in components/currency/currency-preference-context.tsx, components/currency/exchange-rates-context.tsx, and components/currency/use-display-money.ts. Wishlist persistence and controls are isolated in components/wishlist/wishlist-context.tsx and app/wishlist/wishlist-client.tsx. The browser-specific shell is separated under app/(browser)/layout.tsx.
Invalidation, Domains, and External Interfaces
Shopify-triggered cache invalidation enters through app/api/revalidate/route.ts, protected by a revalidation secret, allowing catalog/content changes to refresh rendered routes. middleware.ts and lib/domain-redirects.ts define request-level domain routing/redirect behavior; snippets/shopify-theme-domain-redirect.liquid supports corresponding behavior from the Shopify theme. Newsletter and prebook submissions use server actions at components/newsletter/actions.ts and app/prebook/[handle]/notify-form.tsx, forming explicit server-side integration boundaries.
Main entry points: layout.tsx Browser shell · index.ts Shopify adapter · page.tsx Product detail · cart-context.tsx Cart state
Components 20
App Routing
Server-rendered storefront routes and discovery.
- Application shell
app/layout.tsx - Browser shell
app/(browser)/layout.tsx - Storefront entry
app/(browser)/page.tsx - Product detail
app/products/[handle]/page.tsx - Catalog indexes · Collection and product listing pages.
app/indexes/collections/page.tsx - Editorial story
app/story/[slug]/page.tsx - SEO discovery · Sitemap and robots generation.
app/sitemap.ts - Product display primitives · Cards, rails, and collection showcases.
components/product-card/index.tsx
Commerce Boundary
Shopify adapter and Storefront API operations.
- Shopify adapter · UI-facing commerce access boundary.
lib/shopify/index.ts - Commerce types
lib/shopify/types.ts - GraphQL operations · Uses reusable fragments for Storefront API operations.
- Shopify Storefront API · Authoritative catalog, cart, and checkout service.
Client State
Interactive browser contexts and UI islands.
- Variant and purchase UI
app/products/[handle]/product-client.tsx - Cart state · Owns optimistic cart state.
components/cart/cart-context.tsx - Cart server actions
components/cart/actions.ts - Cart drawer
components/cart/drawer.tsx - Browser preferences · Currency display and persistent wishlist state.
components/currency/currency-preference-context.tsx
External Interfaces
Invalidation, domain, and submission boundaries.
- Cache invalidation · Secret-protected Shopify-triggered revalidation.
app/api/revalidate/route.ts - Domain routing · Request redirects coordinated with the Shopify theme.
middleware.ts - Submission actions · Newsletter and prebook submission boundary.
components/newsletter/actions.ts
Connections 22
- Application shell → Browser shell: wraps
- Browser shell → Storefront entry: renders
- Browser shell → Product detail: routes to
- Browser shell → Catalog indexes: routes to
- Browser shell → Editorial story: routes to
- Product detail → Shopify adapter: loads product
- Catalog indexes → Shopify adapter: loads catalog
- Editorial story → Shopify adapter: loads content
- SEO discovery → Shopify adapter: discovers routes
- Shopify adapter → Commerce types: uses
- Shopify adapter → GraphQL operations: executes
- GraphQL operations → Shopify Storefront API: Storefront API
- Product detail → Variant and purchase UI: hydrates interaction
- Product detail → Product display primitives: composes
- Variant and purchase UI → Cart state: adds variants
- Cart drawer → Cart state: consumes
- Cart state → Cart server actions: persists changes
- Cart server actions → GraphQL operations: cart mutations
- Browser shell → Browser preferences: provides
- Cache invalidation → Shopify adapter: refreshes cached data
- Domain routing → Browser shell: routes requests
- Submission actions → Shopify Storefront API: server-side integration