Skip to content

Repository files navigation

🛍️ E-Commerce Store UI

A modern, responsive storefront built with Next.js 16, React 19, and Tailwind CSS 4. Features a complete shopping experience including product browsing, cart management, Stripe checkout, order history, and secure authentication via NextAuth.


📋 Table of Contents


✨ Features

FeatureDescription
🔐 AuthenticationLogin & register with NextAuth (Credentials provider + JWT strategy)
🛡️ Route ProtectionMiddleware-based auth guard — unauthenticated users redirected to /login
🏠 HomepageProduct slider showcasing new arrivals via Embla Carousel
🛍️ Product CatalogBrowse all products with individual product detail pages
Ratings & ReviewsInteractive star-rating component for product reviews
🛒 Shopping CartAdd/remove items, update quantities, view cart summary
💳 Stripe CheckoutSecure payment with Stripe Elements integration
📦 Order ManagementView order history and order details
🌙 Dark ModeDark-themed UI with Tailwind CSS
🔔 Toast NotificationsUser feedback via Sonner toast library
📱 Responsive DesignMobile-friendly layout with container-based responsive design
TurbopackFast dev server powered by Next.js Turbopack bundler
🧠 React CompilerEnabled React Compiler for automatic optimizations

🛠️ Tech Stack

TechnologyVersionPurpose
Next.js16.2.7React framework with App Router + Turbopack
React19.2.4UI library
TypeScript5.xType safety
Tailwind CSS4.xUtility-first CSS
NextAuth4.24.14Authentication (Credentials + JWT)
Stripe Elements9.x / 6.xPayment UI components
shadcn/ui4.xAccessible, customizable UI component library
Axios1.17.xHTTP client for API calls
Embla Carousel8.xProduct image carousel
Sonner2.xToast notifications
Lucide React1.xIcon library
Remix Icon4.xAdditional icon library
next-themes0.4.xTheme management

Fonts

  • Noto Sans — Primary sans-serif font
  • Geist Sans — Secondary sans-serif font
  • Geist Mono — Monospace font

🏛️ Architecture

┌──────────────────────────────────────────────────┐
│ Client Browser │
└────────────────────────┬─────────────────────────┘
│
┌──────────────▼──────────────┐
│ Next.js 16 App │
│ (localhost:3000) │
│ │
│ ┌────────────────────────┐ │
│ │ App Router │ │
│ │ ┌─ layout.tsx │ │
│ │ ├─ page.tsx (Home) │ │
│ │ ├─ /login │ │
│ │ ├─ /register │ │
│ │ ├─ /products │ │
│ │ ├─ /products/[id] │ │
│ │ ├─ /cart │ │
│ │ ├─ /check-out │ │
│ │ └─ /orders │ │
│ └────────────────────────┘ │
│ │
│ ┌────────────────────────┐ │
│ │ Middleware │ │
│ │ (proxy.ts) │ │
│ │ Route protection via │ │
│ │ NextAuth withAuth() │ │
│ └────────────────────────┘ │
│ │
│ ┌────────────────────────┐ │
│ │ API Client Layer │ │
│ │ (src/api/) │ │
│ │ Axios + auto-attach │ │
│ │ JWT from session │ │
│ └───────────┬────────────┘ │
└──────────────┼──────────────┘
│ HTTP / REST
┌──────────────▼──────────────┐
│ NestJS Backend API │
│ (localhost:4000/api/v1) │
└─────────────────────────────┘

Key Architectural Decisions

  1. Server & Client Components — Pages use Next.js server components by default; interactive widgets (forms, carousels, cart actions) are client components
  2. API Proxy Layer — A configured Axios instance (apiClient.ts) auto-attaches the JWT from the NextAuth session on every request, supporting both server-side (getServerSession) and client-side (getSession) contexts
  3. Middleware Route Protectionproxy.ts uses NextAuth's withAuth middleware to protect all routes except /login, /register, and public Next.js internals
  4. Cloudinary Image Supportnext.config.ts whitelists Cloudinary, Unsplash, and Pixabay domains for next/image optimization

📁 Project Structure

