Skip to content

Singhss21/E-Commerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›οΈ E-Commerce Full-Stack Application

A complete E-Commerce platform built with modern web technologies featuring a customer-facing frontend, admin dashboard, and robust backend API.

πŸ“‹ Table of Contents

🎯 Project Overview

This is a full-stack E-Commerce application with three main components:

  1. Frontend (Customer Portal) - React-based customer interface for browsing products, cart management, and checkout
  2. Admin Dashboard - React-based admin panel for product management and order processing
  3. Backend API - Node.js/Express server with MongoDB database and payment integrations

Key Features:

  • πŸ” User authentication and authorization
  • πŸ›’ Shopping cart functionality
  • πŸ’³ Multiple payment gateways (Stripe, Razorpay, COD)
  • πŸ“± Responsive design with Tailwind CSS
  • πŸ–ΌοΈ Image upload with Cloudinary
  • πŸ“Š Admin dashboard for inventory management
  • πŸ” Product search and filtering
  • πŸ“¦ Order management system

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Admin Panel   β”‚    β”‚    Backend      β”‚
β”‚   (Customer)    β”‚    β”‚                 β”‚    β”‚    (API)        β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ Product Browseβ”‚    β”‚ β€’ Add Products  β”‚    β”‚ β€’ REST API      β”‚
β”‚ β€’ Shopping Cart β”‚    β”‚ β€’ Manage Orders β”‚    β”‚ β€’ Authenticationβ”‚
β”‚ β€’ Checkout      β”‚    β”‚ β€’ View Analyticsβ”‚    β”‚ β€’ File Upload   β”‚
β”‚ β€’ User Profile  β”‚    β”‚ β€’ User Mgmt     β”‚    β”‚ β€’ Payment Proc  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Database      β”‚
                    β”‚   (MongoDB)     β”‚
                    β”‚                 β”‚
                    β”‚ β€’ Users         β”‚
                    β”‚ β€’ Products      β”‚
                    β”‚ β€’ Orders        β”‚
                    β”‚ β€’ Cart Data     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Frontend & Admin Panel

  • React 19 - Modern React with hooks and functional components
  • React Router DOM - Client-side routing
  • Tailwind CSS - Utility-first CSS framework
  • Vite - Fast build tool and development server
  • Axios - HTTP client for API calls
  • React Toastify - Toast notifications
  • Context API - State management

Backend

  • Node.js - JavaScript runtime
  • Express.js - Web application framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB object modeling
  • JWT - JSON Web Tokens for authentication
  • bcrypt - Password hashing
  • Multer - File upload middleware
  • CORS - Cross-origin resource sharing

External Services

  • Cloudinary - Cloud image storage and management
  • Stripe - Payment processing
  • Razorpay - Payment gateway
  • MongoDB Atlas - Cloud database hosting

Development Tools

  • ESLint - Code linting
  • PostCSS - CSS processing
  • Autoprefixer - CSS vendor prefixing
  • Nodemon - Development server with auto-restart

πŸ“ Project Structure

E-Commerce/
β”œβ”€β”€ frontend/                 # Customer-facing React app
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/       # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ pages/           # Page components
β”‚   β”‚   β”œβ”€β”€ context/         # React Context for state
β”‚   β”‚   β”œβ”€β”€ assets/          # Images and static files
β”‚   β”‚   └── App.jsx          # Main app component
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
β”‚
β”œβ”€β”€ admin/                   # Admin dashboard React app
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/      # Admin UI components
β”‚   β”‚   β”œβ”€β”€ pages/          # Admin pages
β”‚   β”‚   └── assets/         # Admin assets
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
β”‚
└── backend/                 # Node.js API server
    β”œβ”€β”€ config/             # Configuration files
    β”œβ”€β”€ controllers/        # Business logic
    β”œβ”€β”€ middleware/         # Custom middleware
    β”œβ”€β”€ models/            # Database schemas
    β”œβ”€β”€ routes/            # API routes
    β”œβ”€β”€ server.js          # Main server file
    └── package.json

✨ Features

