A production-grade REST API backend for an e-commerce platform built with Django and Django REST Framework.
- API Docs: coming soon on Render
- Frontend: ecommerce-frontend
| Layer | Technology |
|---|---|
| Backend | Python 3.12, Django |
| API | Django REST Framework |
| Auth | JWT (simplejwt) + token blacklisting |
| Database | PostgreSQL (prod), SQLite (dev) |
| Images | Pillow |
| API Docs | drf-spectacular (Swagger) |
| Testing | pytest — 35 tests passing |
| Container | Docker + docker-compose |
| CI/CD | GitHub Actions |
| Deployment | Render |
ecommerce/
├── users/ # Custom user model, JWT auth, profile
├── products/ # Products, categories, custom permissions
├── cart/ # Shopping cart — add, update, remove, clear
├── reviews/ # Product reviews, signals for avg_rating
├── orders/ # Checkout, order history, cancel, stock management
├── wishlist/ # Save products for later, toggle add/remove
├── coupons/ # Discount codes — percentage or fixed amount
└── e_commerce/ # Project settings, urls, wsgi
- JWT Authentication — register, login, logout with token blacklisting and auto refresh
- Custom User Model — email-based login, seller/buyer roles
- Products — CRUD with category filtering, search, pagination, custom seller permissions
- Shopping Cart — add, update quantity, remove items, stock validation
- Orders — checkout with stock deduction, order history, cancel with stock restore
- Reviews — one review per product per user, signals auto-update avg rating
- Wishlist — toggle add/remove
- Coupons — percentage and fixed discount, expiry and usage limit validation
- Async Emails — order confirmation sent in background thread
- Race Condition Protection — select_for_update() on checkout
- Swagger Docs — full API documentation at /api/docs/
| Endpoint | Methods | Description |
|---|---|---|
/api/auth/register/ |
POST | Register a new user |
/api/auth/login/ |
POST | Login and obtain authentication token |
/api/auth/logout/ |
POST | Logout authenticated user |
/api/auth/profile/ |
GET | Retrieve current user profile |
/api/products/ |
GET | List all products |
/api/products/create/ |
POST | Create a new product (seller only) |
/api/products/<id>/ |
GET | Retrieve product details |
/api/products/<id>/reviews/ |
GET | List reviews for a product |
/api/products/<id>/reviews/add/ |
POST | Add a review to a product |
/api/cart/ |
GET | Retrieve cart items |
/api/cart/add/ |
POST | Add item to cart |
/api/cart/<id>/ |
PUT | Update cart item quantity |
/api/cart/<id>/ |
DELETE | Remove item from cart |
/api/cart/ |
DELETE | Clear cart |
/api/orders/checkout/ |
POST | Create order from cart |
/api/orders/ |
GET | List user orders |
/api/orders/<id>/ |
GET | Retrieve order details |
/api/orders/<id>/cancel/ |
POST | Cancel an order |
/api/wishlist/ |
GET | Retrieve wishlist items |
/api/wishlist/toggle/ |
POST | Add or remove product from wishlist |
/api/coupons/validate/ |
POST | Validate coupon code |
/api/docs/ |
GET | API documentation |
1. Clone the repo
git clone https://github.com/Nick0099/E_Commerce.git
cd E_Commerce2. Install dependencies
pip install -r requirements.txt3. Run migrations
python manage.py migrate
python manage.py createsuperuser4. Start the server
python manage.py runserver5. Visit API docs
http://localhost:8000/api/docs/
docker-compose up --build
docker-compose exec web python manage.py createsuperuserpytest --tb=short35 tests across users, products, cart, orders and coupons.
| Key | Description |
|---|---|
SECRET_KEY |
Django secret key |
DEBUG |
True/False |
DATABASE_URL |
PostgreSQL connection URL |
Nischal Neupane — nischalneupane45@gmail.com