ActiveCore is a full-featured, production-ready REST API backend for a premium workout wear e-commerce platform. Built with Django and Django REST Framework, it handles everything from authentication and product management to real-time order notifications and Stripe-powered payments β deployed on AWS EC2 with automated CI/CD.
π Authentication & Users
Cookie-based JWT authentication β secure HttpOnly cookies (no localStorage exposure)
Google OAuth 2.0 social login
OTP verification via Email (SMTP) and WhatsApp (Twilio) for account verify & password reset
Role-based access control β customer and admin roles with custom permission classes
Custom AbstractUser model with UUID primary keys and Cloudinary profile images
WebSocket authentication via JWT middleware for Django Channels
Full product catalog with categories, product types, variants (size-based), and inventory tracking
Cloudinary-powered product image management (primary + secondary images with DB constraints)
Product ratings (1β5 stars) with automatic ProductMetrics recalculation via signals
Featured products list (max 8 enforced at serializer level)
Advanced product list with filtering by category, size, price range, and sorting (newest, price asc/desc)
Global search across name, description, category, and product type
Separate admin and public serializers for fine-grained response control
Per-user persistent cart with atomic stock validation using select_for_update
Real-time subtotal, 18% GST, shipping, and total recalculation
Pre-checkout cart validation β detects stale prices and stock issues before payment
Full CRUD: add, update quantity, remove item, clear cart, item count
Stripe Payment Intent integration with webhook event handling
Support for ONLINE and COD (Cash on Delivery) payment methods
Full order lifecycle: PENDING β CONFIRMED β PROCESSING β SHIPPED β DELIVERED β CANCELLED / FAILED / REFUNDED
Order status history tracking with changed_by audit trail
Order expiry management via custom management command (cancel_expired_orders)
Per-user account overview with order statistics
π Real-Time Notifications & AI Chatbot
Django Channels + WebSocket-based push notifications
Per-user notification groups; notifications persisted to DB
Admin can broadcast global notifications to all users
Admin can send targeted notifications to a specific user
Triggered automatically on order events via Django signals
AI Assistant Chatbot powered by a persistent WebSocket connection (ws://<host>/ws/chat/)
Chat interface history persistence via REST APIs
Single wishlist per user (auto-created on registration via signals)
Add/remove items, item count, clear all
Price-drop detection β flags items where current price is below price_at_added
Move all wishlist items to cart in one atomic operation
Admin APIs for user management: list, search, detail, block/unblock, delete
Admin product CRUD with full variant and inventory management
Admin order management: list with filters, search, detail, status update, stats
Dashboard metrics: total users, revenue, revenue by category, top-selling products/types, order status distribution
HTTPS enforced with HSTS preloading (1 year)
CSRF and CORS protection with cross-origin cookie support for Vercel frontend
X-Frame-Options: DENY, XSS filter, Content-Type-NoSniff
SameSite=None; Secure cookies for cross-domain authentication
Layer
Technology
Framework
Django 6.0, Django REST Framework
Database
PostgreSQL (via dj-database-url)
** Channels**
Django Channels
ASGI Server
Daphne
Reverse Proxy
Nginx + Let's Encrypt SSL
Payments
Stripe (Payment Intents + Webhooks)
Media Storage
Cloudinary
Auth
SimpleJWT (cookie-based, blacklisting), Google OAuth
OTP
Twilio WhatsApp API + Django SMTP
API Docs
drf-spectacular (OpenAPI 3 β Swagger + ReDoc)
Deployment
AWS EC2, GitHub Actions CI/CD
activecore-backend/
βββ core/ # Django project settings & routing
β βββ settings/
β β βββ base.py # Shared settings (JWT, DRF, Stripe, Cloudinary, etc.)
β β βββ dev.py # Development overrides
β β βββ prod.py # Production security config (HSTS, secure cookies)
β βββ asgi.py # ASGI + WebSocket routing
β βββ pricing.py # GST + shipping pricing engine
β βββ urls.py # Root URL configuration
β
βββ apps/
β βββ accounts/ # Auth, users, OTP, Google OAuth, address
β β βββ authentication.py # Cookie-based JWT authentication backend
β β βββ middleware/ # JWT WebSocket auth middleware
β β βββ api/
β β βββ serializers/ # 8 purpose-built serializers
β β βββ views/
β β βββ admin/ # Admin user management views
β β βββ public/ # Login, register, OTP, Google auth, me
β β
β βββ products/ # Catalog, variants, inventory, ratings
β β βββ models.py # Category, ProductType, Product, Variant, Inventory, Metrics
β β βββ signals.py # Auto-create ProductMetrics on product creation
β β βββ api/
β β βββ serializers/ # 14 purpose-built serializers
β β βββ views/
β β βββ admin/ # Category, ProductType, Product, Variant CRUD
β β βββ public/ # List, detail, search, featured, ratings
β β
β βββ cart/ # Shopping cart with atomic stock validation
β β βββ api/views/
β β βββ cart_read_views.py
β β βββ cart_write_views.py
β β βββ cart_meta_views.py
β β βββ cart_validation_views.py
β β
β βββ orders/ # Checkout, Stripe, webhooks, order lifecycle
β β βββ services.py # OrderService β create, cancel, update status
β β βββ management/commands/
β β βββ cancel_expired_orders.py
β β
β βββ wishlist/ # Single wishlist per user with price-drop detection
β βββ notifications/ # WebSocket real-time notifications
β β βββ consumers.py # AsyncWebsocketConsumer
β β βββ services.py # notify_user, notify_all_users helpers
β βββ reports/ # Admin analytics dashboard
β βββ common/ # Shared pagination (page_size=12, max=100)
β
βββ deploy/
β βββ nginx.conf # Nginx reverse proxy + SSL config
β βββ daphne.service # Systemd service for Daphne ASGI
β βββ deploy.sh # Manual deploy script
β
βββ .github/
βββ workflows/
βββ deploy.yml # GitHub Actions CI/CD pipeline
Python 3.11+
PostgreSQL 14+
Cloudinary account
Stripe account (with webhooks configured)
Twilio account (for WhatsApp OTP)
git clone https://github.com/adinathmk/activecore-backend.git
cd activecore-backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
# Django
DJANGO_ENV = development
DEBUG = True
SECRET_KEY = your-secret-key
ALLOWED_HOSTS = 127.0.0.1,localhost
# CORS
CORS_ALLOWED_ORIGINS = http://localhost:5173
CSRF_TRUSTED_ORIGINS = http://localhost:5173
# Database
DATABASE_URL = postgresql://user:password@localhost:5432/activecore
# Cloudinary
CLOUDINARY_CLOUD_NAME = ...
CLOUDINARY_API_KEY = ...
CLOUDINARY_API_SECRET = ...
# Email
EMAIL_HOST = smtp.gmail.com
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = your@email.com
EMAIL_HOST_PASSWORD = your-app-password
DEFAULT_FROM_EMAIL = your@email.com
# Stripe
STRIPE_SECRET_KEY = sk_test_...
STRIPE_WEBHOOK_SECRET = whsec_...
STRIPE_PUBLISHABLE_KEY = pk_test_...
# Twilio
TWILIO_ACCOUNT_SID = ...
TWILIO_AUTH_TOKEN = ...
TWILIO_WHATSAPP_NUMBER = whatsapp:+14155238886
# Google OAuth
GOOGLE_CLIENT_ID = ...
3. Database & Static Files
python manage.py migrate
python manage.py collectstatic
python manage.py createsuperuser
4. Run Development Server
# HTTP only
python manage.py runserver
# With WebSocket support (recommended)
daphne core.asgi:application
All endpoints are prefixed with /api/. Interactive docs available at:
Swagger UI: /api/docs/
ReDoc: /api/redoc/
OpenAPI Schema: /api/schema/
Auth legend: β Public Β |Β β
Authenticated Β |Β π Admin only
Method
Endpoint
Auth
Description
POST
/register/
β
Register a new user
POST
/login/
β
Login β sets HttpOnly JWT cookies
POST
/logout/
β
Logout and clear auth cookies
POST
/refresh/
β
Refresh access token using refresh cookie
GET
/me/
β
Get current user profile + address
PATCH
/me/
β
Update profile (name, phone, avatar, address)
POST
/send-otp/
β
Send account verification OTP to email
POST
/verify-otp/
β
Verify OTP and activate account
POST
/forgot-password/
β
Send password reset OTP via email or WhatsApp
POST
/reset-password/
β
Reset password using OTP
POST
/google/
β
Sign in / register with Google OAuth2
GET
/admin/users/
π
List all users (paginated)
GET
/admin/users/search/
π
Search users by name
GET
/admin/users/<uuid>/
π
Get detailed user info
POST
/admin/users/<uuid>/block/
π
Toggle user active/blocked status
DELETE
/admin/users/<uuid>/delete/
π
Delete a user account
ποΈ Products β /api/products/
Method
Endpoint
Auth
Description
GET
/
β
List products (paginated, 12 per page)
GET
/?category=<slug>
β
Filter by category slug
GET
/?size=<S|M|L|XL>
β
Filter by size
GET
/?min_price=&max_price=
β
Filter by selling price range
GET
/?sort=newest|price_asc|price_desc
β
Sort products
GET
/search/?q=<query>&limit=<n>
β
Full-text product search (max 20 results)
GET
/home/featured/
β
Get featured products (up to 8)
GET
/<slug>/
β
Product detail with variants, images, features, ratings
POST
/<slug>/rate/
β
Submit or update a product rating (1β5 stars)
GET
/admin/
π
List all products with optional filters
POST
/admin/
π
Create new product (multipart/form-data with images)
GET
/admin/<id>/
π
Admin product detail
PATCH
/admin/<id>/
π
Update product (partial, supports image replacement)
DELETE
/admin/<id>/
π
Soft-delete product (sets is_active=False)
GET
/admin/search/
π
Search products across name, category, type
GET
/admin/categories/
π
List all categories
POST
/admin/categories/
π
Create new category (auto-generates slug)
GET
/admin/product-types/
π
List all product types
POST
/admin/product-types/
π
Create new product type
GET
/admin/variants/
π
List all variants with inventory
POST
/admin/variants/
π
Create a new variant + inventory record
GET
/admin/variants/<id>/
π
Get variant detail
PATCH / PUT
/admin/variants/<id>/
π
Update variant and stock
DELETE
/admin/variants/<id>/
π
Deactivate a variant
Method
Endpoint
Auth
Description
GET
/
β
Get cart with all items, subtotal, tax, total
GET
/count/
β
Get total item quantity in cart
POST
/add/
β
Add a variant to cart (with stock check)
PATCH
/items/<id>/
β
Update item quantity (set 0 to remove)
DELETE
/items/<id>/remove/
β
Remove a specific cart item
DELETE
/clear/
β
Remove all items from cart
POST
/validate/
β
Validate cart before checkout (stock + price sync)
π¦ Orders β /api/orders/
Method
Endpoint
Auth
Description
POST
/checkout/
β
Create order from cart (ONLINE or COD)
GET
/
β
List all orders for current user
GET
/<uuid>/
β
Order detail with items and status history
POST
/<uuid>/cancel/
β
Cancel an order
GET
/account-overview/
β
Summary: total orders, delivered, cancelled, total spent
POST
/<uuid>/create-payment-intent/
β
Create Stripe Payment Intent for an order
POST
/payments/webhook/
β
Stripe webhook (handles payment success / failure)
GET
/admin/
π
List all orders with filters and ordering
GET
/admin/search/
π
Search orders by ID, email, customer name
GET
/admin/<uuid>/
π
Admin order detail
PATCH
/admin/<uuid>/update-status/
π
Update order status
GET
/admin/stats/
π
Order statistics and analytics
β€οΈ Wishlist β /api/wishlist/
Method
Endpoint
Auth
Description
GET
/
β
Get wishlist items (includes is_price_dropped flag)
DELETE
/
β
Clear entire wishlist
GET
/count/
β
Get wishlist item count
POST
/items/
β
Add a product variant to wishlist
DELETE
/items/<variant_id>/
β
Remove a specific item from wishlist
POST
/move-to-cart/
β
Atomically move all wishlist items to cart
π Notifications β /api/notifications/
Method
Endpoint
Auth
Description
GET
/
β
Get notifications (admin can pass ?user_id=<uuid>)
POST
/send/
π
Broadcast notification to all users via WebSocket
POST
/send-user/
π
Send notification to a specific user via WebSocket
WebSocket Endpoint: ws://<host>/ws/notifications/
Requires valid access JWT cookie
Joins a per-user channel group (user_<uuid>) on connect
Receives real-time JSON messages on order status changes
π¬ AI Chatbot β /api/chat/
Method
Endpoint
Auth
Description
GET
/history/
β
Get a history of chatbot messages (limit 50)
WebSocket Endpoint: ws://<host>/ws/chat/
Requires valid access JWT cookie
Receives real-time AI JSON text chunks dynamically streams the response
π Reports β /api/reports/
Method
Endpoint
Auth
Description
GET
/dashboard/
π
Dashboard: users, revenue, top products/types, order status distribution
Every push to main triggers a GitHub Actions workflow that SSHs into the EC2 instance and runs:
git pull origin main
pip install -r requirements.txt
python manage.py migrate
python manage.py collectstatic --noinput
sudo systemctl restart daphne
Internet βββΊ Nginx (443/SSL) βββΊ Daphne (127.0.0.1:8001) βββΊ Django / Channels -> PostgreSQL
Daphne runs as a systemd service bound to 127.0.0.1:8001
Nginx handles HTTPS termination (Let's Encrypt) and proxies all traffic including WebSocket upgrades
# Cancel unpaid orders that have exceeded their expiry window
python manage.py cancel_expired_orders
Recommended to schedule as a cron job every 5β10 minutes in production.
python manage.py test apps
Django 6.0
djangorestframework
djangorestframework-simplejwt
django-channels
daphne
drf-spectacular
django-environ
dj-database-url
cloudinary / django-cloudinary-storage
stripe
twilio
phonenumbers
psycopg2-binary
Built with β€οΈ for ActiveCore β Where performance meets style.