Production-minded E-commerce REST API built with Django and Django REST Framework (DRF), featuring JWT authentication, a Redis-backed cart, order processing with a robust state machine, and Stripe PaymentIntent integration.
Designed to demonstrate real backend engineering concerns: async work offloading, data integrity, concurrency safety, and reliable webhook ingestion.
- JWT Authentication (SimpleJWT): register/login/logout, profile, password change, password reset
- Product & Category management with pagination and filtering
- Redis-backed cart (fast reads/writes, expiration, stock checks)
- Order processing from cart → order items + stock decrement
- Robust order state machine preventing invalid transitions (e.g.,
canceled → paid) - Stripe integration: create PaymentIntent + webhook updates for payments
- Async processing with Celery + Redis for non-blocking tasks (email + webhook processing; extensible to invoice/PDF generation)
- Concurrency control: database row-level locking using
select_for_update()during critical sections
- Python 3.10+
- Redis (used for cart storage and Celery broker/result backend)
- Stripe account (for PaymentIntents + webhook signature verification)
python -m venv .venv
source .venv/bin/activatepip install -r requirements.txtCreate a .env file at the project root:
# Django
SECRET_KEY=change-me
# Email (used by password reset task)
EMAIL_USER=your_email@example.com
EMAIL_PASS=your_email_password
FROM_EMAIL=your_email@example.com
# Stripe
STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
# Celery (optional overrides)
CELERY_BROKER_URL=redis://127.0.0.1:6379/0
CELERY_RESULT_BACKEND=redis://127.0.0.1:6379/3python manage.py migratepython manage.py createsuperuserIf you already have Redis installed locally:
redis-serverBy default, this project uses separate Redis logical databases:
redis://127.0.0.1:6379/2for cache/cartredis://127.0.0.1:6379/0for the Celery brokerredis://127.0.0.1:6379/3for the Celery result backend
Or via Docker:
docker run --rm -p 6379:6379 redis:7-alpineIn a separate terminal:
celery -A ecommerce worker -l infopython manage.py runserverThis project validates webhook signatures using STRIPE_WEBHOOK_SECRET and queues processing to Celery.
Recommended local workflow using the Stripe CLI:
stripe listen --forward-to http://127.0.0.1:8000/api/v1/payments/webhook/Then copy the printed webhook secret (whsec_...) into your .env.
Base URL prefix: /api/v1/
POST /api/v1/users/register/POST /api/v1/users/login/POST /api/v1/users/logout/GET /api/v1/users/me/PUT /api/v1/users/me/update/POST /api/v1/users/change-password/POST /api/v1/users/send-reset-password-email/POST /api/v1/users/reset-password/<uid>/<token>/GET /api/v1/users/(admin)GET /api/v1/users/<id>/(admin)
GET/POST /api/v1/products/GET/PUT/DELETE /api/v1/products/<id>/GET/POST /api/v1/categories/GET/PUT/DELETE /api/v1/categories/<id>/
GET /api/v1/cart/DELETE /api/v1/cart/(clear cart)POST /api/v1/cart/items/(add item)PUT /api/v1/cart/items/<product_id>/(update quantity)DELETE /api/v1/cart/items/<product_id>/(remove)
GET/POST /api/v1/orders/GET /api/v1/orders/<id>/PUT /api/v1/orders/<id>/status/(admin)PUT /api/v1/orders/<id>/cancel/
POST /api/v1/payments/create-payment-intent/POST /api/v1/payments/webhook/(Stripe)
After login/register, include the access token:
Authorization: Bearer <access_token>OpenAPI schema and interactive documentation are available via drf-spectacular:
- OpenAPI schema:
/api/schema/ - Swagger UI:
/api/docs/swagger/ - Redoc:
/api/docs/redoc/
- Service Layer: business logic encapsulation (e.g., Redis cart operations in a dedicated service)
- State Machine: order status transitions are centrally enforced on the model
- Async Workers: Celery tasks for background work (email + Stripe webhook processing)
python manage.py test- PostgreSQL migration for production-grade transactions/locking and better scalability
- Dockerization (Django + Redis + Celery) for reproducible local/prod environments
- CI/CD pipeline (linting, unit tests, build, deploy)
- Idempotency for webhooks (store processed event IDs) for extra safety under retries
- Django, Django REST Framework
- Celery + Redis
- SQLite (development)
- Stripe API