Skip to content

harshalkumar-ishi/django-ecommerce-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛒 Django E-commerce API

A production-ready, full-featured E-commerce REST API built with Django REST Framework, PostgreSQL, Redis, Celery, and Docker.

Python Django DRF PostgreSQL Redis Celery Docker Razorpay


📌 Features

Feature Details
🔐 JWT Auth + RBAC Register, login, token refresh, blacklist on logout
🛍️ Products & Categories CRUD, nested categories, image gallery, reviews, ratings
🔍 Smart Search + Filters Search by name/description/SKU, filter by price/category/stock/sale
🛒 Redis-cached Cart Add/update/remove items, auto-invalidate cache on change
🎟️ Dynamic Coupons Percentage & flat discounts, usage limits, per-user limits, expiry
📦 Orders + Timeline Place orders, full status history (pending→shipped→delivered)
💳 Razorpay Payments Create order, verify signature, webhook, payment retry system
❤️ Wishlist + Price Alerts Save products, get notified when price drops
🤖 Recommendations Personalized suggestions based on wishlist + order history
⚙️ Background Jobs Order confirmation emails, price alert checks, auto-cancel
🕐 Scheduled Tasks Price alerts (hourly), auto-cancel orders (daily) via Celery Beat

🏗️ Project Structure

django-ecommerce-api/
├── apps/
│   ├── products/         # Categories, Products, Reviews, Search
│   ├── cart/             # Redis-cached Cart, Coupon application
│   ├── orders/           # Orders, Timeline tracking, Background tasks
│   ├── payments/         # Razorpay integration, Webhook, Retry
│   ├── coupons/          # Dynamic discount system
│   └── wishlist/         # Wishlist, Price alerts, Recommendations
├── config/
│   ├── settings.py       # All settings: JWT, Redis, Celery, Razorpay
│   ├── celery.py         # Celery app instance
│   └── urls.py           # Root URL conf + Swagger
├── scripts/
│   ├── entrypoint.sh     # Web: wait → migrate → seed → runserver
│   ├── start_worker.sh   # Celery worker
│   └── start_beat.sh     # Celery beat
├── Dockerfile
├── docker-compose.yml    # 5 services: db, redis, web, worker, beat
└── .env.example

🚀 Quick Start

git clone https://github.com/harshalkumar-ishi/django-ecommerce-api.git
cd django-ecommerce-api
cp .env .env.example

docker-compose up --build -d

On startup, the entrypoint script automatically:

  • Waits for PostgreSQL + Redis to be healthy
  • Runs all migrations
  • Seeds demo categories, products, coupons
  • Seeds Celery Beat schedules
  • Starts the Django server

📖 API Endpoints

Auth

Method Endpoint Description
POST /api/v1/auth/register/ Register new user
POST /api/v1/auth/login/ Login, get JWT tokens
POST /api/v1/auth/logout/ Blacklist refresh token
POST /api/v1/auth/token/refresh/ Refresh access token
GET/PATCH /api/v1/auth/profile/ View / update profile

Products

Method Endpoint Description
GET /api/v1/products/ List products (filter, search, sort)
GET /api/v1/products/featured/ Featured products
GET /api/v1/products/search/?q=iphone Smart search
GET /api/v1/products/<slug>/ Product detail
GET /api/v1/products/<slug>/related/ Related products
GET/POST /api/v1/products/<slug>/reviews/ Reviews
GET/POST /api/v1/products/categories/ Categories

Cart

Method Endpoint Description
GET /api/v1/cart/ View cart (Redis cached)
POST /api/v1/cart/items/ Add item
PATCH /api/v1/cart/items/<id>/ Update quantity
DELETE /api/v1/cart/items/<id>/ Remove item
POST /api/v1/cart/coupon/ Apply coupon
DELETE /api/v1/cart/coupon/ Remove coupon

Orders

Method Endpoint Description
GET /api/v1/orders/ My orders
POST /api/v1/orders/place/ Place order from cart
GET /api/v1/orders/<id>/ Order detail + timeline
POST /api/v1/orders/<id>/cancel/ Cancel order

Payments

Method Endpoint Description
POST /api/v1/payments/create/ Create Razorpay order
POST /api/v1/payments/verify/ Verify payment signature
GET /api/v1/payments/<order_id>/detail/ Payment status
POST /api/v1/payments/<order_id>/retry/ Retry failed payment
POST /api/v1/payments/webhook/razorpay/ Razorpay webhook

Wishlist

Method Endpoint Description
GET /api/v1/wishlist/ View wishlist
POST /api/v1/wishlist/items/ Add product
DELETE /api/v1/wishlist/items/<id>/ Remove product
PATCH /api/v1/wishlist/items/<id>/alert/ Set price alert
GET /api/v1/wishlist/recommendations/ Get recommendations

💳 Razorpay Integration Flow

1. POST /api/v1/payments/create/    → Get razorpay_order_id
2. Use Razorpay JS SDK on frontend  → User completes payment
3. POST /api/v1/payments/verify/    → Verify signature, confirm order
4. Webhook /payments/webhook/       → Server-to-server confirmation backup
5. POST /payments/<id>/retry/       → Retry on failure (max 3 attempts)

🎟️ Coupon System

Coupon Type Value Condition
WELCOME10 Percentage 10% off
FLAT200 Flat ₹200 off Min order ₹999
SAVE20 Percentage 20% off Max discount ₹500

🕐 Scheduled Tasks

Task Schedule Description
Check price alerts Every hour Email users when wishlist price drops
Auto-cancel pending orders Daily midnight Cancel unpaid orders after 24h

📦 Tech Stack

Layer Technology
Framework Django 4.2, Django REST Framework
Auth djangorestframework-simplejwt
Database PostgreSQL 15
Cache Redis 7 (django-redis)
Task Queue Celery 5 + django-celery-beat
Payment Razorpay
Search/Filter django-filter
Docs drf-spectacular (Swagger + ReDoc)
Containerisation Docker, Docker Compose

Built by Harshalkumar Ishi

About

A production-ready, full-featured E-commerce REST API built with Django REST Framework, PostgreSQL, Redis, Celery, and Docker.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors