Skip to content

Architecture Diagrams

Visual documentation of the Freeze Design webshop architecture, components, and workflows.

Color Legend

Color Meaning
๐ŸŸฆ Blue Frontend (Next.js/React)
๐ŸŸฉ Green Backend (Django/DRF)
๐ŸŸง Orange External Services
๐ŸŸช Purple Database/Storage
โฌœ Gray Users/Actors

1. System Context Diagram

High-level overview showing the system and its external interactions.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#0d9488', 'primaryTextColor': '#fff', 'primaryBorderColor': '#0f766e', 'lineColor': '#64748b', 'secondaryColor': '#f1f5f9', 'tertiaryColor': '#fff'}}}%%
flowchart TB
    subgraph users[" ๐Ÿ‘ฅ Users "]
        customer["๐Ÿ›’ Customer<br/><small>Browse, Design, Order</small>"]
        teamManager["๐Ÿ‘” Team Manager<br/><small>Bulk Orders</small>"]
        admin["โš™๏ธ Admin<br/><small>Manage Catalog</small>"]
    end

    subgraph system["๐Ÿช Freeze Design Webshop"]
        frontend["๐Ÿ–ฅ๏ธ Frontend<br/><small>Next.js 16</small>"]
        backend["โšก Backend API<br/><small>Django REST</small>"]
    end

    subgraph external[" โ˜๏ธ External Services "]
        posthog["๐Ÿ“Š PostHog<br/><small>Analytics</small>"]
        sentry["๐Ÿ› Sentry<br/><small>Error Tracking</small>"]
        s3["๐Ÿ“ฆ S3 Storage<br/><small>Media Files</small>"]
        email["๐Ÿ“ง Email Service<br/><small>Notifications</small>"]
    end

    subgraph data[" ๐Ÿ’พ Data Stores "]
        postgres[("๐Ÿ˜ PostgreSQL<br/><small>Primary DB</small>")]
        redis[("โšก Redis<br/><small>Cache & Queue</small>")]
    end

    customer --> frontend
    teamManager --> frontend
    admin --> frontend

    frontend <--> backend

    frontend --> posthog
    frontend --> sentry
    backend --> sentry
    backend --> s3
    backend --> email

    backend <--> postgres
    backend <--> redis

    style frontend fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style backend fill:#10b981,stroke:#059669,color:#fff
    style postgres fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style redis fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style posthog fill:#f97316,stroke:#ea580c,color:#fff
    style sentry fill:#f97316,stroke:#ea580c,color:#fff
    style s3 fill:#f97316,stroke:#ea580c,color:#fff
    style email fill:#f97316,stroke:#ea580c,color:#fff
    style customer fill:#6b7280,stroke:#4b5563,color:#fff
    style teamManager fill:#6b7280,stroke:#4b5563,color:#fff
    style admin fill:#6b7280,stroke:#4b5563,color:#fff

2. Container Diagram

Services, applications, and their communication patterns.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#0d9488'}}}%%
flowchart TB
    subgraph browser["๐ŸŒ Browser"]
        spa["๐Ÿ“ฑ Single Page App<br/><small>React 19 + Next.js 16</small><br/><small>TypeScript, Tailwind CSS</small>"]
        designer["๐ŸŽจ Design Editor<br/><small>Fabric.js Canvas</small>"]
    end

    subgraph frontend_server["๐Ÿ–ฅ๏ธ Frontend Server :3000"]
        nextjs["โš›๏ธ Next.js Server<br/><small>SSR + API Routes</small>"]
    end

    subgraph backend_server["โšก Backend Server :8000"]
        django["๐Ÿ Django API<br/><small>REST Framework</small><br/><small>drf-spectacular</small>"]
        celery["โฐ Celery Worker<br/><small>Async Tasks</small>"]
    end

    subgraph data_layer["๐Ÿ’พ Data Layer"]
        pg[("๐Ÿ˜ PostgreSQL 15<br/><small>Primary Database</small>")]
        redis_cache[("โšก Redis 7<br/><small>Cache</small>")]
        redis_queue[("โšก Redis 7<br/><small>Task Queue</small>")]
    end

    subgraph storage["๐Ÿ“ฆ File Storage"]
        media["๐Ÿ–ผ๏ธ Media Storage<br/><small>Product Images</small><br/><small>Design Previews</small>"]
        prints["๐Ÿ“„ Print Files<br/><small>Production Ready</small>"]
    end

    spa --> nextjs
    designer --> nextjs
    nextjs <-->|"REST API<br/>JSON + CSRF"| django

    django --> pg
    django --> redis_cache
    django --> celery
    celery --> redis_queue
    celery --> media
    celery --> prints

    django --> media

    style spa fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style designer fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style nextjs fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style django fill:#10b981,stroke:#059669,color:#fff
    style celery fill:#10b981,stroke:#059669,color:#fff
    style pg fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style redis_cache fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style redis_queue fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style media fill:#f97316,stroke:#ea580c,color:#fff
    style prints fill:#f97316,stroke:#ea580c,color:#fff

