A production-ready E-Commerce Backend API built with Django REST Framework and PostgreSQL — featuring complete shopping functionality with JWT Authentication, Role-based Access Control, Cart Management, Order Processing, and Product Reviews.
Base URL: https://web-production-746fb.up.railway.app/api/register
- ✅ JWT Authentication — Secure Register, Login, Token Refresh
- ✅ Role-based Access — Admin vs Customer permissions
- ✅ Products Management — Full CRUD with image upload
- ✅ Categories — Product categorization system
- ✅ Cart System — Add, Remove, Update quantity
- ✅ Order Processing — Place orders, track history
- ✅ Reviews & Ratings — Product review system
- ✅ Search & Filter — By name, category, price range
- ✅ Pagination — 10 products per page
- ✅ PostgreSQL — Production-grade database
| Technology | Usage |
|---|---|
| Python 3.11 | Core Language |
| Django 4.2 | Web Framework |
| Django REST Framework | API Development |
| PostgreSQL | Database |
| SimpleJWT | Authentication |
| Pillow | Image Handling |
| django-filter | Search & Filtering |
| python-decouple | Environment Variables |
| Railway | Cloud Deployment |
ecommerce-api/
├── store/
│ ├── models.py # Product, Cart, Order, Review models
│ ├── serializers.py # Data serialization
│ ├── views.py # API business logic
│ ├── urls.py # URL routing
│ └── admin.py # Admin panel config
├── core/
│ ├── settings.py # Project configuration
│ └── urls.py # Main URL config
├── Procfile # Railway deployment
├── requirements.txt # Dependencies
└── README.md
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /api/register/ |
Register new user | ❌ |
| POST | /api/login/ |
Login — JWT token | ❌ |
| POST | /api/token/refresh/ |
Refresh token | ❌ |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/products/ |
All products (search, filter, paginate) | ❌ |
| POST | /api/products/ |
Create product | ✅ Admin |
| GET | /api/products/{id}/ |
Product detail | ❌ |
| PUT | /api/products/{id}/ |
Update product | ✅ Admin |
| DELETE | /api/products/{id}/ |
Delete product | ✅ Admin |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/categories/ |
All categories | ❌ |
| POST | /api/categories/ |
Create category | ✅ Admin |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/cart/ |
View cart + total | ✅ |
| POST | /api/cart/add/ |
Add product to cart | ✅ |
| DELETE | /api/cart/remove/{id}/ |
Remove item | ✅ |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /api/orders/place/ |
Place order from cart | ✅ |
| GET | /api/orders/ |
Order history | ✅ |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/products/{id}/reviews/ |
Get reviews | ✅ |
| POST | /api/products/{id}/reviews/ |
Add review + rating | ✅ |
GET /api/products/?search=phone
GET /api/products/?category=1
GET /api/products/?ordering=price
GET /api/products/?ordering=-price
- Python 3.11+
- PostgreSQL
- pip
# 1. Clone the repository
git clone https://github.com/Mr-SHAAD/ecommerce-api.git
cd ecommerce-api
# 2. Create virtual environment
python -m venv env
source env/bin/activate # Mac/Linux
env\Scripts\activate # Windows
# 3. Install dependencies
pip install -r requirements.txt
# 4. Create .env file
touch .envAdd to .env:
SECRET_KEY=your_secret_key_here
DEBUG=True
DB_NAME=ecommerce
DB_USER=postgres
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432# 5. Run migrations
python manage.py migrate
# 6. Create admin user
python manage.py createsuperuser
# 7. Start server
python manage.py runserverStep 1 — Register:
POST /api/register/
{
"username": "testuser",
"email": "test@gmail.com",
"password": "pass123"
}Step 2 — Login & get token:
POST /api/login/
{
"username": "testuser",
"password": "pass123"
}Step 3 — Add to Cart:
POST /api/cart/add/
Headers: Authorization: Bearer <token>
{
"product_id": 1,
"quantity": 2
}Step 4 — Place Order:
POST /api/orders/place/
Headers: Authorization: Bearer <token>
Mohammad Shaad (iamshaadgour)
- 🐙 GitHub: @Mr-SHAAD
- 💼 LinkedIn: Mohammad Shaad
- 📧 Email: knowmore8126@gmail.com
⭐ If you found this helpful, please star this repo!