Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛒 E-Commerce API (High-Performance RESTful Backend)

Node.js Express.js MongoDB

A complete, production-ready backend API for a fully functional E-commerce platform. Built with Node.js, Express, and MongoDB, focusing on scalability, clean code architecture, and robust security measures.

This project implements advanced features like real-time stock management, secure cart operations, image processing, and comprehensive data validation.

🛠️ Tech Stack

  • Runtime Environment: Node.js
  • Framework: Express.js
  • Database: MongoDB (with Mongoose ODM)
  • Authentication JWT, Bcryptjs
  • Validation: Joi
  • File Uploads: Multer
  • Email: Nodemailer
  • Payment: Fawaterk API
  • Dev Tools: ngrok (for local Webhook testing), Postman
  • Security: Helmet, rateLimit, hpp, cors
  • Performance: Compression
  • Utilities: Slugify, express-async-handler

🚀 Key Features

🔐 Security & Authentication

  • JWT Authentication: Secure login and registration system using JSON Web Tokens.
  • Role-Based Access Control (RBAC): Distinct roles for User and Admin (e.g., only admins can manage products/categories).
  • Parameter Pollution: Protected against HPP (HTTP Parameter Pollution).
  • Rate Limiting: Prevents brute-force attacks and DoS.

📦 Product & Category Management

  • CRUD Operations: Full management for Products, Categories, Subcategories, and Brands.
  • Advanced Filtering: Filter by price, category, ratings, etc.
  • Pagination & Sorting: Efficient data retrieval for large datasets.
  • Image Handling:
    • Multiple image uploads using Multer.
    • Auto-Cleanup: System automatically deletes images from the server when a product or category is deleted to save storage space.

🛒 Smart Cart System

  • Server-Side Calculations: Prices and totals are calculated on the backend to prevent manipulation.
  • Stock Validation:
    • Prevents adding items exceeding available stock.
    • Automatically checks stock levels before updating quantities.
  • Product Merging: Automatically merges duplicate items in the cart instead of creating new rows.
  • Cart Cleanup: Automatically removes the cart if the last item is deleted.

⭐ Reviews & Ratings

  • Real-time Average: Automatically calculates and updates the average rating and quantity of reviews for each product.
  • Duplicate Prevention: Ensures a user can review a product only once.

🛠️ Error Handling & Validation

  • Global Error Handling: Centralized error controller for consistent API responses.
  • Joi Validation: Strict validation for all incoming data (Body, Params, Queries).
  • Friendly Error Messages: Clear messages for frontend developers (e.g., "Stock limit reached").

💳 Secure Payment Integration

  • Online Payment Gateway: Integrated with Fawaterk to accept secure online payments (Credit Cards, Wallets, etc.).
  • Automated Order Management:
    • Creates secure checkout sessions.
    • Webhook Handling: Listens to payment gateway webhooks to automatically update order status (e.g., from Pending to Paid) in real-time.
    • Handles payment failures and cancellations gracefully.

🗄 Running Locally

  • Prerequisites

  • 1-Clone the Repository and Install Dependencies

git clone https://github.com/AhmedSedkyy/nodejs-ecommerce-api

cd nodejs-ecommerce-api

npm install
  • 2-Create a .env file
PORT=3000

DATABASE=mongodb://0.0.0.0:27017/e-commerce

JWT_SECRET=your_secret_key


FAWATERAK_BASE_URL=https://staging.fawaterk.com
FAWATERAK_API_TOKEN=Your FAWATERAK_API_TOKEN


EMAIL_HOST=smtp.gmail.com 
EMAIL_PORT=465
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_email_app_password

  • 3-Run the Server
npm start

👤 Author

[Ahmed Sedky]

LinkedIn GitHub

About

A robust, production-ready E-commerce REST API built with Node.js, Express, and MongoDB. Features include JWT Auth, Online Payments (Fawaterk), Real-time Stock Management, and Advanced Security layers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages