flowchart TD
    A["👤 User clicks Submit"] --> B["🔄 handleConfirmBulkGeneration"]

    B --> C["📡 POST /api/bulk-generation/start-v2"]

    C --> D["🌐 Next.js Proxy"]

    D --> E["🏗️ FastAPI Endpoint /start-v2"]

    E --> F["⚡ start_bulk_generation_workflow.delay"]

    F --> G["💾 Create Database Records"]

    G --> H["📋 Initialize Redis Step Tracking"]

    H --> I["🚀 Push validate_preset to Redis Queue"]

    I --> J["🔄 Redis Queue Processor"]

    J --> K["🎯 Step Routing via STEP_FUNCTIONS"]

    K --> L["📝 Step 1: validate_preset"]
    L --> M["🎨 Step 2: generate_prompts"]
    M --> N["📁 Step 3: setup_directory"]
    N --> O["🖼️ Step 4: generate_images"]

    O --> P["🔥 asyncio.run generate_images_batch"]

    P --> Q["⚡ ThreadPoolExecutor Parallel processing"]

    Q --> R["🎯 generate_single_image for each prompt"]

    R --> S["🧠 get_ai_image_generator"]

    S --> T["🚀 ai_generator.generate_image"]

    T --> U{🔍 dimension_routing_enabled?}

    U -->|True| V["🧭 Smart Routing"]
    U -->|False| W["🔄 Simple Round-Robin NEVER REACHED"]

    V --> X{📏 Input Type Detection}

    X -->|exact_dimensions| Y["🎯 Force Replicate Only"]
    X -->|aspect_ratio| Z["🔄 Round-robin Compatible Providers"]
    X -->|default| AA["🎲 Full Round-robin All Providers"]

    Y --> BB["🚀 Replicate Provider"]
    Z --> CC{🎯 Round-robin Selection}
    AA --> CC

    CC -->|Provider 1| BB
    CC -->|Provider 2| DD["🌟 Google Nano Banana Provider"]

    BB --> EE["📸 provider.generate_image"]
    DD --> EE

    EE --> FF["📥 Download Image"]

    FF --> GG["💾 Save Metadata"]

    GG --> HH["🔢 Increment Round-robin Index"]

    HH --> II["✅ Return Success Result"]

    II --> JJ["🔄 Continue Workflow Steps 5-8"]

    JJ --> KK["📦 ZIP Created & Uploaded to S3"]

    style A fill:#e1f5fe
    style O fill:#fff3e0
    style V fill:#f3e5f5
    style BB fill:#ffebee
    style DD fill:#e8f5e8
    style HH fill:#fff9c4