3. Frontend Architecture

Next.js application structure with providers, contexts, and components.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#3b82f6'}}}%%
flowchart TB
    subgraph layout["๐Ÿ“„ Root Layout"]
        subgraph providers["๐Ÿ”Œ Providers Stack"]
            sentry_p["๐Ÿ› SentryProvider"]
            posthog_p["๐Ÿ“Š PostHogProvider"]
            query_p["๐Ÿ”„ QueryProvider<br/><small>TanStack Query</small>"]
            theme_p["๐ŸŽจ ThemeProvider"]
            auth_p["๐Ÿ” AuthProvider"]
            cart_p["๐Ÿ›’ CartProvider"]
            team_p["๐Ÿ‘ฅ TeamOrderProvider"]
        end
    end

    subgraph pages["๐Ÿ“‘ Pages (App Router)"]
        home["๐Ÿ  / <br/><small>Homepage</small>"]
        products["๐Ÿ“ฆ /products<br/><small>Product List</small>"]
        detail["๐Ÿ” /products/[slug]<br/><small>Product Detail</small>"]
        designer_page["๐ŸŽจ /designer<br/><small>Design Editor</small>"]
        cart_page["๐Ÿ›’ /cart<br/><small>Shopping Cart</small>"]
        checkout["๐Ÿ’ณ /checkout<br/><small>Checkout</small>"]
        team["๐Ÿ‘ฅ /team-order<br/><small>Team Orders</small>"]
        orders["๐Ÿ“‹ /orders<br/><small>Order History</small>"]
    end

    subgraph components["๐Ÿงฉ Components (71 total)"]
        nav["๐Ÿงญ Navigation"]
        product_comp["๐Ÿ“ฆ ProductCard<br/>ProductGrid"]
        designer_comp["๐ŸŽจ Designer<br/><small>Fabric.js Canvas</small>"]
        cart_comp["๐Ÿ›’ CartItem<br/>CartSummary"]
        form_comp["๐Ÿ“ Forms<br/>Inputs"]
    end

    subgraph hooks["๐Ÿช Custom Hooks"]
        useProducts["useProducts"]
        useCart["useCart"]
        useDesign["useDesign"]
        useAuth["useAuth"]
    end

    subgraph api_client["๐Ÿ“ก API Client"]
        axios_client["Axios Instance<br/><small>CSRF + Credentials</small>"]
    end

    sentry_p --> posthog_p --> query_p --> theme_p --> auth_p --> cart_p --> team_p

    team_p --> pages
    pages --> components
    components --> hooks
    hooks --> api_client
    api_client -->|"HTTP"| backend_api["โšก Backend API"]

    style sentry_p fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style posthog_p fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style query_p fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style theme_p fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style auth_p fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style cart_p fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style team_p fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style home fill:#60a5fa,stroke:#3b82f6,color:#fff
    style products fill:#60a5fa,stroke:#3b82f6,color:#fff
    style detail fill:#60a5fa,stroke:#3b82f6,color:#fff
    style designer_page fill:#60a5fa,stroke:#3b82f6,color:#fff
    style cart_page fill:#60a5fa,stroke:#3b82f6,color:#fff
    style checkout fill:#60a5fa,stroke:#3b82f6,color:#fff
    style team fill:#60a5fa,stroke:#3b82f6,color:#fff
    style orders fill:#60a5fa,stroke:#3b82f6,color:#fff
    style backend_api fill:#10b981,stroke:#059669,color:#fff

4. Backend Architecture