store_ui/
├── src/
│ ├── app/ # Next.js App Router pages
│ │ ├── layout.tsx # Root layout (Providers, NavBar, Toaster)
│ │ ├── globals.css # Global styles (Tailwind + custom CSS)
│ │ ├── page.tsx # Homepage — new arrivals slider
│ │ ├── login/ # Login page
│ │ │ ├── page.tsx # Server component entry
│ │ │ └── login-form.tsx # Client component — login form UI
│ │ ├── register/ # Registration page
│ │ ├── products/ # Product pages
│ │ │ ├── page.tsx # Product listing
│ │ │ └── [productId]/ # Dynamic product detail route
│ │ ├── cart/ # Shopping cart page
│ │ ├── check-out/ # Checkout page with Stripe payment
│ │ ├── orders/ # Order history page
│ │ └── api/auth/[...nextauth]/ # NextAuth route handler
│ │ └── route.ts
│ │
│ ├── components/ # Reusable UI components
│ │ ├── NavBar.tsx # Main navigation bar
│ │ ├── providers.tsx # SessionProvider wrapper (client component)
│ │ ├── rating.tsx # Interactive star rating component
│ │ ├── rating-basic.tsx # Basic (display-only) star rating
│ │ ├── products/ # Product-related components
│ │ │ ├── Product_item.tsx # Product card component
│ │ │ ├── products_slider.jsx # Product carousel (Embla)
│ │ │ └── AddToCart.tsx # Add-to-cart button with API call
│ │ ├── cart/ # Cart-related components
│ │ │ ├── CartItems.tsx # Cart items list
│ │ │ ├── cartItemCard.tsx # Individual cart item card
│ │ │ ├── PlaceOrder.tsx # Place order summary & action
│ │ │ ├── CheckOutForm.tsx # Checkout form wrapper
│ │ │ ├── PaymentDioalog.tsx # Stripe payment dialog
│ │ │ └── orderItem.tsx # Order item display card
│ │ └── ui/ # shadcn/ui component library
│ │
│ ├── api/ # API client layer (Axios)
│ │ ├── apiClient.ts # Configured Axios instance + JWT interceptor
│ │ ├── authApi.ts # Auth API calls (register, etc.)
│ │ ├── productsApi.ts # Product API calls
│ │ ├── cartApi.ts # Cart API calls
│ │ ├── orderApi.ts # Order API calls
│ │ ├── userApi.ts # User API calls
│ │ └── handelError.ts # Centralized error handler
│ │
│ ├── lib/ # Utility libraries
│ │ ├── auth.ts # NextAuth configuration (CredentialsProvider)
│ │ └── utils.ts # Helper functions (cn, etc.)
│ │
│ ├── types/ # TypeScript type definitions
│ │ └── next-auth.d.ts # NextAuth module augmentation (custom token fields)
│ │
│ └── proxy.ts # NextAuth middleware (route protection)
│
├── public/ # Static assets
├── components.json # shadcn/ui configuration
├── next.config.ts # Next.js configuration (React Compiler, remote images)
├── postcss.config.mjs # PostCSS configuration
├── tailwind.config.ts # Tailwind CSS configuration (if present)
├── .env.example # Environment variable template
├── .env.local # Local environment variables (git-ignored)
└── package.json

🚀 Getting Started

Prerequisites

  • Node.js ≥ 20
  • pnpm (recommended) or npm
  • The backend API running at http://localhost:4000 (see backend README)
  • A Stripe account (for the publishable key)

Installation

# Navigate to the frontend directorycd store_ui
# Install dependencies
pnpm install
# Copy and configure environment variables
cp .env.example .env.local
# Edit .env.local with your values (see below)# Start the development server
pnpm run dev

The app will be available at http://localhost:3000.


🔐 Environment Variables

Create a .env.local file using .env.example as a template:

# NextAuth ConfigurationNEXTAUTH_URL=http://localhost:3000NEXTAUTH_SECRET=your_random_secret_string# Backend APINEXT_PUBLIC_BACKEND_URL=http://localhost:4000/api/v1# Stripe (publishable key — safe for client-side)NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
VariableDescriptionRequired
NEXTAUTH_URLThe canonical URL of your frontend app
NEXTAUTH_SECRETSecret used to sign/encrypt JWTs (generate with openssl rand -base64 32)
NEXT_PUBLIC_BACKEND_URLFull base URL of the NestJS backend API
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYStripe publishable key for client-side payment forms

🗺️ Pages & Routes

