Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Production-Ready E-Commerce Platform

A full-stack, production-ready e-commerce platform similar to Amazon, built with modern technologies and comprehensive security features.

πŸš€ Features

Core Functionality

  • βœ… User Authentication & Authorization

    • JWT-based authentication (access + refresh tokens)
    • Email verification
    • Password reset functionality
    • Two-factor authentication (2FA) with TOTP
    • OAuth2 integration (Google, Facebook)
    • Role-based access control (Customer, Seller, Admin)
  • βœ… Product Management

    • Complete CRUD operations
    • Advanced search and filtering
    • Product variants (size, color, etc.)
    • Inventory tracking
    • Product recommendations
    • Recently viewed products
    • Image management
  • βœ… Shopping Experience

    • Persistent shopping cart
    • Wishlist functionality
    • Product reviews and ratings
    • Real-time stock availability
  • βœ… Order Management

    • Complete checkout process
    • Order tracking
    • Order history
    • Cancel/refund support
    • Invoice generation
  • βœ… Payment Integration

    • Stripe payment processing
    • Webhook handling
    • Secure payment flow
    • Refund management
  • βœ… Admin Dashboard

    • User management
    • Product management
    • Order management
    • Analytics and statistics

πŸ—οΈ Architecture

Tech Stack

Backend

  • Framework: Node.js with Express.js
  • Language: TypeScript
  • Database: PostgreSQL
  • ORM: Prisma
  • Cache/Session: Redis
  • Authentication: JWT (jsonwebtoken)
  • Security: Helmet, CORS, Rate Limiting
  • Validation: Zod
  • Documentation: Swagger/OpenAPI
  • Payment: Stripe

