Skip to content

Backend Architecture

The backend is built with Django 5.1 and Django REST Framework.

Project Structure

backend/
├── apps/
│   ├── core/           # Site settings, static pages
│   ├── products/       # Product catalog
│   ├── designs/        # Custom designs
│   ├── orders/         # Orders and cart
│   ├── payments/       # Payment processing
│   ├── users/          # User accounts
│   ├── pricing/        # Discount codes
│   └── clipart/        # Design clipart library
├── config/
│   ├── settings.py     # Django settings
│   ├── urls.py         # URL routing
│   └── celery.py       # Celery config
├── media/              # Uploaded files
├── static/             # Static assets
└── templates/          # Django templates

App Responsibilities

Products App

Manages the product catalog including: - Product models with variants (color/size) - Categories with MPTT hierarchy - Print area configuration - Catalog import/export

Designs App

Handles custom design creation: - Custom design storage (Fabric.js JSON) - Design templates - Font and color management - Image upload handling

Orders App

Order processing workflow: - Shopping cart management - Order creation and status - VAT calculation - Order history

API Design

All APIs follow REST conventions:

  • GET /api/resources/ - List
  • POST /api/resources/ - Create
  • GET /api/resources/{id}/ - Retrieve
  • PUT /api/resources/{id}/ - Update
  • DELETE /api/resources/{id}/ - Delete

Serializers

class ProductSerializer(serializers.ModelSerializer):
    category = CategorySerializer()
    color_variants = ColorVariantSerializer(many=True)

    class Meta:
        model = Product
        fields = ['id', 'name', 'slug', 'category', ...]

ViewSets

class ProductViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Product.objects.filter(is_active=True)
    serializer_class = ProductSerializer
    filterset_class = ProductFilter

Background Tasks

Celery handles async operations:

  • Email notifications
  • Catalog import/export
  • Image processing
  • Report generation
@shared_task
def send_order_confirmation(order_id):
    order = Order.objects.get(id=order_id)
    # Send email...