RouteAccessDescription
/🔒 ProtectedHomepage — new arrivals product slider
/login🌐 PublicLogin form (NextAuth credentials)
/register🌐 PublicUser registration form
/products🔒 ProtectedProduct catalog listing
/products/[productId]🔒 ProtectedProduct detail page (images, description, add to cart, reviews)
/cart🔒 ProtectedShopping cart with item management
/check-out🔒 ProtectedCheckout page with Stripe payment form
/orders🔒 ProtectedOrder history

🔒 Protected routes require authentication. Unauthenticated users are automatically redirected to /login.


🔑 Authentication

Flow

sequenceDiagram
participant User as Browser
participant Form as Login Form (Client)
participant NA as NextAuth API Route
participant BE as Backend API
User->>Form: Enter email & password
Form->>NA: signIn("credentials", {email, password})
NA->>BE: POST /api/v1/auth/login
BE-->>NA: { user, token }
NA->>NA: JWT callback → store accessToken
NA->>NA: Session callback → expose to client
NA-->>Form: Success
Form->>User: Redirect to homepage
Note over User, BE: All subsequent API requests include<br/>Authorization: Bearer <token>
Loading

Key Implementation Details

  • Provider: CredentialsProvider — sends email + password to the backend's /auth/login endpoint
  • Strategy: JWT-based sessions (no database session store)
  • Token Handling: The backend's access token is stored in the NextAuth JWT and exposed via the session object
  • Auto-attach: The Axios interceptor in apiClient.ts automatically reads the session and attaches the Authorization: Bearer header to every API request
  • Type Safety: next-auth.d.ts extends the User, Session, and JWT types to include the custom accessToken field
  • Middleware: proxy.ts uses withAuth to protect all routes except /login, /register, and Next.js internals

Public Routes (no auth required)

/login
/register
/api/auth/*
/_next/*
/favicon.ico
/robots.txt
/sitemap.xml

🔌 API Client Layer

The src/api/ directory provides a typed abstraction over the backend API:

apiClient.ts — Core Axios Instance

// Auto-configured with:// - baseURL: NEXT_PUBLIC_BACKEND_URL// - Content-Type: application/json// - Request interceptor: auto-attaches JWT from NextAuth session// (uses getServerSession on server, getSession on client)

API Modules

FileEndpointsDescription
authApi.tsRegisterUser registration API call
productsApi.tsList, Get by IDProduct catalog queries
cartApi.tsGet, Add, Update, RemoveCart management
orderApi.tsCreate, List, GetOrder operations
userApi.tsProfileUser profile queries
handelError.tsCentralized error extraction from Axios errors

🧩 UI Components

Core Components

ComponentFileDescription
NavBarNavBar.tsxMain navigation with links and auth state
Providersproviders.tsxWraps the app in <SessionProvider> for NextAuth
Ratingrating.tsxInteractive star-rating input component
Rating Basicrating-basic.tsxDisplay-only star rating

Product Components

ComponentFileDescription
Product ItemProduct_item.tsxProduct card with image, name, price
Products Sliderproducts_slider.jsxEmbla Carousel of product cards
Add to CartAddToCart.tsxButton that calls the cart API to add a product

Cart & Order Components

ComponentFileDescription
Cart ItemsCartItems.tsxRenders the list of cart items
Cart Item CardcartItemCard.tsxIndividual cart item with quantity controls
Place OrderPlaceOrder.tsxOrder summary card with place-order action
Checkout FormCheckOutForm.tsxCheckout form wrapper
Payment DialogPaymentDioalog.tsxStripe Elements payment dialog
Order ItemorderItem.tsxOrder item display with status and details

shadcn/ui Components

Pre-configured shadcn/ui components are stored in components/ui/. Configuration is managed via components.json.


📜 Scripts

ScriptCommandDescription
devpnpm run devStart dev server with Turbopack
buildpnpm run buildBuild for production
startpnpm run startStart production server
lintpnpm run lintRun ESLint

🖼️ Remote Image Domains

The following external image domains are whitelisted in next.config.ts for next/image:

  • images.unsplash.com — Unsplash stock photos
  • cdn.pixabay.com — Pixabay stock photos
  • res.cloudinary.com — Cloudinary CDN (product images)

📄 License

This project is private — see the root README for details.

Releases

Packages

Contributors

Languages