Skip to content

Backend Architecture

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

Project Structure

backend/
├── apps/
│   ├── analytics/      # PostHog event tracking
│   ├── clipart/        # SVG clipart library
│   ├── core/           # Site settings, pages, audit, backups
│   ├── designs/        # Custom designs, templates, fonts
│   ├── invoices/       # Invoice generation, numbering
│   ├── orders/         # Orders and cart
│   ├── payments/       # Mollie payments, refunds, audit
│   ├── pricing/        # Discounts, volume, team, offers
│   ├── products/       # Product catalog, variants, images
│   └── users/          # User accounts, profiles, addresses
├── config/
│   ├── settings.py     # Django settings
│   ├── urls.py         # URL routing
│   └── celery.py       # Celery config + beat schedule
├── fixtures/seed/      # Git-tracked seed data
├── media/              # Uploaded files (dev only)
├── static/             # Static assets
└── templates/          # Django templates (emails, invoices)

App Responsibilities

Products App

Manages the product catalog including: - Product models with variants (color/size) - Categories with MPTT hierarchy - Multi-view print area configuration (front/back/left/right) - Product color images with WebP generation - Catalog import/export (seed data system)

Designs App

Handles custom design creation: - Multi-view design storage (Fabric.js JSON per view) - Design templates and fonts (uploaded + Google) - Text colors with price modifiers - Image upload handling

Orders App

Order processing workflow: - Shopping cart management - Order creation with pricing snapshots - Status tracking with email notifications - VAT calculation and order history

Payments App

Payment processing with Mollie: - Payment creation and webhook handling - Refund management - Payment audit logging with state snapshots

Invoices App

Invoice generation: - Sequential invoice numbering (INV-YYYY-NNNNN) - PDF generation with WeasyPrint - Idempotent generation (one invoice per order)

Pricing App

Complex discount system: - Discount codes (percentage/fixed) - Volume discounts with tiered pricing - Team order discounts - Special offers (time-limited) - Automated pricing rules

Core App

Platform infrastructure: - Singleton site settings (cached) - Static pages (Terms, Privacy, FAQ, etc.) - Admin audit logging (before/after state) - Database backup management (S3)

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 via Redis broker:

  • Hourly database backups (S3 upload with checksums)
  • Email notifications (order confirmation, status changes via Resend)
  • Monitoring (disk space, payment anomaly detection)
  • Backup maintenance (retention cleanup, restore verification)

Celery Beat Schedule

Task Schedule Purpose
backup.daily_backup Hourly (min=0) Database backup to S3
backup.cleanup_old_backups Daily 03:00 Retention enforcement
backup.verify_latest_backup Daily 04:00 Backup integrity check
backup.test_restore Monthly Full restore test
monitoring.check_disk_space Hourly (:30) Disk usage alerts
monitoring.check_payment_anomalies Every 15 min Payment fraud detection