This repository contains a Django-based e-commerce template project with:
- product catalog and category filtering
- shopping basket management
- checkout and payment processing via Stripe
- user authentication/authorization including GitHub OAuth
- asynchronous email delivery with Celery
- caching with Redis
- PostgreSQL as the primary database
The backend source code is located in store-server.
Django 6.0PostgreSQL(viapsycopg)Redis(cache + Celery broker/result backend)Celeryfor background tasksStripefor payments and checkout sessionsdjango-allauthfor account flows and social login (GitHub)django-debug-toolbaranddjango-extensionsfor development
Main Django apps:
products:ProductCategory,Product,Basketmodels- catalog listing, category pages, basket operations
- catalog cache key/version helpers in
product_list_cache.py
orders:- order creation and order history
- Stripe Checkout session creation
- Stripe webhook handling and order status updates
users:- custom
Usermodel - registration/login/profile/logout
- email verification flow
- GitHub social auth adapter
- custom
Core project package:
store/settings.py: database/cache/email/Stripe/Celery/auth settingsstore/urls.py: app routes + Stripe webhook routestore/celery.py: Celery app bootstrap and task autodiscovery
The project uses PostgreSQL as the default DB engine (django.db.backends.postgresql).
The domain models are implemented using Django ORM:
- catalog data (
ProductCategory,Product) - basket state (
Basket) - order snapshot (
Order.basket_historyas JSON) - users and verification records (
User,EmailVerification)
Order.basket_history stores a historical snapshot of purchased items (name, quantity, price, sum). This decouples the order record from future catalog changes.
The project actively uses Django QuerySet API for filtering and performance:
- user-scoped filtering:
- baskets:
Basket.objects.filter(user=request.user) - orders:
Order.objects.filter(initiator=request.user)
- baskets:
- relational optimization with
select_related("product")for basket items - ordering for stable UI:
- products by
id - baskets by
-created_timestamp - orders by
-created
- products by
- safer single-object retrieval:
get_object_or_404(...)for protected basket updates.filter(...).first()when graceful fallback is preferred
This keeps query logic explicit and predictable across list/detail and mutation flows.
Catalog:
- implemented with CBV (
ProductsListView) - supports pagination and category filtering
- product primary keys are cached and then resolved via ORM query
Basket:
- mix of CBV and FBV:
BasketListView(CBV) renders basket page and computed totalsbasket_add,basket_update,basket_remove(FBV) mutate basket state
- all basket endpoints require authentication
- quantity is validated and capped by available
Product.quantity
Local account flow is implemented via:
UserRegistrationView(registration + immediate login)UserLoginView(DjangoLoginView)UserLogoutView(explicit logout endpoint)UserProfileViewprotected byLoginRequiredMixin
Authorization strategy:
- route-level protection using
LoginRequiredMixinand@login_required - object-level scoping by always filtering user-owned records in queries
GitHub auth is provided through django-allauth:
- provider enabled:
allauth.socialaccount.providers.github - backend integration in
AUTHENTICATION_BACKENDS - social routes mounted under
/accounts/
Custom behavior is implemented in users/adapters.py:
- for GitHub login,
is_verified_emailis set when an email is present
The project includes email verification notifications:
EmailVerification.send_verification_email()prepares verification URL and message- actual sending is delegated to Celery task
send_verification_email_task - SMTP configuration is managed via environment variables in settings:
EMAIL_HOST,EMAIL_PORT,EMAIL_HOST_USER,EMAIL_HOST_PASSWORD- SSL/TLS toggles
This design keeps web requests responsive while email is sent asynchronously.
Stripe is integrated in two places:
- Product synchronization:
- when a
Productis saved, Stripe Product/Price objects are created or updated - Stripe IDs are persisted in:
Product.stripe_product_idProduct.stripe_product_price_id
- Checkout and payment confirmation:
OrderCreateViewbuilds Stripe Checkout line items from basket- customer is redirected to hosted Stripe Checkout URL
- webhook endpoint
/webhook/stripe/validates signatures and processes events - on successful payment events, order status is transitioned from
CREATEDtoPAID, and purchased basket rows are removed
Celery solves asynchronous/background execution requirements.
Current project responsibility:
- sending verification emails out of the request-response cycle
Why this matters:
- better user-perceived latency during registration
- retry/error isolation around external SMTP operations
- cleaner separation between web handling and slow I/O tasks
Configuration is loaded from CELERY_* settings and uses Redis as broker/result backend.
Redis is used for two separate concerns:
- Cache backend (
django-redis):
- caches product list PK sets for catalog/category pages
- supports cache invalidation via versioned keys
- Celery infrastructure:
- message broker
- result backend
This improves response times for catalog endpoints and enables reliable background task orchestration.
The project includes JSON fixtures in products/fixtures/:
- categories fixtures
- products fixtures
Fixtures are intended for local bootstrapping, demos, and deterministic test/dev data initialization.
Typical loading commands (from store-server):
python manage.py loaddata products/fixtures/categories.json
python manage.py loaddata products/fixtures/products.jsonUTF-8 variants are also present and can be loaded similarly.
Admin is configured with practical list tooling:
ProductAdmin:- list display including Stripe IDs
- category filter
- inline edit for price/quantity
- search and ordering
OrderAdmin:- status display/editing
- filters by status/creation date
- search by user and customer fields
UserAdmin:- basket data embedded via
BasketAdmininline
- basket data embedded via
EmailVerificationAdmin:- searchable audit of verification codes and time windows
Admin setup is focused on operational support for catalog/order/user management.
The code intentionally combines both styles:
- CBV for structured pages and forms:
- index, product list, basket list, profile, order list/detail/create
- FBV for compact imperative handlers:
- basket mutations (
add/update/remove) - Stripe webhook entrypoint
- basket mutations (
Mixins used:
LoginRequiredMixinfor access control on class-based viewsSuccessMessageMixinfor user feedback in auth forms
This hybrid approach keeps complex render flows organized (CBV) while retaining concise handlers for simple state changes (FBV).
Set these values in your environment before running:
- Django/security:
SECRET_KEY,DEBUG - PostgreSQL:
DB_NAME,DB_USER,DB_PASSWORD,DB_HOST,DB_PORT - Redis/cache:
REDIS_URL,USE_REDIS - Celery:
CELERY_BROKER_URL,CELERY_RESULT_BACKEND - Stripe:
STRIPE_SECRET_KEY,STRIPE_PUBLISHABLE_KEY,STRIPE_ENDPOINT_SECRET - Email/SMTP:
EMAIL_HOST,EMAIL_PORT,EMAIL_HOST_USER,EMAIL_HOST_PASSWORD
From store-server:
pip install -r requirements.txt
python manage.py migrate
python manage.py runserverRun Redis (example via Docker Compose):
docker compose up redisRun Celery worker:
celery -A store worker -l infoand enjoy ٩(◕‿◕。)۶
If you want to receive Stripe webhook events locally, use Stripe CLI and point it to /webhook/stripe/.