Frontend

  • Framework: Next.js 14+ (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • UI Components: shadcn/ui
  • State Management: Zustand
  • Forms: React Hook Form + Zod
  • HTTP Client: Axios
  • Payment UI: Stripe Elements

Infrastructure

  • Containerization: Docker & Docker Compose
  • Database: PostgreSQL 15
  • Cache: Redis 7
  • Process Manager: PM2 (optional)

πŸ“ Project Structure

ecommerce-platform/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/          # Configuration files
β”‚   β”‚   β”œβ”€β”€ controllers/     # Route controllers
β”‚   β”‚   β”œβ”€β”€ middleware/      # Custom middleware
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.middleware.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ rateLimiter.middleware.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ validation.middleware.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ errorHandler.middleware.ts
β”‚   β”‚   β”‚   └── auditLog.middleware.ts
β”‚   β”‚   β”œβ”€β”€ routes/          # API routes
β”‚   β”‚   β”œβ”€β”€ services/        # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.service.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ product.service.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ cart.service.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ order.service.ts
β”‚   β”‚   β”‚   └── payment.service.ts
β”‚   β”‚   β”œβ”€β”€ utils/           # Utility functions
β”‚   β”‚   β”‚   β”œβ”€β”€ encryption.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ jwt.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ email.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ logger.ts
β”‚   β”‚   β”‚   └── validators.ts
β”‚   β”‚   β”œβ”€β”€ prisma/          # Prisma schema
β”‚   β”‚   └── server.ts        # Main server file
β”‚   β”œβ”€β”€ .env.example
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/             # Next.js pages (App Router)
β”‚   β”‚   β”œβ”€β”€ components/      # React components
β”‚   β”‚   β”œβ”€β”€ lib/             # Utilities and configs
β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ services/        # API services
β”‚   β”‚   └── utils/           # Helper functions
β”‚   β”œβ”€β”€ public/              # Static assets
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ next.config.js
β”‚   β”œβ”€β”€ tailwind.config.ts
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”œβ”€β”€ docker-compose.yml
└── README.md

πŸ”’ Security Features

Authentication Security

  • βœ… bcrypt password hashing (cost factor 12)
  • βœ… JWT with short-lived access tokens (15 min) + long-lived refresh tokens (7 days)
  • βœ… HTTP-only secure cookies for token storage
  • βœ… Token rotation on refresh
  • βœ… Account lockout after failed login attempts
  • βœ… Two-factor authentication (2FA) with TOTP
  • βœ… Logout from all devices functionality

API Security

  • βœ… Helmet.js for security headers
  • βœ… Rate limiting with Redis store (per IP and per user)
  • βœ… CORS configuration with whitelisted origins
  • βœ… Request validation with Zod
  • βœ… Input sanitization to prevent XSS
  • βœ… Parameterized queries to prevent SQL injection
  • βœ… API versioning (v1)

Data Protection

  • βœ… Encryption at rest for sensitive data (AES-256-GCM)
  • βœ… TLS/SSL for data in transit
  • βœ… Environment variables for secrets
  • βœ… Audit logging for critical operations

Application Security

  • βœ… CSRF protection
  • βœ… Content Security Policy (CSP)
  • βœ… XSS protection
  • βœ… Secure session management
  • βœ… NoSQL injection prevention
  • βœ… HPP (HTTP Parameter Pollution) prevention
  • βœ… Secure file upload validation

Infrastructure Security

  • βœ… Docker containerization with non-root users
  • βœ… Health check endpoints
  • βœ… Winston logging (no sensitive data in logs)
  • βœ… Error handling without exposing stack traces in production

🚦 Getting Started

Prerequisites

  • Node.js 18+
  • Docker & Docker Compose
  • PostgreSQL 15+ (if not using Docker)
  • Redis 7+ (if not using Docker)
  • Stripe account (for payments)

Installation

1. Clone the Repository

git clone <repository-url>
cd e-com_app

2. Environment Setup

Backend:

cd backend
cp .env.example .env

Edit .env and configure your environment variables:

# Database
DATABASE_URL="postgresql://postgres:postgres123@localhost:5432/ecommerce?schema=public"

# JWT Secrets (MUST be changed in production!)
JWT_ACCESS_SECRET=your-super-secret-jwt-access-key-change-in-production-min-32-chars
JWT_REFRESH_SECRET=your-super-secret-jwt-refresh-key-change-in-production-min-32-chars

# Redis
REDIS_URL=redis://localhost:6379

# Stripe
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret

# Email (Gmail example)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password

# Frontend URL
FRONTEND_URL=http://localhost:3000

Frontend:

cd frontend

Create .env.local:

NEXT_PUBLIC_API_URL=http://localhost:5000/api/v1
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key

3. Using Docker (Recommended)

# From project root
docker-compose up -d

This will start:

  • PostgreSQL on port 5432
  • Redis on port 6379
  • Backend API on port 5000
  • Frontend on port 3000
  • PgAdmin on port 5050 (optional)

4. Manual Setup (Without Docker)

Backend:

cd backend

# Install dependencies
npm install

# Generate Prisma client
npx prisma generate

# Run database migrations
npx prisma migrate dev

# Start development server
npm run dev

Frontend:

cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

πŸ—„οΈ Database Setup

Run Migrations

cd backend
npx prisma migrate dev

Prisma Studio (Database GUI)

npx prisma studio

Access at http://localhost:5555

πŸ“š API Documentation

Once the backend is running, access Swagger documentation at:

http://localhost:5000/api-docs

πŸ§ͺ Testing

Backend:

cd backend
npm test
npm run test:coverage

Frontend:

cd frontend
npm test

πŸ“Š Database Schema

Key Models

  • User: Customer, Seller, Admin with RBAC
  • Product: With variants, images, and inventory
  • Category: Hierarchical categories
  • Cart: Persistent shopping cart
  • Order: Order management with status tracking
  • Payment: Stripe integration
  • Review: Product reviews and ratings
  • Wishlist: User wishlists
  • Address: Shipping and billing addresses
  • Session: User sessions
  • AuditLog: Security audit trail

πŸ”‘ API Endpoints

Authentication

  • POST /api/v1/auth/register - Register user
  • POST /api/v1/auth/login - Login user
  • POST /api/v1/auth/logout - Logout user
  • POST /api/v1/auth/refresh - Refresh access token
  • POST /api/v1/auth/verify-email - Verify email
  • POST /api/v1/auth/forgot-password - Request password reset
  • POST /api/v1/auth/reset-password - Reset password
  • POST /api/v1/auth/2fa/setup - Setup 2FA
  • POST /api/v1/auth/2fa/verify - Verify 2FA
  • GET /api/v1/auth/me - Get current user

Products

  • GET /api/v1/products - Get all products
  • GET /api/v1/products/:id - Get product by ID
  • POST /api/v1/products - Create product (Admin/Seller)
  • PUT /api/v1/products/:id - Update product
  • DELETE /api/v1/products/:id - Delete product
  • GET /api/v1/products/search - Search products
  • GET /api/v1/products/featured - Get featured products

Cart

  • GET /api/v1/cart - Get user cart
  • POST /api/v1/cart/items - Add to cart
  • PATCH /api/v1/cart/items/:id - Update cart item
  • DELETE /api/v1/cart/items/:id - Remove from cart

Orders

  • POST /api/v1/orders - Create order
  • GET /api/v1/orders - Get user orders
  • GET /api/v1/orders/:id - Get order by ID
  • POST /api/v1/orders/:id/cancel - Cancel order

Payments

  • POST /api/v1/payments/create-intent - Create payment intent
  • POST /api/v1/payments/webhook - Stripe webhook
  • GET /api/v1/payments/order/:orderId - Get payment

🎨 Frontend Features

Pages

  • Home page with featured products
  • Product listing with filters
  • Product detail page
  • Shopping cart
  • Checkout
  • Order history
  • User profile
  • Admin dashboard

Components

  • Responsive navigation
  • Product cards
  • Shopping cart widget
  • Search bar with autocomplete
  • Authentication forms
  • Payment forms (Stripe Elements)

πŸ› οΈ Development

Code Quality

# Linting
npm run lint

# Type checking
npm run type-check

# Format code
npm run format

πŸš€ Deployment

Production Build

Backend:

cd backend
npm run build
npm start

Frontend:

cd frontend
npm run build
npm start

Security Checklist for Production

  • Change all default passwords
  • Use strong JWT secrets (min 32 characters)
  • Enable HTTPS/TLS
  • Configure proper CORS origins
  • Set up proper firewall rules
  • Enable rate limiting
  • Set up monitoring and alerts
  • Configure backup strategy
  • Enable audit logging
  • Review and update security headers
  • Set secure cookie flags
  • Disable debug mode

πŸ“ Environment Variables

Backend (.env)

Variable Description Required Default
NODE_ENV Environment mode No development
PORT Server port No 5000
DATABASE_URL PostgreSQL connection string Yes -
JWT_ACCESS_SECRET JWT access token secret Yes -
JWT_REFRESH_SECRET JWT refresh token secret Yes -
REDIS_URL Redis connection string Yes -
STRIPE_SECRET_KEY Stripe secret key Yes -

See .env.example for full list.

Frontend (.env.local)

Variable Description Required
NEXT_PUBLIC_API_URL Backend API URL Yes
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY Stripe publishable key Yes

πŸ› Troubleshooting

Common Issues

Database connection fails:

  • Ensure PostgreSQL is running
  • Check DATABASE_URL in .env
  • Verify database exists

Redis connection fails:

  • Ensure Redis is running
  • Check REDIS_URL in .env

JWT errors:

  • Ensure JWT secrets are at least 32 characters
  • Check token expiration settings

πŸ“„ License

This project is licensed under the MIT License.

🀝 Contributing

Contributions are welcome! Please read the contributing guidelines first.


Built with ❀️ using modern web technologies

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages