A modern, production-ready Django REST API backend for the {{ app_name|default:'Your App' }} e-commerce platform.
- Product Management: Categories, sizes, products, images, reviews
- User Authentication: JWT-based registration, login, profile, and permissions
- Shopping Cart & Orders: Add/update/remove items, checkout, order tracking
- Payment Integration: Stripe payments with secure webhooks
- PDF Reports: Download order receipts and monthly revenue reports (WeasyPrint)
- Email Campaigns: Send rich, template-based emails to all users (with WYSIWYG editing)
- Admin Panel: Jazzmin-powered, analytics dashboard, custom branding, dark mode
- Staff Permissions: Staff group can read/add/update but not delete (products, orders, campaigns)
- Real-time Updates: WebSocket support for order status
- Modern, DRY, and Clean Codebase
- Django 5.2+
- Django REST Framework
- SimpleJWT (auth)
- Channels (WebSocket)
- Stripe
- WeasyPrint (PDF)
- django-summernote (WYSIWYG email templates)
- Jazzmin (admin UI)
- Python 3.8+
- pip
- Node.js (for frontend, optional)
-
Clone the repository
git clone https://github.com/shyanukant/e-commerce-api.git cd e-commerce-api -
Create virtual environment
python -m venv venv venv\Scripts\activate # Windows source venv/bin/activate # Linux/Mac
-
Install dependencies
pip install -r requirements.txt
-
Run migrations
python manage.py makemigrations python manage.py migrate
-
Create superuser
python manage.py createsuperuser
-
Collect static files
python manage.py collectstatic --noinput
-
Run the server
python manage.py runserver
- Run server in .devcontainer
python manage.py runserver 0.0.0.0:8000
- Access at:
http://localhost:8000/admin/ - Jazzmin theme, custom branding, analytics dashboard
- PDF download for order receipts and monthly revenue
- Email campaign management (visual + code editor)
- Staff group: assign users for limited admin permissions (no delete)
POST /api/users/register/— RegisterPOST /api/users/login/— LoginPOST /api/token/— JWT tokenPOST /api/token/refresh/— Refresh token
GET /api/store/products/— List productsPOST /api/store/products/— Add product (admin/staff)- ...
GET /api/orders/orders/— List user ordersPOST /api/orders/checkout/— CheckoutGET /api/orders/orders/{id}/download_receipt/— Download PDF receipt
- Managed via admin panel (Campaigns section)
- Run:
python manage.py create_staff_group
- Assign users to the "Staff" group in admin
- Staff can read/add/update products, orders, campaigns, but cannot delete
- PDF Receipts/Reports: WeasyPrint, downloadable from admin
- Email Campaigns: Visual/code editor, send to all users, template management
Add to .env or settings.py:
STRIPE_PUBLISHABLE_KEY = 'pk_test_...'
STRIPE_SECRET_KEY = 'sk_test_...'
STRIPE_WEBHOOK_SECRET = 'whsec_...'python manage.py test- Set
DEBUG = False - Use PostgreSQL for production
- Configure static/media file serving
- Set up Stripe keys and webhooks
- Use a production ASGI server (Daphne/Uvicorn)
This project uses Django Channels and Daphne (ASGI server) for real-time features (WebSockets). Order status updates are pushed live to users via WebSocket.
- ASGI Entrypoint:
- The app runs with Daphne (not Gunicorn) for full HTTP + WebSocket support.
- Entrypoint:
backend.asgi:application
- Channels/Redis:
- Redis is used as the channel layer for production-ready real-time features.
- All order status changes are broadcast to the user's WebSocket group.
- Frontend Demo:
- See
public/order-tracker.htmlfor a simple order tracker using WebSockets.
- See
- Copy
.env.exampleto.envand setDJANGO_DB_ENGINE=sqlite(default for local dev). - Run migrations, create a superuser, and start the server:
python manage.py migrate python manage.py createsuperuser python manage.py runserver
- The app will use SQLite and run with Channels (ASGI) for real-time features.
- Copy
.env.exampleto.envand setDJANGO_DB_ENGINE=postgresql. - Build and start all services (app, Postgres, Redis):
docker-compose up --build
- The app will use Postgres and Redis, and run with Daphne for ASGI/Channels support (real-time features).
- Access the app at
http://localhost:8000/and the admin at/admin/.
- Open the project in VS Code and reopen in container.
- All services (app, Postgres, Redis) are started automatically.
- Ports 8000 (app), 5432 (Postgres), and 6379 (Redis) are forwarded.
- Environment is loaded from
.devcontainer/devcontainer.env. - Migrations are run automatically on first start.
- On every push or pull request to
main, the pipeline:- Spins up Postgres and Redis services
- Installs dependencies
- Runs migrations
- Runs the full Django test suite
- See
.github/workflows/ci.ymlfor details.
- Use
.envfor local/dev,.env.exampleas a template. - Key variables:
DJANGO_DB_ENGINE=sqlitefor local,postgresqlfor Docker/prodDEBUG=1for local,DEBUG=0for productionDJANGO_SECRET_KEY,DJANGO_DB_*,REDIS_HOST,REDIS_PORT
- Run the server and open
public/order-tracker.htmlin your browser. - Place an order, then update its status in the admin panel.
- You should see live status updates in the tracker page (WebSocket).
MIT