Customer Features

  • User Registration & Login - Secure authentication with JWT
  • Product Browsing - View products with images, descriptions, and pricing
  • Product Search - Search functionality with filters
  • Shopping Cart - Add/remove items with size selection
  • Checkout Process - Multiple payment options (Stripe, Razorpay, COD)
  • Order History - View past orders and status
  • Responsive Design - Mobile-friendly interface

Admin Features

  • Product Management - Add, edit, and delete products
  • Image Upload - Multiple image upload with Cloudinary
  • Order Management - View and update order status
  • Inventory Control - Manage product stock and categories
  • User Management - View customer data and orders

Technical Features

  • RESTful API - Well-structured API endpoints
  • File Upload - Secure image upload with validation
  • Payment Integration - Multiple payment gateways
  • Real-time Updates - Live cart and order updates
  • Error Handling - Comprehensive error management
  • Security - JWT authentication, password hashing, CORS

πŸ”„ Workflow

Customer Journey

  1. Browse Products β†’ View product catalog with search/filter
  2. Product Details β†’ Select size and add to cart
  3. Cart Management β†’ Review items, update quantities
  4. Checkout β†’ Enter shipping details and payment method
  5. Payment β†’ Complete payment via Stripe/Razorpay/COD
  6. Order Confirmation β†’ Receive order confirmation and tracking

Admin Workflow

  1. Login β†’ Admin authentication
  2. Add Products β†’ Upload images, set details, categories
  3. Manage Inventory β†’ Update stock, prices, descriptions
  4. Process Orders β†’ View orders, update status
  5. Analytics β†’ Monitor sales and customer data

Backend Process Flow

  1. Request β†’ Client sends HTTP request
  2. Authentication β†’ Verify JWT token (if required)
  3. Validation β†’ Validate request data
  4. Business Logic β†’ Process request in controller
  5. Database β†’ Perform CRUD operations
  6. Response β†’ Send JSON response to client

πŸš€ Installation & Setup

Prerequisites

  • Node.js (v18 or higher)
  • MongoDB (local or Atlas)
  • npm or yarn package manager

Environment Variables

Create .env files in the backend directory:

# Database
MONGO_URI=mongodb://localhost:27017
# or MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net

# JWT
JWT_SECRET=your_jwt_secret_key

# Cloudinary
CLOUDINARY_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_SECRET_KEY=your_cloudinary_secret_key

# Payment Gateways
STRIPE_SECRET_KEY=your_stripe_secret_key
RAZORPAY_KEY_ID=your_razorpay_key_id
RAZORPAY_KEY_SECRET=your_razorpay_secret_key

# Admin Credentials
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=admin_password

# Server
PORT=4000

Create .env files in frontend and admin directories:

VITE_BACKEND_URL=http://localhost:4000

Installation Steps

  1. Clone the repository

    git clone <repository-url>
    cd E-Commerce
  2. Install backend dependencies

    cd backend
    npm install
  3. Install frontend dependencies

    cd ../frontend
    npm install
  4. Install admin dependencies

    cd ../admin
    npm install
  5. Start the development servers

    Backend:

    cd backend
    npm run server

    Frontend:

    cd frontend
    npm run dev

    Admin:

    cd admin
    npm run dev
  6. Access the applications

πŸ“š API Documentation

Authentication Endpoints

User Registration

POST /api/user/register
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123"
}

User Login

POST /api/user/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "password123"
}

Admin Login

POST /api/user/admin-login
Content-Type: application/json

{
  "email": "admin@example.com",
  "password": "admin_password"
}

Product Endpoints

Get All Products

GET /api/product/list

Get Single Product

POST /api/product/single
Content-Type: application/json

{
  "productId": "product_id_here"
}

Add Product (Admin)

POST /api/product/add
Content-Type: multipart/form-data
Authorization: Bearer <admin_token>

{
  "name": "Product Name",
  "description": "Product description",
  "price": 99.99,
  "category": "Men",
  "subCategory": "Topwear",
  "sizes": ["S", "M", "L", "XL"],
  "bestseller": true,
  "image1": <file>,
  "image2": <file>,
  "image3": <file>,
  "image4": <file>
}

Remove Product (Admin)

POST /api/product/remove
Content-Type: application/json
Authorization: Bearer <admin_token>

{
  "id": "product_id_here"
}

