A full-featured Django REST Framework e-commerce backend for a fashion/clothing store. Supports product management, inventory, cart, orders, coupons, payments (SSLCommerz + Cash on Delivery), and reviews.
- π§΅ Urban Thread β E-Commerce REST API
| Layer | Technology |
|---|---|
| Framework | Django 6.x + Django REST Framework |
| Auth | JWT via djangorestframework-simplejwt |
| Database | SQLite (dev) β easily swappable to PostgreSQL |
| Payment Gateway | SSLCommerz |
| Filtering | django-filter |
| API Docs | drf-spectacular (Swagger) + drf-yasg (ReDoc) |
| CORS | django-cors-headers |
| Config | python-decouple |
urbanthread/
βββ accounts/ # Custom user, profile, address
βββ products/ # Category, brand, product, images, size, color
βββ inventory/ # Stock management per product variant
βββ cart/ # Shopping cart & cart items
βββ coupons/ # Discount coupon management
βββ orders/ # Order creation and management
βββ payments/ # SSLCommerz & Cash on Delivery integration
βββ reviews/ # Product reviews & ratings
βββ urbanthread/ # Project settings, URLs, WSGI/ASGI
βββ manage.py
- User Auth β Register, login, logout with JWT tokens
- Products β Full CRUD for categories, brands, products, images, sizes, colors
- Inventory β Track stock per (product Γ color Γ size) variant
- 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
- Payments β SSLCommerz online payment + Cash on Delivery; IPN support; refunds
- Reviews β Authenticated users can leave 1β5 star reviews on products
- API Docs β Swagger UI and ReDoc available out of the box
git clone https://github.com/MNR-Tushar/urbanthread.git
cd urbanthreadpython -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activatepip install -r requirements.txtIf you don't have a
requirements.txtyet, install the core packages:pip install django djangorestframework djangorestframework-simplejwt django-cors-headers django-filter drf-spectacular drf-yasg python-decouple pillow requests
Create a .env file in the project root (see Environment Variables below).
python manage.py migratepython manage.py createsuperuserpython manage.py collectstaticCreate a .env file in the root directory with the following keys:
# Django
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
# 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 (optional)
EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_HOST_USER=your@email.com
EMAIL_HOST_PASSWORD=your-email-password
DEFAULT_FROM_EMAIL=noreply@urbanthread.compython manage.py runserverThe API will be available at: http://127.0.0.1:8000/
All API routes are prefixed with their app name. JWT Authorization: Bearer <access_token> header is required for protected routes.
Base URL: /accounts/
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /accounts/register/ |
Public | Register a new user |
| 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": "john@example.com",
"password": "securepassword123"
}Login example:
POST /accounts/login/
{
"email": "john@example.com",
"password": "securepassword123"
}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 (products):
- 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 |
Add item example:
POST /cart/add_item/
{
"product_id": 1,
"color_id": 2,
"size_id": 3,
"quantity": 2
}Update item example:
PATCH /cart/update_item/
{
"item_id": 5,
"quantity": 4
}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 |
Validate coupon example:
POST /coupons/validate_coupon/
{
"code": "SAVE20"
}Response:
{
"valid": true,
"discount": 20.0,
"code": "SAVE20",
"message": "Coupon applied! You get 20.00% off"
}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 values: pending β processing β completed / cancelled
Payment status values: unpaid β paid / refunded
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 |
Initiate SSLCommerz payment:
POST /payments/initiate/
{
"order_number": "ORD-ABC12345",
"payment_method": "sslcommerz"
}Response:
{
"success": true,
"gateway_url": "https://sandbox.sslcommerz.com/...",
"session_key": "...",
"transaction_id": "TXN-..."
}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 |
Create review example:
POST /reviews/
{
"product": 1,
"rating": 4,
"review_text": "Great quality shirt, fits perfectly!"
}Rating must be between 1 and 5.
Urban Thread uses JWT (JSON Web Token) authentication.
- Register or login to receive
accessandrefreshtokens. - Include the access token in the request header:
Authorization: Bearer <access_token> - Access tokens expire after 60 days; refresh tokens after 10 days.
- Use
/accounts/token/refresh/with your refresh token to get a new access token. - Use
/accounts/logout/to blacklist the refresh token.
- Get sandbox credentials from SSLCommerz.
- Set
SSLCOMMERZ_STORE_ID,SSLCOMMERZ_STORE_PASSWORD, andSSLCOMMERZ_IS_SANDBOX=Truein.env. - Call
POST /payments/initiate/withpayment_method: "sslcommerz"to get a gateway URL. - Redirect the user to
gateway_url. - SSLCommerz will call the success/fail/cancel/IPN endpoints automatically.
Set payment_method: "cash_on_delivery" when creating the order or initiating payment. 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 filter configurations, including:
- Users, profiles, and addresses
- Products, brands, categories, images, sizes, colors
- Inventory stock levels
- Orders and order items
- Coupons
- Payments with status badges and payment logs
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/ |
This project is licensed under the MIT License.