Django application structure with apps and their responsibilities.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#10b981'}}}%%
flowchart TB
    subgraph api_layer["๐ŸŒ API Layer"]
        drf["Django REST Framework<br/><small>Serializers + Views</small>"]
        spectacular["drf-spectacular<br/><small>OpenAPI Docs</small>"]
    end

    subgraph apps["๐Ÿ“ฆ Django Apps"]
        users_app["๐Ÿ‘ค users<br/><small>Authentication</small><br/><small>User Profiles</small>"]
        products_app["๐Ÿ“ฆ products<br/><small>Catalog</small><br/><small>Categories, Variants</small>"]
        designs_app["๐ŸŽจ designs<br/><small>Custom Designs</small><br/><small>Templates, Fonts</small>"]
        orders_app["๐Ÿ›’ orders<br/><small>Cart & Orders</small><br/><small>Order Items</small>"]
        pricing_app["๐Ÿ’ฐ pricing<br/><small>Discounts</small><br/><small>Volume Pricing</small>"]
        clipart_app["๐Ÿ–ผ๏ธ clipart<br/><small>Design Assets</small>"]
        core_app["โš™๏ธ core<br/><small>Site Settings</small><br/><small>Pages</small>"]
        payments_app["๐Ÿ’ณ payments<br/><small>Payment Processing</small>"]
    end

    subgraph services["โšก Services Layer"]
        design_service["Design Service<br/><small>Cost Calculation</small>"]
        order_service["Order Service<br/><small>Checkout Logic</small>"]
        pricing_service["Pricing Service<br/><small>Discount Rules</small>"]
    end

    subgraph tasks["โฐ Celery Tasks"]
        preview_task["Generate Preview<br/><small>Image Processing</small>"]
        print_task["Generate Print File<br/><small>Production Ready</small>"]
        export_task["Catalog Export<br/><small>Backup/Migration</small>"]
    end

    drf --> apps
    spectacular --> drf
    apps --> services
    services --> tasks

    designs_app --> design_service
    orders_app --> order_service
    pricing_app --> pricing_service

    style drf fill:#10b981,stroke:#059669,color:#fff
    style spectacular fill:#10b981,stroke:#059669,color:#fff
    style users_app fill:#34d399,stroke:#10b981,color:#000
    style products_app fill:#34d399,stroke:#10b981,color:#000
    style designs_app fill:#34d399,stroke:#10b981,color:#000
    style orders_app fill:#34d399,stroke:#10b981,color:#000
    style pricing_app fill:#34d399,stroke:#10b981,color:#000
    style clipart_app fill:#34d399,stroke:#10b981,color:#000
    style core_app fill:#34d399,stroke:#10b981,color:#000
    style payments_app fill:#34d399,stroke:#10b981,color:#000
    style design_service fill:#10b981,stroke:#059669,color:#fff
    style order_service fill:#10b981,stroke:#059669,color:#fff
    style pricing_service fill:#10b981,stroke:#059669,color:#fff
    style preview_task fill:#f97316,stroke:#ea580c,color:#fff
    style print_task fill:#f97316,stroke:#ea580c,color:#fff
    style export_task fill:#f97316,stroke:#ea580c,color:#fff

5. Data Model Overview

