A robust and scalable eCommerce backend built with Django and DRF. It provides a comprehensive set of APIs for product browsing, cart management, checkout, and user authentication.
The Django model verbose_name
fields and admin interface labels are written in Persian (Farsi) to provide a localized admin experience.
If you prefer English labels, you can update the verbose_name
in your models or use Django’s built-in translation framework.
- ⚙️ Features
- 🚀 Installation
- 🔧 Environment Variables
- ✅ Running Tests
- 🛠️ Tech Stack
- 📚 API Documentation
- 🔐 Authentication & Authorization
- JWT-based authentication (Djoser + SimpleJWT)
- User registration, login, logout
- Password reset & account activation
- 🔎 Product catalog with search & filters
- Hierarchical categories with flexible filtering & sorting
- Price range & keyword search
- Efficient product pagination for large catalogs
- 🛒 Cart management
- Add & Remove products
- Persistent cart per user
- 💳 Checkout system
- Order creation
- Invoice
- Order history tracking to view past orders
- Payment flow will be integrated later to finalize the purchase (planned for later updates)
- 📊 Admin tools
- Manage products, categories, and orders
- Track visit counts & product popularity
- 🧩 RESTful API with Swagger documentation
- Build and start containers
docker compose up --build
- Access the backend
- API:
http://localhost:9000/
- Admin:
http://localhost:9000/admin/
- API:
- Stop containers
docker compose down
- (Optional) Seed the database with demo data
Run this command inside your project directory:
docker compose exec web python manage.py seed_data
- Clone the repository
git clone https://github.com/alireza-v/EcomDjangoAPI
- Create & activate virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
pip install -r requirements.txt
- Apply database migrations
python manage.py migrate
- Create a superuser
python manage.py createsuperuser
- Run the development server
python manage.py runserver
- Access the application
- API Docs:
http://localhost:9000/swagger/
- Django Admin:
http://localhost:9000/admin/
- API Docs:
Before running the application, create a .env
file in the root directory and add the following:
SECRET_KEY=your-secret-key
DOMAIN=your-domain-name
SITE_NAME=your-site-name
EMAIL_HOST_USER=[email protected]
EMAIL_HOST_PASSWORD=your-email-password
To generate a SECRET_KEY
, use the following code snippet
from django.core.management.utils import get_random_secret_key
secret_key = get_random_secret_key()
print(secret_key)
The backend is tested with pytest-django, ensuring robust integration test coverage across models, serializers, and API endpoints
pytest -v -x
-v
: Verbose output (show more details)-x
: Stop after the first failure
pytest app-name
Example:
pytest users -v
pytest app-name/tests/test_file_name::class/function_name
Examples:
pytest users/tests/test_models.py -v
pytest users/tests/test_models.py::test_user_registration -v
- Django: Web framework for building the backend
- Django Rest Framework: Toolkit for building RESTful APIs
- Djoser: REST implementation of Django's authentication system
- drf-yasg: Automated generation of Swagger/OpenAPI documentation
- pytest: Testing framework for running test cases
- django-admin-interface : Customizable admin UI