Cart Endpoints

Add to Cart

POST /api/cart/add
Content-Type: application/json
Authorization: Bearer <user_token>

{
  "itemId": "product_id",
  "size": "M"
}

Get Cart

POST /api/cart/get
Authorization: Bearer <user_token>

Update Cart

POST /api/cart/update
Content-Type: application/json
Authorization: Bearer <user_token>

{
  "itemId": "product_id",
  "size": "M",
  "quantity": 2
}

Order Endpoints

Place Order (COD)

POST /api/order/place
Content-Type: application/json
Authorization: Bearer <user_token>

{
  "userId": "user_id",
  "items": [
    {
      "id": "product_id",
      "name": "Product Name",
      "price": 99.99,
      "size": "M",
      "quantity": 1
    }
  ],
  "amount": 109.99,
  "address": {
    "street": "123 Main St",
    "city": "New York",
    "state": "NY",
    "zipCode": "10001"
  }
}

Place Order (Stripe)

POST /api/order/stripe
Content-Type: application/json
Authorization: Bearer <user_token>

{
  "userId": "user_id",
  "items": [...],
  "amount": 109.99,
  "address": {...}
}

Place Order (Razorpay)

POST /api/order/razorpay
Content-Type: application/json
Authorization: Bearer <user_token>

{
  "userId": "user_id",
  "items": [...],
  "amount": 109.99,
  "address": {...}
}

Get User Orders

POST /api/order/user-orders
Content-Type: application/json
Authorization: Bearer <user_token>

{
  "userId": "user_id"
}

Get All Orders (Admin)

POST /api/order/all-orders
Authorization: Bearer <admin_token>

Update Order Status (Admin)

POST /api/order/update-status
Content-Type: application/json
Authorization: Bearer <admin_token>

{
  "orderId": "order_id",
  "status": "Shipped"
}

πŸ—„οΈ Database Schema

User Model

{
  name: String (required),
  email: String (required, unique),
  password: String (required, hashed),
  cartData: Object (default: {})
}

Product Model

{
  name: String (required),
  description: String (required),
  price: Number (required),
  image: Array (required), // Cloudinary URLs
  category: String (required), // e.g., "Men", "Women"
  subCategory: String (required), // e.g., "Topwear", "Bottomwear"
  sizes: Array (required), // e.g., ["S", "M", "L", "XL"]
  bestseller: Boolean,
  date: Number (required) // Timestamp
}

Order Model

{
  userId: String (required),
  items: Array (required), // Product details with quantities
  amount: Number (required),
  address: Object (required), // Shipping address
  status: String (required, default: "Order Placed"),
  paymentMethod: String (required), // "COD", "Stripe", "Razorpay"
  payment: Boolean (required, default: false),
  date: Number (required) // Timestamp
}

πŸ’³ Payment Integration

Supported Payment Methods

  1. Cash on Delivery (COD)

    • No payment processing required
    • Order placed immediately
    • Payment collected on delivery
  2. Stripe

    • Secure online payment processing
    • Supports major credit cards
    • Automatic payment verification
    • Redirect to Stripe checkout
  3. Razorpay

    • Indian payment gateway
    • Supports UPI, cards, net banking
    • Order creation and verification
    • Payment status tracking

Payment Flow

  1. Order Creation β†’ Create order in database
  2. Payment Gateway β†’ Redirect to payment provider
  3. Payment Processing β†’ Customer completes payment
  4. Verification β†’ Verify payment with gateway
  5. Order Update β†’ Update order status and clear cart
  6. Confirmation β†’ Send confirmation to customer

πŸ“€ File Upload

Cloudinary Integration

  • Multiple Images β†’ Up to 4 images per product
  • Automatic Optimization β†’ Cloudinary handles image optimization
  • Secure URLs β†’ HTTPS image URLs
  • CDN Delivery β†’ Fast global image delivery

Upload Process

  1. File Selection β†’ Admin selects images
  2. Form Data β†’ Images sent as multipart/form-data
  3. Multer Processing β†’ Server processes uploaded files
  4. Cloudinary Upload β†’ Images uploaded to Cloudinary
  5. URL Storage β†’ Image URLs stored in database
  6. Product Creation β†’ Product saved with image URLs

