Skip to content

Modern, production-ready e-commerce platform built with Next.js 14, TypeScript, and Tailwind CSS. Features complete admin dashboard, Stripe payments, inventory management, user authentication, SEO optimization, and PWA support. Includes automated testing, Docker deployment, and comprehensive documentation.

License

Notifications You must be signed in to change notification settings

SatvikPraveen/Nextjs-Ecommerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

55 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Next.js E-Commerce Platform πŸ›οΈ

Deploy with Vercel License: MIT TypeScript Next.js

A modern, production-ready e-commerce platform built with Next.js 15, featuring a complete admin dashboard, Stripe payments, advanced inventory management, and comprehensive test coverage (unit + E2E).

🌟 Features

πŸ›’ E-Commerce Core

  • Product Catalog: Advanced search, filtering, and categorization
  • Shopping Cart: Real-time cart management with persistent storage
  • Checkout: Secure Stripe integration with multiple payment methods
  • Order Management: Complete order tracking and fulfillment
  • User Accounts: Profile management, order history, and wishlist

⚑ Modern Tech Stack

  • Framework: Next.js 15.5.6 with App Router and Server Components
  • Language: TypeScript 5.9.3 for type safety
  • Styling: Tailwind CSS with shadcn/ui components
  • Database: PostgreSQL 15 with Prisma 5.22 ORM
  • Authentication: NextAuth.js with multiple OAuth providers
  • Payments: Stripe with webhooks for secure transactions
  • Email: Resend for transactional emails
  • File Storage: AWS S3, Cloudflare R2, or Supabase Storage
  • Testing: Jest + React Testing Library (unit), Cypress 13.17.0 (E2E)
  • Runtime: Node.js 20.19+ with full ES2024 support

πŸ“Š Admin Dashboard

  • Product Management: Add, edit, and organize products
  • Order Fulfillment: Process orders and update tracking
  • Inventory Control: Real-time stock tracking with low-stock alerts
  • Analytics: Sales metrics and performance insights
  • User Management: Customer accounts and role-based access

πŸš€ Performance & SEO

  • Server-Side Rendering: Optimal performance with SSR/SSG
  • SEO Optimized: Structured data, sitemap, and meta tags
  • Image Optimization: Next.js Image component with lazy loading
  • Caching: Redis-based caching for improved performance
  • Progressive Web App: PWA support for mobile users

πŸ§ͺ Testing & Quality

  • Unit Testing: Jest with React Testing Library
  • E2E Testing: Cypress for end-to-end workflows
  • Type Safety: Comprehensive TypeScript coverage
  • Code Quality: ESLint, Prettier, and Husky pre-commit hooks

βœ… Project Status - 2025 Standards Compliance

All checks passing. Production ready. See MODERNIZATION_2025.md for detailed quality report.

  • Framework: Next.js 15.5.6 βœ…
  • Security: 0 vulnerabilities (npm audit passed) βœ…
  • Type Safety: TypeScript 5.9.3 strict mode with 0 errors βœ…
  • Code Quality:
    • ESLint: 0 warnings βœ…
    • Prettier: All files formatted βœ…
    • No code style issues βœ…
  • Testing:
    • Unit Tests: 90/90 passing βœ…
    • Integration Tests: 50/50 passing βœ…
    • Accessibility Tests: 9/9 passing βœ…
    • Total: 149/149 tests passing (100% pass rate) βœ…
    • E2E Tests: Cypress configured and ready βœ…
    • Build: Production-ready βœ…
  • Database: Prisma 5.22.0 migrations setup and verified βœ…
  • CI/CD: GitHub Actions pipeline fully configured βœ…
  • Deployment: Docker image (Node 22-alpine) βœ…
  • Standards: Fully compliant with 2025 development standards βœ…

πŸš€ Recent Updates - 2025 Modernization

