A production-ready Django REST Framework e-commerce backend for a fashion/clothing store. Built with async task processing, multi-container Docker setup, and CI/CD pipeline. Supports product management, inventory, cart, orders, coupons, payments (SSLCommerz + Cash on Delivery), reviews, and automated background jobs.
| Resource | URL |
|---|---|
| Swagger UI | https://urbanthread-6nok.onrender.com/api/docs/ |
| ReDoc | https://urbanthread-6nok.onrender.com/redoc/ |
| Admin | https://urbanthread-6nok.onrender.com/admin/ |
- π§΅ Urban Thread β E-Commerce REST API
- π Live Demo
- π Table of Contents
- π Tech Stack
- π Project Structure
- β¨ Features
- π Architecture Overview
- βοΈ Installation & Setup
- π Environment Variables
- π Running the Server
- β‘ Background Tasks (Celery)
- π‘ API Endpoints
- π Authentication
- π³ Payment Integration
- π‘ Admin Panel
- π API Documentation
- π CI/CD Pipeline
- π License
| Layer | Technology |
|---|---|
| Framework | Django 4.x + Django REST Framework |
| Auth | JWT via djangorestframework-simplejwt |
| Database | PostgreSQL (production) / SQLite (dev) |
| Cache & Broker | Redis (separate instances for cache and Celery broker) |
| Async Tasks | Celery + Celery Beat (periodic tasks) |
| Payment Gateway | SSLCommerz + Cash on Delivery |
| Filtering | django-filter |
| API Docs | drf-spectacular (Swagger UI) + drf-yasg (ReDoc) |
| Containerization | Docker + Docker Compose (multi-container) |
| CI/CD | GitHub Actions |
| CORS | django-cors-headers |
| Config | python-decouple |
urbanthread/
βββ .github/
β βββ workflows/ # GitHub Actions CI/CD pipeline
βββ accounts/ # Custom user, profile, address, email verification
βββ cart/ # Shopping cart & cart items
βββ coupons/ # Discount coupon management + auto-expiry tasks
βββ inventory/ # Stock management per product variant
βββ orders/ # Order creation, management, auto-cancellation tasks
βββ payments/ # SSLCommerz & Cash on Delivery integration
βββ products/ # Category, brand, product, images, size, color
βββ reviews/ # Product reviews & ratings
βββ urbanthread/ # Project settings, URLs, WSGI/ASGI, Celery config
βββ Dockerfile
βββ docker-compose.yml
βββ manage.py
βββ requirements.txt
- User Auth β Register with email verification, login/logout via JWT, token refresh & blacklist
- Products β Full CRUD for categories, brands, products, images, sizes, colors
- Inventory β Track stock per (product Γ color Γ size) variant with real-time availability check
- Cart β Add, update, remove items with real-time stock validation
- Coupons β Percentage-based discount coupons with expiry dates
- Orders β Place orders from cart, cancel orders, view history; inventory auto-decremented on order placement
- Payments β SSLCommerz online payment + Cash on Delivery; IPN webhook support; refunds
- Reviews β Authenticated users can leave 1β5 star reviews on products
- Email Verification β Async email dispatch with retry logic on failure
- Coupon Auto-Expiry β Periodic task marks expired coupons as inactive
- Order Auto-Cancellation β Cancels unpaid/stale orders after a configurable timeout
- Low Stock Alerts β Notifies admins when inventory drops below threshold
- Abandoned Cart Reminders β Sends reminder emails to users with inactive carts
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Docker Compose β
β β
β ββββββββββββ ββββββββββββ βββββββββββββββββββ β
β β Django β β Celery β β Celery Beat β β
β β (web) β β Worker β β (Scheduler) β β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββββββ¬βββββββββ β
β β β β β
β ββββββΌβββββββββββββββΌβββββββββββββββββββΌβββββββββ β
β β Redis (Broker) β β
β βββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββ βββββββββββββββββββββββββ β
β β Redis (Cache) β β PostgreSQL β β
β βββββββββββββββββββ βββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Two separate Redis instances: one for Celery broker/results, one for Django cache.
Prerequisites: Docker & Docker Compose installed.
# 1. Clone the repository
git clone https://github.com/MNR-Tushar/UrbanThread.git
cd UrbanThread
# 2. Create environment file
cp .env.example .env
# Edit .env with your values
# 3. Build and start all containers
docker compose up --build
# 4. In a new terminal, run migrations
docker compose exec web python manage.py migrate
# 5. Create a superuser
docker compose exec web python manage.py createsuperuserThe API will be available at http://localhost:8000/
Services started by Docker Compose:
| Service | Description |
|---|---|
web |
Django application server |
db |
PostgreSQL database |
redis_broker |
Redis for Celery broker & results |
redis_cache |
Redis for Django cache |
celery |
Celery worker for async tasks |
celery_beat |
Celery Beat scheduler for cron tasks |
Prerequisites: Python 3.10+, PostgreSQL, Redis
# 1. Clone the repository
git clone https://github.com/MNR-Tushar/UrbanThread.git
cd UrbanThread
# 2. Create & activate virtual environment
python -m venv venv
source venv/bin/activate # macOS/Linux
# venv\Scripts\activate # Windows
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment variables
cp .env.example .env
# Edit .env with your values
# 5. Apply migrations
python manage.py migrate
# 6. Create superuser
python manage.py createsuperuser
# 7. Start Celery worker (separate terminal)
celery -A urbanthread worker --loglevel=info
# 8. Start Celery Beat scheduler (separate terminal)
celery -A urbanthread beat --loglevel=info
# 9. Run the server
python manage.py runserverCreate a .env file in the project root:
# Django
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
# Database (PostgreSQL)
DB_NAME=urbanthread
DB_USER=postgres
DB_PASSWORD=your-db-password
DB_HOST=db # 'db' for Docker, 'localhost' for local
DB_PORT=5432
# Redis β Celery Broker
REDIS_BROKER_URL=redis://redis_broker:6379/0
# Redis β Django Cache
REDIS_CACHE_URL=redis://redis_cache:6379/0
# SSLCommerz Payment Gateway
SSLCOMMERZ_STORE_ID=your_store_id
SSLCOMMERZ_STORE_PASSWORD=your_store_password
SSLCOMMERZ_IS_SANDBOX=True
# Frontend URL (for payment redirects)
FRONTEND_URL=http://localhost:3000
# Email
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_HOST_USER=[email protected]
EMAIL_HOST_PASSWORD=your-app-password
DEFAULT_FROM_EMAIL=[email protected]docker compose uppython manage.py runserverUrban Thread uses Celery for async and periodic task processing with Redis as the message broker.
| Task | Trigger | Description |
|---|---|---|
send_verification_email |
User registration | Sends email verification link asynchronously with retry on failure |
| Task | Schedule | Description |
|---|---|---|
expire_coupons |
Every hour | Marks expired coupons as inactive |
auto_cancel_orders |
Every 30 min | Cancels unpaid orders past timeout |
send_low_stock_alerts |
Daily | Emails admin for low-inventory variants |
send_abandoned_cart_reminders |
Daily | Sends reminder emails to users with old active carts |
# View worker logs
docker compose logs celery
# View beat scheduler logs
docker compose logs celery_beat
# Check active tasks
docker compose exec celery celery -A urbanthread inspect activeAll API routes are prefixed with their app name. Protected routes require:
Authorization: Bearer <access_token>
Base URL: /accounts/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /accounts/register/ |
Public | Register + sends verification email |
| POST | /accounts/login/ |
Public | Login and receive JWT tokens |
| POST | /accounts/logout/ |
Required | Blacklist refresh token / logout |
| POST | /accounts/token/refresh/ |
Public | Refresh access token |
| GET | /accounts/allusers/ |
Required | List users (admins see all) |
| GET/PUT/PATCH | /accounts/allusers/{id}/ |
Required | Get/update user |
| GET/POST | /accounts/address/ |
Required | List or create addresses |
| GET/PUT/PATCH/DELETE | /accounts/address/{id}/ |
Required | Manage a single address |
| GET/POST | /accounts/profile/ |
Required | List or create profile |
| GET/PUT/PATCH/DELETE | /accounts/profile/{id}/ |
Required | Manage profile |
Register example:
POST /accounts/register/
{
"username": "john_doe",
"email": "[email protected]",
"password": "securepassword123"
}A verification email is sent asynchronously via Celery after registration.
Base URL: /products/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /products/categories/ |
Public | List all categories |
| POST | /products/categories/ |
Admin | Create category |
| GET | /products/brands/ |
Public | List all brands |
| POST | /products/brands/ |
Admin | Create brand |
| GET | /products/products/ |
Public | List all products |
| POST | /products/products/ |
Admin | Create product |
| GET | /products/products/{id}/ |
Public | Product detail |
| PUT/PATCH/DELETE | /products/products/{id}/ |
Admin | Update/delete product |
| GET/POST | /products/product-images/ |
Admin | Manage product images |
| GET | /products/sizes/ |
Public | List all sizes |
| GET | /products/colors/ |
Public | List all colors |
Filtering & Search:
- Filter:
?category=<id>&brand=<id>&is_available=true - Search:
?search=<keyword> - Order:
?ordering=priceor?ordering=-created_at - Pagination:
?limit=10&offset=0
Base URL: /inventorys/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /inventorys/inventorys/ |
Public | List all inventory |
| POST | /inventorys/inventorys/ |
Admin | Create inventory entry |
| GET | /inventorys/inventorys/{id}/ |
Public | Single inventory entry |
| PUT/PATCH/DELETE | /inventorys/inventorys/{id}/ |
Admin | Update/delete inventory |
| GET | /inventorys/inventorys/check_availability/ |
Public | Check stock for a variant |
| GET | /inventorys/inventorys/product_inventory/ |
Public | All inventory for a product |
Check availability:
GET /inventorys/inventorys/check_availability/?product_id=1&color_id=2&size_id=3
Base URL: /cart/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /cart/my_cart/ |
Required | View current user's cart |
| POST | /cart/add_item/ |
Required | Add item to cart |
| PATCH | /cart/update_item/ |
Required | Update item quantity |
| DELETE | /cart/remove_item/ |
Required | Remove a single item |
| DELETE | /cart/clear_cart/ |
Required | Clear all items from cart |
Base URL: /coupons/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /coupons/ |
Required | List coupons |
| GET | /coupons/{id}/ |
Required | Get single coupon |
| POST | /coupons/ |
Admin | Create coupon |
| PUT/PATCH/DELETE | /coupons/{id}/ |
Admin | Update/delete coupon |
| POST | /coupons/validate_coupon/ |
Required | Validate a coupon code |
Expired coupons are automatically deactivated by the
expire_couponsCelery Beat task.
Base URL: /orders/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /orders/create_order/ |
Required | Place an order from the cart |
| PATCH | /orders/{id}/cancel_order/ |
Required | Cancel a pending/processing order |
| GET | /orders/order_history/ |
Required | View order history |
Create order example:
POST /orders/create_order/
{
"address_id": 1,
"payment_method": "cash_on_delivery",
"coupon_code": "SAVE20"
}Supported payment methods:
cash_on_delivery,sslcommerz
Order status flow: pending β processing β completed / cancelled
Unpaid orders are automatically cancelled after a timeout by the
auto_cancel_ordersCelery Beat task.
Base URL: /payments/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /payments/initiate/ |
Required | Initiate payment for an order |
| POST | /payments/sslcommerz/success/ |
Public | SSLCommerz success callback |
| POST | /payments/sslcommerz/fail/ |
Public | SSLCommerz fail callback |
| POST | /payments/sslcommerz/cancel/ |
Public | SSLCommerz cancel callback |
| POST | /payments/sslcommerz/ipn/ |
Public | SSLCommerz IPN webhook |
| POST | /payments/refund/ |
Admin | Initiate refund |
| GET | /payments/ |
Required | List payments |
| GET | /payments/{id}/ |
Required | Payment detail |
| GET | /payments/{id}/logs/ |
Required | Payment logs |
| GET | /payments/my_payments/ |
Required | Current user's payments |
Base URL: /reviews/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /reviews/ |
Public | List all reviews |
| GET | /reviews/?product_id=<id> |
Public | Reviews for a specific product |
| GET | /reviews/{id}/ |
Public | Single review |
| POST | /reviews/ |
Required | Create a review |
| PUT/PATCH | /reviews/{id}/ |
Required | Update your review |
| DELETE | /reviews/{id}/ |
Required | Delete your review |
Rating must be between 1 and 5.
Urban Thread uses JWT (JSON Web Token) authentication via djangorestframework-simplejwt.
- Register or login to receive
accessandrefreshtokens. - Include the access token in every protected request:
Authorization: Bearer <access_token> - Use
/accounts/token/refresh/with your refresh token to get a new access token. - Use
/accounts/logout/to blacklist the refresh token on logout.
- Get sandbox credentials from SSLCommerz Developer Portal.
- Set
SSLCOMMERZ_STORE_ID,SSLCOMMERZ_STORE_PASSWORD, andSSLCOMMERZ_IS_SANDBOX=Truein.env. - Call
POST /payments/initiate/β redirect user to returnedgateway_url. - SSLCommerz calls the success/fail/cancel/IPN endpoints automatically.
Set payment_method: "cash_on_delivery" when creating the order. The order is placed immediately with payment_status: unpaid.
Access the Django admin at: http://127.0.0.1:8000/admin/
All models are registered with sensible list displays, search, and filters including:
- Users, profiles, and addresses
- Products, brands, categories, images, sizes, colors
- Inventory stock levels per variant
- Orders and order items with status management
- Coupons with expiry tracking
- Payments with status badges and payment logs
- Celery periodic task management (via
django-celery-beat)
Two interactive API documentation UIs are available after starting the server:
| UI | URL |
|---|---|
| Swagger UI (drf-spectacular) | http://127.0.0.1:8000/api/docs/ |
| Swagger UI (drf-yasg) | http://127.0.0.1:8000/swagger/ |
| ReDoc | http://127.0.0.1:8000/redoc/ |
| OpenAPI JSON/YAML | http://127.0.0.1:8000/api/schema/ |
The project uses GitHub Actions for automated testing and deployment on every push to main.
Pipeline steps:
- Lint β Code style checks
- Test β Run test suite with pytest
- Build β Build Docker image
- Deploy β Push to registry / deploy to server
Pipeline configuration: .github/workflows/
This project is licensed under the MIT License.