Core database entities and their relationships.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8b5cf6'}}}%%
erDiagram
    User ||--o| UserProfile : has
    User ||--o{ CustomDesign : creates
    User ||--o| ShoppingCart : has
    User ||--o{ Order : places

    Category ||--o{ Category : parent
    Category ||--o{ Product : contains
    Brand ||--o{ Product : owns

    Product ||--o{ ProductVariant : has
    Product }o--o{ Color : available_in
    Product }o--o{ Size : available_in

    ProductVariant ||--|| Product : belongs_to
    ProductVariant ||--|| Color : has
    ProductVariant ||--|| Size : has

    Color ||--o{ ProductColorImage : has_images

    CustomDesign ||--o| Product : for_product
    CustomDesign ||--o| ProductVariant : for_variant
    CustomDesign ||--o{ TeamNameList : has_members

    ShoppingCart ||--o{ CartItem : contains
    CartItem ||--o| ProductVariant : references
    CartItem ||--o| CustomDesign : has_design

    Order ||--o{ OrderItem : contains
    OrderItem ||--o| ProductVariant : references
    OrderItem ||--o| CustomDesign : has_design

    DiscountCode }o--o{ Order : applied_to
    VolumeDiscount ||--o| Product : for_product
    TeamDiscount ||--o{ Order : applied_to

    User {
        int id PK
        string email
        string password
        datetime created
    }

    Product {
        int id PK
        string sku
        string name
        string slug
        decimal base_price
        json print_positions
    }

    ProductVariant {
        int id PK
        string sku
        int stock_quantity
        decimal price_adjustment
        boolean is_active
    }

    CustomDesign {
        int id PK
        json design_json_front
        json design_json_back
        string status
        decimal calculated_cost
    }

    Order {
        int id PK
        string order_number
        string status
        decimal total
        datetime created
    }

6. User Flow: Browse โ†’ Design โ†’ Checkout

Complete customer journey from browsing to order completion.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#0d9488'}}}%%
sequenceDiagram
    autonumber

    participant U as ๐Ÿ‘ค Customer
    participant F as ๐Ÿ–ฅ๏ธ Frontend
    participant B as โšก Backend
    participant DB as ๐Ÿ’พ Database
    participant C as โฐ Celery

    rect rgb(59, 130, 246, 0.1)
        Note over U,DB: 1๏ธโƒฃ Browse Products
        U->>F: Visit /products
        F->>B: GET /api/products/
        B->>DB: Query products
        DB-->>B: Product list
        B-->>F: JSON response
        F-->>U: Display product grid
    end

    rect rgb(16, 185, 129, 0.1)
        Note over U,DB: 2๏ธโƒฃ View Product Details
        U->>F: Click product card
        F->>B: GET /api/products/{slug}/
        B->>DB: Query product + variants
        DB-->>B: Product details
        B-->>F: Product with colors, sizes
        F-->>U: Show product page
    end

    rect rgb(139, 92, 246, 0.1)
        Note over U,C: 3๏ธโƒฃ Create Design
        U->>F: Click "Start ontwerpen"
        F-->>U: Open Fabric.js canvas
        U->>F: Add text, images, colors
        F->>F: Local canvas editing
        U->>F: Click "Save Design"
        F->>B: POST /api/designs/
        B->>DB: Store design JSON
        B->>C: Generate preview task
        C->>DB: Store preview image
        B-->>F: Design ID + preview URL
        F-->>U: Show saved design
    end

    rect rgb(249, 115, 22, 0.1)
        Note over U,DB: 4๏ธโƒฃ Add to Cart
        U->>F: Select size, quantity
        U->>F: Click "Add to cart"
        F->>B: POST /api/cart/add/
        B->>B: Calculate design cost
        B->>DB: Add CartItem
        DB-->>B: Updated cart
        B-->>F: Cart with totals
        F-->>U: Show cart badge
    end

    rect rgb(236, 72, 153, 0.1)
        Note over U,DB: 5๏ธโƒฃ Checkout
        U->>F: Go to /checkout
        F->>B: GET /api/cart/
        B-->>F: Cart items + totals
        U->>F: Enter shipping info
        U->>F: Click "Place Order"
        F->>B: POST /api/orders/checkout/
        B->>B: Validate cart
        B->>B: Apply discounts
        B->>DB: Create Order + OrderItems
        B->>DB: Clear cart
        B-->>F: Order confirmation
        F-->>U: Show order success
    end

7. Design Cost Calculation Flow

How design pricing is calculated based on elements and colors.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8b5cf6'}}}%%
flowchart TB
    subgraph input["๐Ÿ“ฅ Design Input"]
        design["CustomDesign<br/><small>Fabric.js JSON</small>"]
    end

    subgraph parse["๐Ÿ” Parse Design"]
        front["Front View<br/><small>design_json_front</small>"]
        back["Back View<br/><small>design_json_back</small>"]
        left["Left View<br/><small>design_json_left</small>"]
        right["Right View<br/><small>design_json_right</small>"]
    end

    subgraph count["๐Ÿ“Š Count Elements"]
        text_count["Text Elements<br/><small>i-text, textbox</small>"]
        image_count["Image Elements<br/><small>image, clipart</small>"]
    end

    subgraph colors["๐ŸŽจ Color Analysis"]
        extract["Extract Unique Colors<br/><small>from text fills</small>"]
        lookup["Lookup TextColor<br/><small>price_modifier</small>"]
        surcharge["Color Surcharges<br/><small>special colors extra</small>"]
    end

    subgraph pricing["๐Ÿ’ฐ Calculate Cost"]
        text_cost["Text Cost<br/><small>count ร— design_text_price</small>"]
        image_cost["Image Cost<br/><small>count ร— design_image_price</small>"]
        color_cost["Color Cost<br/><small>ฮฃ surcharges</small>"]
    end

    subgraph total["๐Ÿ“‹ Total Design Cost"]
        sum["total = text_cost<br/>+ image_cost<br/>+ color_surcharges"]
    end

    design --> front & back & left & right
    front & back & left & right --> text_count & image_count
    front & back & left & right --> extract
    extract --> lookup --> surcharge

    text_count --> text_cost
    image_count --> image_cost
    surcharge --> color_cost

    text_cost & image_cost & color_cost --> sum

    style design fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style sum fill:#10b981,stroke:#059669,color:#fff
    style text_cost fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style image_cost fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style color_cost fill:#f97316,stroke:#ea580c,color:#fff

8. Team Order Flow

Bulk ordering workflow for teams and organizations.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#0d9488'}}}%%
sequenceDiagram
    autonumber

    participant TM as ๐Ÿ‘” Team Manager
    participant F as ๐Ÿ–ฅ๏ธ Frontend
    participant B as โšก Backend
    participant DB as ๐Ÿ’พ Database

    rect rgb(59, 130, 246, 0.1)
        Note over TM,DB: 1๏ธโƒฃ Create Team Design Template
        TM->>F: Design team jersey template
        F->>B: POST /api/designs/
        B->>DB: Save template design
        B-->>F: Design ID
    end

    rect rgb(16, 185, 129, 0.1)
        Note over TM,DB: 2๏ธโƒฃ Add Team Members
        TM->>F: Enter team roster
        Note right of F: Name, Number, Size<br/>per team member
        F->>B: POST /api/designs/{id}/add_team_names/
        B->>DB: Create TeamNameList entries
        B-->>F: Team roster saved
    end

    rect rgb(139, 92, 246, 0.1)
        Note over TM,DB: 3๏ธโƒฃ Add All to Cart
        TM->>F: Click "Add team to cart"
        F->>B: POST /api/cart/add/ (bulk)
        loop For each team member
            B->>B: Calculate individual cost
            B->>DB: Create CartItem
        end
        B->>B: Check TeamDiscount eligibility
        B->>B: Apply volume discount
        B-->>F: Cart with team items
        F-->>TM: Show team order summary
    end

    rect rgb(249, 115, 22, 0.1)
        Note over TM,DB: 4๏ธโƒฃ Checkout with Discount
        TM->>F: Proceed to checkout
        F->>B: POST /api/orders/checkout/
        B->>B: Apply TeamDiscount
        B->>DB: Create Order with all items
        B-->>F: Order with bulk pricing
        F-->>TM: Order confirmation
    end

9. CI/CD Pipeline

GitHub Actions workflow for testing, building, and deploying.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#0d9488'}}}%%
flowchart TB
    subgraph trigger["๐ŸŽฏ Triggers"]
        push["Push to main/develop"]
        pr["Pull Request"]
        tag["Version Tag (v*)"]
    end

    subgraph ci["๐Ÿงช CI Pipeline (ci.yml)"]
        subgraph backend_test["๐Ÿ Backend Tests"]
            py_setup["Setup Python 3.12"]
            pg_redis["Start PostgreSQL + Redis"]
            lint_be["Lint (flake8)"]
            migrate["Run Migrations"]
            pytest["pytest + Coverage"]
        end

        subgraph frontend_test["โš›๏ธ Frontend Tests"]
            node_setup["Setup Node.js 20"]
            lint_fe["Lint (ESLint)"]
            jest["Jest Unit Tests"]
            playwright["Playwright E2E"]
        end

        subgraph docs_test["๐Ÿ“š Docs Tests"]
            mkdocs_build["Build MkDocs"]
        end
    end

    subgraph deploy_prod["๐Ÿš€ Deploy Production (deploy-production.yml)"]
        docker_build["๐Ÿณ Build Docker Images"]
        ghcr_push["๐Ÿ“ฆ Push to GHCR"]
        ssh_deploy["๐Ÿ” SSH Deploy"]
        health_check["โค๏ธ Health Checks"]
        discord["๐Ÿ“ข Discord Notify"]
    end

    subgraph docs_deploy["๐Ÿ“– Docs Deploy (docs.yml)"]
        build_mkdocs["Build MkDocs"]
        build_openapi["Build OpenAPI/Swagger"]
        build_storybook["Build Storybook"]
        build_typedoc["Build TypeDoc"]
        combine["Combine All Docs"]
        cloudflare["Deploy to Cloudflare Pages"]
    end

    push --> ci
    pr --> ci
    push --> docs_deploy

    tag --> deploy_prod

    ci --> backend_test & frontend_test & docs_test

    py_setup --> pg_redis --> lint_be --> migrate --> pytest
    node_setup --> lint_fe --> jest --> playwright

    docker_build --> ghcr_push --> ssh_deploy --> health_check --> discord

    build_mkdocs & build_openapi & build_storybook & build_typedoc --> combine --> cloudflare

    style push fill:#6b7280,stroke:#4b5563,color:#fff
    style pr fill:#6b7280,stroke:#4b5563,color:#fff
    style tag fill:#f97316,stroke:#ea580c,color:#fff
    style pytest fill:#10b981,stroke:#059669,color:#fff
    style playwright fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style docker_build fill:#0ea5e9,stroke:#0284c7,color:#fff
    style cloudflare fill:#f97316,stroke:#ea580c,color:#fff
    style discord fill:#5865f2,stroke:#4752c4,color:#fff

10. Deployment Architecture

Production environment topology.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#0d9488'}}}%%
flowchart TB
    subgraph internet["๐ŸŒ Internet"]
        users["๐Ÿ‘ฅ Users"]
        cdn["โ˜๏ธ Cloudflare<br/><small>CDN + WAF</small>"]
    end

    subgraph github["๐Ÿ“ฆ GitHub"]
        repo["Repository"]
        ghcr["Container Registry<br/><small>GHCR</small>"]
        actions["GitHub Actions"]
    end

    subgraph server["๐Ÿ–ฅ๏ธ Production Server"]
        subgraph docker["๐Ÿณ Docker Compose"]
            nginx["๐Ÿ”€ Nginx<br/><small>Reverse Proxy</small><br/><small>:80, :443</small>"]
            frontend_c["โš›๏ธ Frontend<br/><small>Next.js</small><br/><small>:3000</small>"]
            backend_c["๐Ÿ Backend<br/><small>Django + Gunicorn</small><br/><small>:8000</small>"]
            celery_c["โฐ Celery<br/><small>Worker</small>"]
            postgres_c[("๐Ÿ˜ PostgreSQL<br/><small>:5432</small>")]
            redis_c[("โšก Redis<br/><small>:6379</small>")]
        end

        volumes["๐Ÿ“ Volumes<br/><small>Media, Static, Logs</small>"]
    end

    subgraph external["โ˜๏ธ External"]
        s3_ext["๐Ÿ“ฆ S3 Backup"]
        sentry_ext["๐Ÿ› Sentry"]
        posthog_ext["๐Ÿ“Š PostHog"]
    end

    users --> cdn --> nginx
    nginx --> frontend_c
    nginx --> backend_c

    frontend_c <--> backend_c
    backend_c --> postgres_c
    backend_c --> redis_c
    backend_c --> celery_c
    celery_c --> redis_c

    backend_c --> volumes
    celery_c --> volumes

    actions --> ghcr
    ghcr --> docker

    backend_c --> sentry_ext
    frontend_c --> sentry_ext
    frontend_c --> posthog_ext
    backend_c --> s3_ext

    style users fill:#6b7280,stroke:#4b5563,color:#fff
    style cdn fill:#f97316,stroke:#ea580c,color:#fff
    style nginx fill:#009639,stroke:#007a2f,color:#fff
    style frontend_c fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style backend_c fill:#10b981,stroke:#059669,color:#fff
    style celery_c fill:#10b981,stroke:#059669,color:#fff
    style postgres_c fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style redis_c fill:#dc2626,stroke:#b91c1c,color:#fff
    style ghcr fill:#6b7280,stroke:#4b5563,color:#fff

11. API Endpoint Map

REST API organized by resource.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#10b981'}}}%%
flowchart LR
    subgraph api["โšก /api"]
        subgraph products_api["๐Ÿ“ฆ Products"]
            p1["GET /products/"]
            p2["GET /products/{id}/"]
            p3["GET /categories/"]
            p4["GET /categories/tree/"]
            p5["GET /colors/"]
            p6["GET /sizes/"]
            p7["GET /variants/"]
        end

        subgraph designs_api["๐ŸŽจ Designs"]
            d1["GET /designs/"]
            d2["POST /designs/"]
            d3["GET /designs/{id}/"]
            d4["PATCH /designs/{id}/"]
            d5["DELETE /designs/{id}/"]
            d6["POST /designs/{id}/add_team_names/"]
            d7["POST /designs/{id}/generate_preview/"]
            d8["PATCH /designs/{id}/finalize/"]
        end

        subgraph cart_api["๐Ÿ›’ Cart"]
            c1["GET /cart/"]
            c2["POST /cart/add/"]
            c3["PATCH /cart/items/{id}/"]
            c4["DELETE /cart/items/{id}/"]
            c5["POST /cart/clear/"]
        end

        subgraph orders_api["๐Ÿ“‹ Orders"]
            o1["GET /orders/"]
            o2["GET /orders/{id}/"]
            o3["POST /orders/checkout/"]
        end

        subgraph auth_api["๐Ÿ” Auth"]
            a1["POST /auth/register/"]
            a2["POST /auth/login/"]
            a3["POST /auth/logout/"]
            a4["GET /auth/me/"]
            a5["GET /auth/profile/"]
            a6["PATCH /auth/profile/"]
        end

        subgraph docs_api["๐Ÿ“š Docs"]
            doc1["GET /schema/"]
            doc2["GET /docs/"]
            doc3["GET /redoc/"]
        end
    end

    style p1 fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style d2 fill:#10b981,stroke:#059669,color:#fff
    style c2 fill:#10b981,stroke:#059669,color:#fff
    style o3 fill:#10b981,stroke:#059669,color:#fff
    style a2 fill:#10b981,stroke:#059669,color:#fff

12. State Management

How application state flows through the frontend.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#3b82f6'}}}%%
flowchart TB
    subgraph global["๐ŸŒ Global State (React Context)"]
        auth_state["๐Ÿ” AuthContext<br/><small>user, loading</small><br/><small>login(), logout()</small>"]
        cart_state["๐Ÿ›’ CartContext<br/><small>cart, items</small><br/><small>add(), remove()</small>"]
        team_state["๐Ÿ‘ฅ TeamOrderContext<br/><small>members, design</small>"]
        theme_state["๐ŸŽจ ThemeContext<br/><small>theme: light/dark</small>"]
    end

    subgraph server["๐Ÿ“ก Server State (TanStack Query)"]
        products_query["useQuery: products"]
        design_query["useQuery: designs"]
        order_query["useQuery: orders"]
        mutation["useMutation:<br/><small>create, update, delete</small>"]
    end

    subgraph local["๐Ÿ“ Local State (useState/Zustand)"]
        form_state["Form inputs"]
        modal_state["Modal visibility"]
        canvas_state["๐ŸŽจ Fabric.js Canvas<br/><small>Design editor state</small>"]
    end

    subgraph cache["๐Ÿ’พ Cache Layer"]
        query_cache["React Query Cache<br/><small>5 min stale time</small>"]
        local_storage["localStorage<br/><small>Theme, preferences</small>"]
    end

    auth_state --> cart_state
    cart_state --> team_state

    products_query --> query_cache
    design_query --> query_cache
    order_query --> query_cache

    theme_state --> local_storage
    canvas_state --> mutation --> design_query

    style auth_state fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style cart_state fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style team_state fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style theme_state fill:#3b82f6,stroke:#1d4ed8,color:#fff
    style canvas_state fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style query_cache fill:#10b981,stroke:#059669,color:#fff

Quick Reference

Diagram Purpose
System Context High-level system overview
Container Services and communication
Frontend Next.js structure
Backend Django apps
Data Model Database entities
User Flow Customer journey
Design Cost Pricing logic
Team Order Bulk ordering
CI/CD Deployment pipeline
Deployment Production topology
API Map REST endpoints
State Frontend state flow