Complete guide to setting up the Next.js E-Commerce platform for local development.
- Prerequisites
- Initial Setup
- Database Setup
- Environment Configuration
- Running the Application
- Testing
- Common Issues
- Development Workflow
Before you begin, ensure you have the following installed:
-
Node.js (v20.19 or higher)
node --version # Should show v20.19 or higherDownload from: https://nodejs.org/
-
npm (comes with Node.js)
npm --version # Should show v9 or higher -
PostgreSQL (v15 or higher)
psql --version # Should show 15 or higherDownload from: https://www.postgresql.org/download/
-
Git
git --version
Download from: https://git-scm.com/
-
Docker Desktop - For containerized database
- Download from: https://www.docker.com/products/docker-desktop/
-
Stripe CLI - For testing webhooks locally
brew install stripe/stripe-cli/stripe # macOSOr download from: https://stripe.com/docs/stripe-cli
-
Python 3 - For utility scripts
python3 --version
git clone <your-repo-url>
cd Nextjs-Ecommercenpm installThis will install all required packages listed in package.json.
If you need Python for utility scripts:
python3 -m venv venv
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On WindowsThe easiest way to get started is using Docker Compose:
# Start PostgreSQL in a container
docker-compose up -d postgres
# Verify it's running
docker psThe database will be available at postgresql://postgres:postgres@localhost:5432/ecommerce_db
If you prefer to use a local PostgreSQL installation:
# Create a new database
createdb ecommerce_db
# Or using psql
psql postgres
CREATE DATABASE ecommerce_db;
\q# Generate Prisma Client
npx prisma generate
# Run migrations to create tables
npx prisma migrate deploy
# Or for development (creates migration files)
npx prisma migrate dev
# Seed the database with sample data
npm run db:seedOpen Prisma Studio to view/edit data:
npm run db:studioThis opens a web UI at http://localhost:5555
cp .env.example .envEdit .env and set the following required variables:
# Database
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/ecommerce_db"
# Authentication
NEXTAUTH_SECRET="your-generated-secret" # Generate with: openssl rand -base64 32
NEXTAUTH_URL="http://localhost:3000"
# Stripe (get from https://dashboard.stripe.com/test/apikeys)
STRIPE_PUBLISHABLE_KEY="pk_test_..."
STRIPE_SECRET_KEY="sk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..." # See webhook setup below
# Email (get from https://resend.com/api-keys)
RESEND_API_KEY="re_..."
FROM_EMAIL="noreply@yourdomain.com"
# App
NEXT_PUBLIC_APP_NAME="My Store"
NEXT_PUBLIC_APP_URL="http://localhost:3000"
ADMIN_EMAIL="admin@example.com"openssl rand -base64 32Copy the output and paste it as the NEXTAUTH_SECRET value.
# Install Stripe CLI if you haven't
brew install stripe/stripe-cli/stripe # macOS
# Login to your Stripe account
stripe login
# Forward webhooks to your local server
stripe listen --forward-to localhost:3000/api/stripe/webhook
# Copy the webhook signing secret (starts with whsec_) to .envIf you want to enable Google/GitHub login:
Google OAuth:
- Go to https://console.cloud.google.com/apis/credentials
- Create OAuth 2.0 Client ID
- Add to
.env:GOOGLE_CLIENT_ID="your-client-id" GOOGLE_CLIENT_SECRET="your-client-secret"
GitHub OAuth:
- Go to https://github.com/settings/developers
- Create New OAuth App
- Add to
.env:GITHUB_ID="your-github-client-id" GITHUB_SECRET="your-github-client-secret"
# Start the development server
npm run devThe app will be available at http://localhost:3000
Features in dev mode:
- Hot reload on file changes
- Detailed error messages
- Source maps for debugging
# Build for production
npm run build
# Start production server
npm start# Build and run everything with Docker
docker-compose up --build
# Run in background
docker-compose up -d
# Stop containers
docker-compose downnpm test# Run once
npm run test:unit
# Watch mode (re-runs on file changes)
npm run test:watchnpm run test:a11y# Run Cypress in headless mode
npm run test:e2e
# Open Cypress UI
npm run test:e2e:opennpm run type-check# Check for issues
npm run lint
# Format code
npm run format
# Check formatting without fixing
npm run format:checkSolution: Install Node.js from https://nodejs.org/
Solutions:
- Verify PostgreSQL is running:
# If using Docker docker ps | grep postgres # If using local PostgreSQL pg_isready
- Check your
DATABASE_URLin.env - Verify credentials are correct
Solution:
npx prisma generateSolution:
# Find and kill the process using port 3000
lsof -ti:3000 | xargs kill -9
# Or use a different port
PORT=3001 npm run devSolution:
- Make sure Stripe CLI is running:
stripe listen --forward-to localhost:3000/api/stripe/webhook
- Copy the webhook secret to
.env - Restart the dev server
Solution:
# Clear cache and reinstall
rm -rf node_modules .next
npm install# Pull latest changes
git pull origin main
# Install any new dependencies
npm install
# Run database migrations
npx prisma migrate dev
# Start development server
npm run dev# Run tests
npm test
# Type check
npm run type-check
# Lint
npm run lint
# Format code
npm run formatWhen modifying the database schema:
# 1. Edit prisma/schema.prisma
# 2. Create migration
npx prisma migrate dev --name describe_your_change
# 3. Generate Prisma Client
npx prisma generate# Production dependency
npm install package-name
# Development dependency
npm install -D package-name
# Commit package.json and package-lock.json
git add package.json package-lock.json
git commit -m "Add package-name dependency"npm run db:push # Push schema changes without migration
npm run db:seed # Seed database with test data
npm run db:studio # Open Prisma Studio
npm run db:generate # Generate Prisma Clientnpm run dev # Start dev server
npm run build # Build for production
npm start # Start production server
npm run type-check # TypeScript type checking
npm run lint # Lint code
npm run format # Format code with Prettiernpm test # Run all tests
npm run test:unit # Unit tests only
npm run test:watch # Watch mode
npm run test:a11y # Accessibility tests
npm run test:e2e # Cypress E2E tests
npm run test:e2e:open # Cypress UIAfter setup is complete:
-
Explore the Admin Dashboard: http://localhost:3000/admin
- Create products
- Manage inventory
- View orders
-
Review Documentation:
- README.md - Project overview
- PROJECT_STRUCTURE.md - Code organization
- MODERNIZATION_2025.md - Recent updates
-
Check Test Coverage:
npm test -- --coverage -
Start Building! 🚀
- 📖 Check the documentation
- 🐛 Found a bug? Open an issue
- 💬 Questions? Start a discussion
- 📧 Contact: admin@yourdomain.com
Happy Coding! 🎉