πŸ” Authentication & Authorization

JWT Implementation

  • Token Generation β†’ JWT created on login/register
  • Token Storage β†’ Stored in localStorage
  • Token Validation β†’ Middleware validates tokens
  • Token Refresh β†’ New token on successful requests

User Types

  1. Customers

    • Register/login with email/password
    • Access to shopping features
    • Personal cart and order history
  2. Admins

    • Special admin credentials
    • Access to admin dashboard
    • Product and order management

Security Features

  • Password Hashing β†’ bcrypt for secure password storage
  • Input Validation β†’ Server-side validation
  • CORS Protection β†’ Cross-origin request handling
  • Error Handling β†’ Secure error responses

🎯 State Management

React Context API

The application uses React Context for global state management:

// ShopContext provides:
- products: Array of all products
- cartItems: Current cart state
- token: Authentication token
- search: Search functionality
- currency: Price formatting
- delivery_fee: Shipping cost

State Operations

  • Add to Cart β†’ Update cart state and sync with backend
  • Update Quantity β†’ Modify cart items
  • Remove Items β†’ Remove from cart
  • Search Products β†’ Filter products based on search
  • Authentication β†’ Manage login state

Data Flow

  1. Context Provider β†’ Wraps entire app
  2. State Updates β†’ Functions update context state
  3. API Calls β†’ Sync state with backend
  4. Component Updates β†’ Components re-render on state changes

πŸš€ Deployment

Backend Deployment (Vercel)

  1. Build Configuration

    {
      "version": 2,
      "builds": [
        {
          "src": "server.js",
          "use": "@vercel/node"
        }
      ],
      "routes": [
        {
          "src": "/(.*)",
          "dest": "server.js"
        }
      ]
    }
  2. Environment Variables β†’ Set in Vercel dashboard

  3. Database β†’ Use MongoDB Atlas

  4. Deploy β†’ Connect GitHub repository

Frontend Deployment (Vercel)

  1. Build Command β†’ npm run build
  2. Output Directory β†’ dist
  3. Environment Variables β†’ Set backend URL
  4. Deploy β†’ Automatic deployment on push

Admin Deployment (Vercel)

  1. Same as Frontend β†’ Separate deployment
  2. Environment Variables β†’ Set backend URL
  3. Custom Domain β†’ Optional custom domain

🀝 Contributing

Development Guidelines

  1. Code Style β†’ Follow ESLint configuration
  2. Commit Messages β†’ Use conventional commits
  3. Testing β†’ Test all features before pushing
  4. Documentation β†’ Update docs for new features

Pull Request Process

  1. Fork Repository β†’ Create your fork
  2. Create Branch β†’ Feature branch from main
  3. Make Changes β†’ Implement your feature
  4. Test Thoroughly β†’ Ensure everything works
  5. Submit PR β†’ Create pull request with description

Code Structure

  • Components β†’ Reusable UI components
  • Pages β†’ Route-specific components
  • Controllers β†’ Business logic
  • Models β†’ Database schemas
  • Routes β†’ API endpoints
  • Middleware β†’ Request processing

πŸ“ License

This project is licensed under the ISC License.

πŸ™ Acknowledgments

  • React Team β†’ For the amazing React framework
  • Tailwind CSS β†’ For the utility-first CSS framework
  • MongoDB β†’ For the flexible NoSQL database
  • Cloudinary β†’ For image management services
  • Stripe & Razorpay β†’ For payment processing

πŸ†˜ Support

If you encounter any issues or have questions:

  1. Check Documentation β†’ Review this README thoroughly
  2. Environment Variables β†’ Ensure all required variables are set
  3. Database Connection β†’ Verify MongoDB connection
  4. Payment Keys β†’ Check payment gateway credentials
  5. File Upload β†’ Verify Cloudinary configuration

For additional help, please create an issue in the repository with:

  • Detailed error description
  • Steps to reproduce
  • Environment information
  • Screenshots (if applicable)

Happy Coding! πŸš€

About

Anyone is a premier global platform where the latest fashion trends converge. Discover and purchase the newest collections of clothing for men, women, and children from top brands worldwide.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors