Skip to main content

Overview

The E-commerce API is a production-ready REST API built with Node.js, Express, TypeScript, and Prisma ORM. It provides a complete backend solution for e-commerce applications with robust authentication, product management, shopping cart functionality, and order processing.

Quick Start

Get up and running in minutes with our step-by-step guide

API Reference

Explore all available endpoints and their parameters

Installation

Complete setup guide for development and production

Authentication

Learn about JWT-based authentication and authorization

Key Features

Authentication & Authorization

  • JWT-based authentication with secure token generation
  • Role-based access control (customer/admin roles)
  • Rate limiting on auth endpoints (10 requests per 15 minutes)
  • Password hashing with bcrypt
  • User registration, login, and profile management

Product Management

  • Full CRUD operations for products
  • Image upload support with Cloudinary integration
  • Product categorization
  • Stock tracking and inventory management
  • Search and filtering capabilities
  • Public read access, admin-only write access

Shopping Cart

  • User-specific cart management
  • Add, update, and remove items
  • Automatic quantity validation
  • Cart persistence across sessions
  • Real-time total calculations

Order Processing

  • Create orders from cart contents
  • Order history tracking
  • Order status management (pending, shipped, delivered, cancelled)
  • Price snapshots at purchase time
  • User-specific order queries

Security Features

  • Helmet.js for HTTP security headers
  • CORS configuration with credential support
  • Rate limiting on sensitive endpoints
  • File upload restrictions (5MB max, safe filenames)
  • Input validation with class-validator
  • SQL injection protection via Prisma ORM

Tech Stack

Runtime

Node.js with TypeScript

Framework

Express.js 5.x

Database

MySQL 8.4 with Prisma ORM

Authentication

JWT (jsonwebtoken)

Architecture

The API follows a layered architecture pattern:
  • Routes: Define API endpoints and apply middleware
  • Middleware: Handle authentication, validation, and error handling
  • Controllers: Process HTTP requests and responses
  • Services: Implement business logic
  • Repositories: Abstract database operations
  • Prisma Client: Type-safe database queries

API Structure

The API is organized into the following main modules:
ModuleBase PathDescription
Authentication/authUser registration, login, profile management
Products/productsProduct catalog management
Categories/categoriesProduct category organization
Cart/cartShopping cart operations
Orders/ordersOrder creation and history

Data Models

The API uses the following core data models:

User

  • id: Integer (auto-increment)
  • name: String
  • email: String (unique)
  • passwordHash: String (bcrypt hashed)
  • role: Enum (customer, admin)
  • Relations: cart, orders

Product

  • id: Integer (auto-increment)
  • name: String (indexed)
  • description: String (optional)
  • price: Decimal (10,2)
  • imageUrl: String
  • stock: Integer
  • categoryId: Integer (optional)
  • Relations: category, cartItems, orderItems

Cart & CartItem

  • One-to-one relationship with User
  • CartItems track product quantity in cart
  • Automatic cascade deletion

Order & OrderItem

  • Order status tracking (pending, shipped, delivered, cancelled)
  • OrderItems capture price at purchase time
  • Indexed by userId and status

Response Format

All API responses follow consistent patterns: Success Response:
{
  "message": "Operation successful",
  "data": { ... }
}
Error Response:
{
  "error": "Error message",
  "details": [ ... ]
}
All timestamps are in ISO 8601 format (UTC timezone)

Rate Limits

Authentication endpoints (/auth/register, /auth/login) are rate-limited to 10 requests per 15 minutes per IP address.
Other endpoints currently have no rate limits but may be added in future versions.

Getting Help

If you need assistance:
  1. Check the Quick Start Guide for common setup issues
  2. Review the API Reference for endpoint details
  3. Examine the Installation Guide for environment configuration

Next Steps

1

Install the API

Follow the Installation Guide to set up your development environment
2

Try the Quick Start

Complete the Quick Start Tutorial to make your first API calls
3

Explore the API

Browse the API Reference to discover all available endpoints

Build docs developers (and LLMs) love