Spirit Beads Backend is the production-grade, scalable e-commerce engine powering thebeadedcase.com. Built with Python and the Django Rest Framework, this REST API provides a robust foundation for product management, order orchestration, and secure payment processing. It is a decoupled backend designed for reliability and maintainability.
This project is currently deployed and serving production traffic at: https://thebeadedcase.com
- Full E-commerce Logic: Manages product catalog, inventory, and categories.
- Stripe Integration: Seamless and secure payment processing via Stripe. Products and prices are automatically synced with the Stripe API.
- Complete Order Orchestration: Handles the entire order lifecycle from "pending" to "paid," including automatic inventory reduction for fulfilled orders.
- Custom Order Workflow: A sophisticated process for custom requests, featuring an admin review and approval system. Admins can set a quoted price and generate a unique Stripe payment link for the customer.
- REST API Architecture: A clean, decoupled REST API built with the Django REST Framework, providing structured data for any frontend client.
- Modular Design: Organized into logical Django apps (
products,orders,payments,custom_orders) for clear separation of concerns and scalability.
- Backend: Python, Django 6.0
- API: Django REST Framework
- Payment Processing: Stripe API
- Database: PostgreSQL (in production), SQLite (for local development)
- CORS:
django-cors-headersfor handling cross-origin requests. - Configuration:
python-decouplefor managing environment variables. - Media Files: Pillow for image processing and management.
Follow these instructions to get the project running locally for development and testing.
- Python 3.10+
pipandvenv- A Stripe account and API keys.
- Clone the repository:
git clone https://github.com/caseyjkey/spirit-beads-service.git cd spirit-beads-service - Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Create a
.envfile in the project root directory. Copy the contents of.env.exampleif it exists, or create it from scratch. - Add your configuration details to the
.envfile. At a minimum, you will need to provide your Stripe API keys and aSECRET_KEYfor Django.SECRET_KEY='your-strong-secret-key' DEBUG=True STRIPE_SECRET_KEY='sk_test_...' STRIPE_PUBLISHABLE_KEY='pk_test_...' STRIPE_WEBHOOK_SECRET='whsec_...' # Add any other required environment variables, like database URL DATABASE_URL='sqlite:///db.sqlite3'
- Run database migrations to set up your local database schema:
python manage.py migrate
Once the installation and configuration are complete, you can run the local development server:
python manage.py runserverThe API will be accessible at http://127.0.0.1:8000. You can access the Django admin panel at http://127.0.0.1:8000/admin. You may need to create a superuser first:
python manage.py createsuperuserThis project serves as a powerful example of a scalable e-commerce backend.
- Order Orchestration: When an order's status is updated to
paid(typically via a Stripe webhook), theOrder.save()method is triggered. This method intelligently checks the previous status and, if the order is newly paid, invokes a private_update_inventory()method. This method iterates through theOrderItems, decrementing theinventory_counton the correspondingProductmodel, ensuring the storefront accurately reflects stock levels. - Stripe Synchronization: The
Productmodel features an overriddensave()method that synchronizes product data with Stripe. When a new product is created or an existing product's price is changed, it calls theensure_stripe_product_and_priceservice. This service creates a corresponding product and price object in Stripe, storing their IDs (stripe_product_id,stripe_price_id) in the database. This keeps the local product catalog as the single source of truth while leveraging Stripe's robust infrastructure for transactions. - Custom Order Lifecycle: The
CustomOrderRequestmodel is the centerpiece of the custom order workflow. A request begins in apendingstate. An administrator can review it via the Django Admin, add notes, and set aquoted_price. Upon approval, the system can generate astripe_payment_link. Once the customer completes payment, the request is transitioned topaid, and a correspondingorders.Orderobject is created to bring it into the standard order fulfillment pipeline.
- spirit-beads-service - Django e-commerce backend (service layer)
- spirit-beads-ui - React 18 production frontend
- lighter-splitter - Spirit Beads ecosystem - image processing pipeline