Simple-E-commerce-API

E-commerce Application

A Flipkart-inspired e-commerce application built with Node.js, Express, MySQL, and vanilla JavaScript.

Project Structure

ecommerce/
├── backend/                 # Backend API server
│   ├── config/             # Database configuration
│   ├── controllers/        # Route controllers
│   ├── middlewares/        # Authentication middleware
│   ├── models/            # Database models
│   ├── routes/            # API routes
│   ├── app.js             # Main server file
│   └── package.json       # Backend dependencies
├── frontend/              # Frontend application
│   ├── assets/           # Product images and static files
│   ├── css/              # Stylesheets
│   ├── js/               # JavaScript files
│   ├── index.html        # Home page
│   ├── login.html        # Login page
│   ├── register.html     # Registration page
│   ├── products.html     # Products page
│   └── cart.html         # Shopping cart page
├── database/             # Database setup files
│   └── setup.sql         # Database schema and sample data
└── package.json          # Root package.json

Features

Issues Fixed

1. Password Security

2. Missing User Model

3. Database Schema Inconsistencies

4. Import Path Issues

5. Missing Environment Configuration

Setup Instructions

Prerequisites

Backend Setup

  1. Install dependencies:
    cd backend
    npm install
    
  2. Set up environment variables:
    cp env.example .env
    # Edit .env with your database credentials and JWT secret
    
  3. Set up database:
    mysql -u root -p < ../database/setup.sql
    
  4. Start the server:
    npm run dev
    

Frontend Setup

  1. Add product images:
    • Download product images and place them in frontend/assets/
    • Required images: smartphone.jpg, laptop.jpg, headphones.jpg, smartwatch.jpg, speaker.jpg
  2. Open in browser:
    • Navigate to frontend/index.html
    • Or serve with a local server: python -m http.server 8000

API Endpoints

Authentication

Products

Cart

Orders

Security Features

Deployment

Backend (Render/Railway)

  1. Connect your GitHub repository
  2. Set environment variables
  3. Deploy with Node.js buildpack

Database (MongoDB Atlas)

  1. Create MongoDB Atlas cluster
  2. Update connection string in environment variables
  3. Update database configuration

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This project is licensed under the ISC License.