# Django eCommerce API with Redis JWT Celery Smart Search
A scalable, modular, and performant eCommerce REST API built with Django and Django REST Framework. Features include JWT authentication, Stripe integration, Redis caching, Celery tasks, real-time chat with Django Channels, personalized search, tagging, and more.
🧭 Table of Contents
- Features
- Tech Stack
- Project Structure
- Getting Started
- API Documentation
- Environment Variables
- Endpoints Overview
- Testing
- License
Hypex E-commerce API
Welcome to the Hypex E-commerce API, a scalable and feature-rich backend solution built with Django and Django REST Framework.
Core Features
- 🔐 User registration, login/logout, and JWT auth
- 🛍️ Product catalog, categories, tagging, search
- 🧺 Cart and order management
- 💳 Stripe payment integration
- 🧾 Coupon and discount system
- 📦 Order history and tracking
- 🔄 Background task scheduling (Celery + Redis)
- 📡 Real-time chat (Django Channels)
- 📬 Email notifications
- 📄 Auto-generated OpenAPI/Swagger docs
- 🐳 Docker support (optional)
🧰 Tech Stack
- Backend: Django, Django REST Framework
- Auth: JWT, Google OAuth2 (social-auth)
- Database: PostgreSQL (configurable)
- Caching/Queue: Redis
- Background Tasks: Celery
- Payments: Stripe API
- Docs: drf-spectacular (OpenAPI/Swagger/Redoc)
- Containerization: Docker & Docker Compose (optional)
📁 Project Structure
apps/
├── accounts/ → User auth, profiles
├── products/ → Products, categories, tags, search
├── orders/ → Order creation, history, cart
├── payments/ → Stripe integration & webhook
├── chat/ → Real-time chat via Channels
├── core/ → Shared utils, settings
- Clean & Modular Architecture: Organized into logical Django apps for maintainability.
- Complete E-commerce Functionality: Covers products, carts, orders, payments, coupons, and more.
-
JWT Authentication: Secure, token-based authentication powered by
djoserandsimple_jwt. -
Interactive API Documentation: Auto-generated, interactive API docs using
drf-spectacular(OpenAPI 3). -
Asynchronous Task Processing: Uses
Celerywith aRedisbroker for handling background tasks like sending emails. -
Performance Optimized: Implements caching with
Redisand rate limiting (throttling) to ensure a fast and reliable API. - Containerized with Docker: Comes with a complete Docker and Docker Compose setup for easy development and deployment.
🚀 Getting Started
This project is fully containerized. All you need is Docker and Docker Compose to get it up and running.
Prerequisites
- Python 3.10+
- PostgreSQL
- Redis
- React.js (for frontend, optional)
-
pipenvorpip
Installation & Setup
# 1. Clone the repo git clone https://github.com/YOUR_USERNAME/hypex-ecommerce-api.git cd hypex-ecommerce-api # 2. Create virtual env & install deps pip install -r requirements.txt # 3. Configure your environment variables cp .env.example .env # then edit with your secrets # 4. Apply migrations python manage.py migrate # 5. Create superuser python manage.py createsuperuser # 6. Start Redis & Celery (in separate terminals) redis-server celery -A ecommerce_api worker -l info # 7. Start development server python manage.py runserver
📘 API Documentation
- Swagger UI: http://localhost:8000/api/schema/swagger-ui/
- Redoc: http://localhost:8000/api/schema/redoc/
🔐 Environment Variables
Set these in .env:
SECRET_KEY=your_secret DATABASE_URL=postgres://user:pass@localhost:5432/dbname REDIS_HOST=localhost REDIS_PORT=6379 EMAIL_HOST_USER=your@email.com EMAIL_HOST_PASSWORD=password DEFAULT_FROM_EMAIL=noreply@yourdomain.com STRIPE_PUBLISHABLE_KEY=... STRIPE_SECRET_KEY=... STRIPE_WEBHOOK_SECRET=... GOOGLE_OAUTH2_KEY=... GOOGLE_OAUTH2_SECRET=... DOMAIN=localhost SITE_NAME=Hypex
🔀 Endpoints Overview
👤 User Management
| Method | Endpoint | Description |
|---|---|---|
| GET | /auth/me/ | Get current user profile |
| PUT | /auth/me/ | Update user profile |
| PATCH | /auth/me/ | Partial update |
| DELETE | /auth/me/ | Delete user |
| POST | /auth/reset-password/ | Request password reset |
| POST | /auth/reset-password-confirm/ | Confirm reset token |
| POST | /auth/set-password/ | Set new password |
🔐 Authentication
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register/ | Register a new user |
| POST | /auth/activate/ | Activate account |
| POST | /auth/token/create/ | Login |
| POST | /auth/token/refresh/ | Refresh JWT token |
| POST | /auth/token/verify/ | Verify token |
| POST | /auth/token/destroy/ | Logout |
🛒 Products
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/products/ | List all products |
| POST | /api/v1/products/ | Create a new product |
| GET | /api/v1/products/{slug}/ | Retrieve product |
| PUT | /api/v1/products/{slug}/ | Update product |
| PATCH | /api/v1/products/{slug}/ | Partial update |
| DELETE | /api/v1/products/{slug}/ | Delete product |
| GET | /api/v1/products/user-products/ | User's own listings |
🧭 Categories
| Method | Endpoint |
|---|---|
| GET | /api/v1/categories/ |
| POST | /api/v1/categories/ |
| GET | /api/v1/categories/{slug}/ |
| PUT | /api/v1/categories/{slug}/ |
| PATCH | /api/v1/categories/{slug}/ |
| DELETE | /api/v1/categories/{slug}/ |
🧺 Cart
| Method | Endpoint |
|---|---|
| GET | /api/v1/cart/ |
| POST | /api/v1/cart/{product_id}/add/ |
| DELETE | /api/v1/cart/{product_id}/remove/ |
📦 Orders
| Method | Endpoint |
|---|---|
| GET | /api/v1/orders/ |
| POST | /api/v1/orders/ |
| GET | /api/v1/orders/{order_id}/ |
| PUT | /api/v1/orders/{order_id}/ |
| PATCH | /api/v1/orders/{order_id}/ |
| DELETE | /api/v1/orders/{order_id}/ |
🏷️ Coupons
| Method | Endpoint |
|---|---|
| GET | /api/v1/coupon/ |
| POST | /api/v1/coupon/ |
| GET | /api/v1/coupon/{id}/ |
| PUT | /api/v1/coupon/{id}/ |
| PATCH | /api/v1/coupon/{id}/ |
| DELETE | /api/v1/coupon/{id}/ |
| POST | /api/v1/coupon/apply-coupon/ |
💳 Payments
| Method | Endpoint |
|---|---|
| POST | /payment/process/{order_id}/ |
| GET | /payment/completed/ |
| GET | /payment/canceled/ |
💬 Chat
| Method | Endpoint |
|---|---|
| GET | /api/v1/chat/{product_id}/ |
-
Clone the Repository
git clone https://github.com/m-h-s/E-commerce-api.git cd E-commerce-api -
Create Environment File The project uses an
.envfile for configuration. A.env.exampleis provided as a template. Simply copy it to create your own configuration file:cp .env.example .env
You can customize the variables inside
.envif needed, but the default values are configured to work with the Docker setup. -
Build and Run with Docker Compose This single command will build the Docker images, create the containers, and run all the services:
docker-compose up -d --build
This will start the following services:
-
web: The Django application running on Gunicorn. -
database: A PostgreSQL database for data storage. -
cache: A Redis instance for caching and Celery. -
celery_worker: A Celery worker for processing asynchronous tasks. -
celery_beat: A Celery beat scheduler for periodic tasks. -
flower: A web-based monitoring tool for Celery. -
nginx: A reverse proxy for the Django application and serving static files.
-
Usage
Once the containers are running, you can access the following services:
-
API: The API is available at
http://localhost:80/api/v1/. -
Interactive API Documentation (Swagger UI):
http://localhost:80/api/v1/docs/ -
Celery Monitoring (Flower):
http://localhost:5555/
🧪 Running Tests
python manage.py test📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
For more info, see in-line docstrings and source code. Happy coding!
Let me know if you want to add Docker setup, deployment notes (Heroku, Railway, etc.), or include a logo/banner at the top!
📬 Contact
Made by [Yousef M. Y. Al Sabbah] – Reach out via [yalsabbah@students.iugaza.edu.ps] or open an issue on GitHub.
Tip: Use Postman or Insomnia to explore the API endpoints quickly during development.
To run the test suite, execute the following command in your terminal. This will run the tests inside the web container.
docker-compose exec web pytest
0 commit comments