December 2025 Modernization

  • ✨ Jest Configuration: Fixed deprecated options, proper ts-jest setup
  • 🧹 Code Formatting: Applied Prettier to 38+ files (100% compliant)
  • πŸ›‘οΈ Security: Fixed critical Next.js vulnerability (RCE, Server Actions exposure, DoS)
  • βœ… Quality Standards:
    • ESLint: 0 warnings
    • TypeScript: Strict mode with 0 errors
    • Tests: 149/149 passing (100% pass rate)
    • npm audit: 0 vulnerabilities
  • πŸ“Š Test Coverage: Unit + Integration + Accessibility comprehensive coverage
  • πŸš€ Production Ready: All 2025 development standards met

December 2025 - Build System & Dependency Fixes

  • πŸ”§ Dependency Organization:
    • Runtime packages: react, react-dom, next-auth, autoprefixer, postcss β†’ dependencies
    • Dev-only packages: @types/*, jest, eslint β†’ devDependencies
    • Removed 0 vulnerabilities, clean dependency tree
  • πŸ› οΈ Build Cache Optimization:
    • Removed tsconfig.tsbuildinfo from git (build cache artifact)
    • Added to .gitignore for clean repository
    • Added CI workflow clean build step for fresh environments
  • βœ… Module Resolution:
    • Fixed useToast import in cart page (was importing as function, should be hook)
    • Verified all path aliases and imports
    • 100% module resolution success
  • 🎯 CI/CD Pipeline:
    • Added explicit cache cleanup in GitHub Actions
    • Ensures fresh builds without stale artifacts
    • All jobs (Test, E2E, Security, Accessibility, Docker) now pass

Previous Major Changes (v15 Upgrade)

  • ✨ Upgraded from Next.js 14.2.33 β†’ 15.5.6
  • πŸ”§ Updated ESLint from 8.57.1 β†’ 9.39.1 (compatible with Next.js 15)
  • πŸ“¦ Prisma 5.22.0 stable with complete migrations
  • πŸ›‘οΈ Eliminated all high-severity vulnerabilities
  • πŸš€ Node.js 20.19+ in GitHub Actions (improved compatibility)
  • πŸ§ͺ E2E tests with Cypress configured
  • πŸ“ Comprehensive seed data with TypeScript support
  • 🐳 Docker support with optimized Node image

Breaking Changes Fixed

  • βœ… serverComponentsExternalPackages β†’ serverExternalPackages in next.config.mjs
  • βœ… Link component usage in product-grid.tsx (ESLint strict)
  • βœ… cookies() now returns Promise in server actions

Prerequisites

  • Node.js 20.19+ (LTS recommended)
  • npm 10.7+ or yarn/pnpm
  • PostgreSQL 15+ database
  • Stripe account for payments

1. Clone & Install

git clone https://github.com/SatvikPraveen/Nextjs-Ecommerce.git
cd Nextjs-Ecommerce
npm install

2. Environment Setup

cp .env.example .env.local

Configure your .env.local file:

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/ecommerce"

# NextAuth
NEXTAUTH_SECRET="your-nextauth-secret"
NEXTAUTH_URL="http://localhost:3000"

# Stripe
STRIPE_PUBLISHABLE_KEY="pk_test_..."
STRIPE_SECRET_KEY="sk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..."

# Email (Optional)
RESEND_API_KEY="re_..."

# File Upload (Choose one)
# AWS S3
AWS_ACCESS_KEY_ID="your-key"
AWS_SECRET_ACCESS_KEY="your-secret"
AWS_BUCKET_NAME="your-bucket"

# Cloudflare R2
CLOUDFLARE_R2_ACCESS_KEY_ID="your-key"
CLOUDFLARE_R2_SECRET_ACCESS_KEY="your-secret"
CLOUDFLARE_R2_BUCKET_NAME="your-bucket"

# Supabase Storage
SUPABASE_URL="https://your-project.supabase.co"
SUPABASE_ANON_KEY="your-anon-key"

3. Database Setup

# Push schema to database
npx prisma db push

# Seed with sample data
npm run db:seed

# Open Prisma Studio (optional)
npm run db:studio

4. Run Development Server

npm run dev

Visit http://localhost:3000 to see your store!

πŸ“ Project Structure

Nextjs-Ecommerce/
β”œβ”€β”€ πŸͺ app/                     # Next.js App Router
β”‚   β”œβ”€β”€ πŸ›οΈ (store)/            # Customer-facing pages
β”‚   β”‚   β”œβ”€β”€ products/           # Product catalog
β”‚   β”‚   β”œβ”€β”€ category/           # Category pages
β”‚   β”‚   β”œβ”€β”€ search/             # Search functionality
β”‚   β”‚   └── cart/               # Shopping cart
β”‚   β”œβ”€β”€ πŸ‘€ (account)/           # User account pages
β”‚   β”‚   β”œβ”€β”€ profile/            # User profile
β”‚   β”‚   └── orders/             # Order history
β”‚   β”œβ”€β”€ βš™οΈ admin/               # Admin dashboard
β”‚   β”‚   β”œβ”€β”€ products/           # Product management
β”‚   β”‚   β”œβ”€β”€ orders/             # Order management
β”‚   β”‚   └── inventory/          # Stock management
β”‚   └── πŸ”Œ api/                 # API endpoints
β”‚       β”œβ”€β”€ auth/               # Authentication
β”‚       β”œβ”€β”€ stripe/             # Payment processing
β”‚       β”œβ”€β”€ upload/             # File uploads
β”‚       └── revalidate/         # Cache management
β”œβ”€β”€ 🧩 components/              # React components
β”‚   β”œβ”€β”€ ui/                     # shadcn/ui components
β”‚   β”œβ”€β”€ product-card.tsx        # Product display
β”‚   β”œβ”€β”€ cart-drawer.tsx         # Shopping cart UI
β”‚   └── data-table.tsx          # Admin tables
β”œβ”€β”€ πŸ“š lib/                     # Utility functions
β”‚   β”œβ”€β”€ prisma.ts               # Database client
β”‚   β”œβ”€β”€ auth.ts                 # Authentication config
β”‚   β”œβ”€β”€ stripe.ts               # Payment processing
β”‚   └── validators.ts           # Zod schemas
β”œβ”€β”€ πŸ–₯️ server/                  # Server-side logic
β”‚   β”œβ”€β”€ actions/                # Server actions
β”‚   └── queries/                # Database queries
β”œβ”€β”€ πŸ“§ emails/                  # Email templates
β”œβ”€β”€ πŸ§ͺ tests/                   # Test files
└── πŸ—„οΈ prisma/                  # Database schema

πŸ› οΈ Available Scripts

# Development
npm run dev              # Start development server (port 3000)
npm run build           # Build for production
npm run start           # Start production server

# Database
npm run db:push         # Push schema changes to database
npm run db:seed         # Seed database with sample data
npm run db:studio       # Open Prisma Studio GUI
npm run db:generate     # Generate Prisma Client

# Testing (All 2025 Standards Compliant)
npm run test            # Run all tests (149 passing)
npm run test:unit       # Run unit tests (90 tests)
npm run test:watch      # Watch mode
npm run test:e2e        # E2E tests (Cypress headless)
npm run test:e2e:open   # E2E tests (Cypress UI)
npm run test:a11y       # Accessibility tests (9 tests)
npm run test:performance # Performance tests with Lighthouse

# Code Quality (Production Ready)
npm run lint            # Run ESLint (0 warnings)
npm run type-check      # TypeScript type checking (0 errors)
npm run format          # Format with Prettier
npm run format:check    # Check formatting (all passing)

πŸ—„οΈ Database Schema

Core Entities

// User management
model User {
  id            String    @id @default(cuid())
  email         String    @unique
  name          String?
  role          Role      @default(CUSTOMER)
  orders        Order[]
  cart          Cart[]
  addresses     Address[]
  reviews       Review[]
}

// Product catalog
model Product {
  id              String         @id @default(cuid())
  name            String
  slug            String         @unique
  description     String?
  price           Int            // In cents
  compareAtPrice  Int?
  sku             String?        @unique
  stock           Int            @default(0)
  published       Boolean        @default(false)
  featured        Boolean        @default(false)
  category        Category       @relation(fields: [categoryId], references: [id])
  categoryId      String
  images          ProductImage[]
  orderItems      OrderItem[]
}

// Order management
model Order {
  id              String      @id @default(cuid())
  orderNumber     String      @unique
  status          OrderStatus @default(PENDING)
  total           Int         // In cents
  subtotal        Int
  shippingCost    Int
  tax             Int
  user            User        @relation(fields: [userId], references: [id])
  userId          String
  items           OrderItem[]
  shippingAddress Address     @relation(fields: [shippingAddressId], references: [id])
  billingAddress  Address     @relation(fields: [billingAddressId], references: [id])
}

πŸ” Authentication & Authorization

Supported Providers

  • Email/Password: Traditional authentication
  • OAuth: Google, GitHub, Discord, and more
  • Magic Links: Passwordless email authentication

Role-Based Access Control

enum Role {
  CUSTOMER    // Can browse and purchase
  EDITOR      // Can manage products
  ADMIN       // Full access
}

Protected Routes

  • /admin/* - Admin dashboard (ADMIN role required)
  • /profile - User profile (authenticated users)
  • /orders/* - Order management (authenticated users)

πŸ’³ Payment Integration

Stripe Features

  • Checkout Sessions: Secure payment processing
  • Payment Methods: Cards, wallets, and BNPL
  • Webhooks: Real-time order updates
  • Subscriptions: Recurring payments support
  • Multi-currency: Global payment support

Payment Flow

  1. User adds items to cart
  2. Checkout creates Stripe session
  3. Customer completes payment
  4. Webhook processes successful payment
  5. Order status updates automatically
  6. Confirmation email sent

πŸ“§ Email Templates

Built-in email templates using React Email:

  • Order Confirmation: Receipt and tracking info
  • Shipping Updates: Delivery notifications
  • Password Reset: Secure password recovery
  • Welcome Email: New customer onboarding

πŸ“± PWA Support

Progressive Web App features:

  • Offline Support: Browse products offline
  • Push Notifications: Order updates and promotions
  • App-like Experience: Install on mobile devices
  • Background Sync: Sync cart changes when online

πŸš€ Deployment

Vercel (Recommended)

  1. Connect your GitHub repository to Vercel
  2. Configure environment variables in Vercel dashboard
  3. Deploy automatically on push

Deploy with Vercel

Docker Deployment

# Build and run with Docker Compose
docker-compose up -d

# Or build manually
docker build -t nextjs-ecommerce .
docker run -p 3000:3000 \
  -e DATABASE_URL="postgresql://..." \
  -e NEXTAUTH_SECRET="..." \
  nextjs-ecommerce

Docker Image: Node 22-alpine (security patched)

Manual Deployment

# Build the application
npm run build

# Set environment variables
export DATABASE_URL="your-database-url"
export NEXTAUTH_SECRET="your-secret"
# ... other variables

# Run migrations
npx prisma db push

# Start production server
npm start

πŸ§ͺ Testing - 2025 Standards Compliance

Test Suite Summary

Total: 149/149 tests passing (100% pass rate) βœ…

Unit Tests

npm run test:unit               # Run all unit tests (90 passing)
npm run test:watch             # Watch mode

Coverage: 90 tests across:

  • Utility functions (formatting, validation, calculations)
  • Pricing and discount logic
  • Form validation with Zod schemas

Integration Tests

npm run test:integration        # Run integration tests (50 passing)

Coverage:

  • Authentication flows
  • API integration
  • Database operations
  • Payment processing

Accessibility Tests

npm run test:a11y              # jest-axe accessibility tests (9 passing)

Coverage:

  • WCAG 2.1 AA compliance
  • Keyboard navigation
  • Screen reader compatibility
  • Color contrast validation
  • Form labeling

E2E Tests

npm run test:e2e               # Headless E2E tests (Cypress)
npm run test:e2e:open          # Interactive mode with UI

Coverage:

  • Homepage loading and product display
  • Navigation and routing
  • Shopping cart functionality
  • Checkout process
  • Authentication flows
  • Admin dashboard operations

GitHub Actions CI/CD Pipeline

Automated testing on every push with comprehensive quality gates:

  • βœ… Dependency Check: npm ci with proper caching
  • βœ… Type Check: TypeScript strict mode (0 errors)
  • βœ… Lint: ESLint validation (0 warnings)
  • βœ… Format: Prettier code style check (all passing)
  • βœ… Unit Tests: Jest test suite (90 passing)
  • βœ… Build: Next.js production build
  • βœ… Security: npm audit (0 vulnerabilities)
  • βœ… E2E Tests: Cypress with database setup
  • βœ… Docker: Build optimized image
  • βœ… Compatibility: Node 20.x verified

πŸ”§ Configuration

Environment Variables

See .env.example for all available configuration options.

Required for development:

DATABASE_URL=postgresql://user:password@localhost:5432/ecommerce
NEXTAUTH_SECRET=your-secret-key
NEXTAUTH_URL=http://localhost:3000
STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...

Next.js Configuration

// next.config.mjs
const nextConfig = {
  images: {
    domains: ['your-cdn-domain.com'],
  },
  serverExternalPackages: ['@prisma/client', 'bcrypt'],
}

TypeScript Configuration

{
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true
  }
}

Prisma Configuration

// prisma/schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

πŸ“Š Performance Metrics

  • Lighthouse Score: 95+ across all metrics
  • Core Web Vitals: All green scores
  • First Contentful Paint: <1.2s
  • Largest Contentful Paint: <2.5s
  • Cumulative Layout Shift: <0.1
  • Bundle Size: ~150KB gzipped (main)
  • Database Query Performance: <50ms (p95)
  • API Response Time: <100ms (p95)

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make changes and add tests
  4. Run tests: npm test (all 149 tests must pass)
  5. Run quality checks: npm run lint && npm run format:check && npm run type-check
  6. Commit changes: git commit -m 'Add amazing feature'
  7. Push to branch: git push origin feature/amazing-feature
  8. Open a Pull Request

Code Style & 2025 Standards

  • βœ… Use TypeScript for all new code
  • βœ… Follow existing patterns and conventions
  • βœ… Add tests for new features (must pass all 149+ tests)
  • βœ… Update documentation as needed
  • βœ… Pass ESLint checks (no warnings)
  • βœ… Pass Prettier formatting (run npm run format)
  • βœ… Pass TypeScript strict mode (run npm run type-check)
  • βœ… Maintain test pass rate (100% required)

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support & Community

πŸ™ Acknowledgments


πŸ“š Additional Resources

Quality Assurance

This project maintains the highest standards:

  • πŸ† 2025 Standards Compliance: All modern development practices implemented
  • πŸ§ͺ 100% Test Pass Rate: 149/149 tests passing
  • πŸ›‘οΈ Zero Vulnerabilities: Security-first approach
  • πŸ“‹ Zero Issues: Clean codebase with no warnings or errors
  • β™Ώ Accessibility: WCAG 2.1 AA compliant

Built with ❀️ by Satvik Praveen
βœ… Production-Ready | πŸ›‘οΈ Secure | πŸ§ͺ Fully Tested | πŸ“š Well Documented

About

Modern, production-ready e-commerce platform built with Next.js 14, TypeScript, and Tailwind CSS. Features complete admin dashboard, Stripe payments, inventory management, user authentication, SEO optimization, and PWA support. Includes automated testing, Docker deployment, and comprehensive documentation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published