by Noor Mohammad
February 27, 2026

Building an e-commerce platform from scratch is one of the most challenging undertakings in web development. You need to handle complex product catalogs, user authentication, payment processing, internationalization, SEO, state management, and a secure admin dashboard—all while delivering a blazing-fast, beautiful, and responsive user experience.
Enter ShopCart Pro: a production-ready e-commerce platform that tackles all of these challenges using the latest and greatest in the React ecosystem. Built on Next.js 16, React 19, TypeScript 5.7, Sanity CMS, Clerk Authentication, Stripe Payments, and Tailwind CSS 4, it serves as a blueprint for how modern e-commerce applications should be architected.
In this deep dive, we'll walk through the architecture, best practices, and critical code patterns that make ShopCart Pro a robust, scalable, and maintainable platform. Whether you're building your own store or looking to master advanced Next.js patterns, there's something here for every developer.
🔗 Live Demo | 📺 YouTube Tutorial | 💎 Get Source Code
Before diving into the implementation, let's break down the full technology stack powering ShopCart Pro:
One of the most critical architectural decisions in ShopCart Pro is how the application is structured using Next.js Route Groups.
The app/[lang] directory is divided into distinct user roles:
1app/[lang]/
2├── (client)/ → Customer-facing pages (shop, cart, checkout, wishlist)
3├── (admin)/ → Admin dashboard (analytics, orders, products, users)
4├── (employee)/ → Employee portal (assigned orders, tasks)
5├── (auth)/ → Authentication pages (sign-in, sign-up)
6├── layout.tsx → Root layout with ClerkProvider, fonts, and metadata
7└── not-found.tsx → Custom 404 pageWhy This Matters: Route groups (parenthesized folders) in Next.js don't affect the URL structure—they're purely organizational.
Best Practice: Always use route groups to organize your Next.js app by user role or domain concern, not by file type.
ShopCart Pro supports 5 languages out of the box (English, French, Italian, Hindi, and Arabic) including RTL support. The configuration uses an as const assertion to create a strict union type ("en" | "it" | "fr" | "hi" | "ar") that provides compile-time safety across the entire application.
Middleware-Level Locale Detection The middleware handles automatic locale detection using the Accept-Language header, transparently redirecting users from /shop to their preferred locale like /en/shop or /ar/shop.
Dictionary-Based Translations Translations are kept in flat JSON files (e.g., en.json, ar.json) loaded server-side.
Best Practice: Keeping translations in flat JSON files and loading them via React Server Components avoids shipping a heavy i18n runtime to the client, resulting in zero-JS translation rendering.
ShopCart Pro uses Clerk for drop-in authentication. What makes this implementation exemplary is how authentication is cleanly wired into the middleware alongside i18n.
1// proxy.ts — Route protection
2const isProtectedRoute = createRouteMatcher([
3 "/user(.*)", "/cart(.*)", "/wishlist(.*)", "/checkout(.*)", "/admin(.*)",
4 "/:locale/user(.*)", "/:locale/cart(.*)", "/:locale/admin(.*)",
5]);
6export default clerkMiddleware(async (auth, req) => {
7 // First: Handle i18n locale redirect logic...
8 // Then: Protect routes requiring authentication
9 if (isProtectedRoute(req)) {
10 await auth.protect();
11 }
12});
13Best Practice: Always handle i18n redirects before auth guards in your middleware. This ensures unauthenticated users are seamlessly redirected to the properly localized sign-in page.
The cart is the heart of e-commerce. ShopCart Pro uses Zustand with persistence middleware to create a cart that survives page refreshes and browser sessions.
1// store.ts — Cart store with Zustand
2import { create } from "zustand";
3import { persist } from "zustand/middleware";
4interface StoreState {
5 items: CartItem[];
6 addItem: (product: Product) => void;
7 // ...other actions and state
8}
9const useCartStore = create<StoreState>()(
10 persist(
11 (set, get) => ({
12 items: [],
13 addItem: (product) => set((state) => { /* logic */ }),
14 }),
15 { name: "cart-store" } // Saves to localStorage
16 )
17);
18Best Practice: Use a single Zustand store with typed interfaces for related client-side state. The persist middleware is essential for e-commerce—never rely on temporary session storage for cart data.ShopCart Pro uses Sanity as a headless CMS. The product schema is a masterclass in content modeling, utilizing schema-level validation (ensuring prices are never negative), read-only computed fields (like average ratings calculated by server actions), and rich preview configurations.
Best Practice: Define strict validation rules and rich visual previews in your CMS schemas. The content editor's experience is just as important as the developer's!
SEO is built into the architecture from the ground up.
app/sitemap.ts) by fetching real-time product, category, and brand data directly from Sanity.title.template ("%s | ShopCart"), OpenGraph tags, and strict robot indexing instructions.ShopCart Pro extensively uses Next.js Server Actions to handle data mutations, completely bypassing the need for traditional REST API endpoints. Actions are strictly organized by domain in the actions/ directory (e.g., userActions.ts, orderEmployeeActions.ts, reviewActions.ts).
Best Practice: Organize server actions by business domain, not by technical layer. This keeps sensitive logic secure on the server while maintaining end-to-end TypeScript safety.
To avoid layout shifts (CLS) and external network requests, fonts are self-hosted using next/font/local.
1// app/[lang]/layout.tsx
2const poppins = localFont({
3 src: "../fonts/Poppins.woff2",
4 variable: "--font-poppins",
5});Best Practice: Self-host fonts in WOFF2 format and apply them via CSS variables for maximum performance and a flawless first paint.Getting the project running locally is fast thanks to Turbopack:
1git clone https://github.com/noorjsdivs/shopcartpro-yt.git
2cd shopcartpro
3pnpm install
4cp .env.example .env # Add Sanity, Clerk, Stripe & Firebase keys
5pnpm dev # Starts dev server with Turbopack
6(All required external services—Sanity, Clerk, Stripe, Firebase—offer generous free tiers perfect for development).
ShopCart Pro isn't just an e-commerce template—it's a production-grade architecture reference for building modern, full-stack web applications with Next.js 16. Every decision, from route groups and Zustand persistence to Sanity schema design, reflects real-world best practices designed to scale.
Ready to build your own store? 🔗 Live Demo | 📺 YouTube Tutorial | 💎 Get Source Code
Discussion (0)
Please sign in to join the conversation