Grand Lifecycle: Logic-Driven Fulfillment

System Design · flowchart diagram · unknown license

This diagram illustrates an e-commerce order's lifecycle, detailing how item sale types (ONHAND, PREORDER, HYBRID) and stock availability dictate fulfillme

Source: https://github.com/bhetypen/minebuddy-backend/blob/bacbbdcbfc113accab2b3fec396b512867bc51ae/readme/ORDERS.md
Curated by bhetypen
e-commerce order processing fulfillment stock management supply chain JWT authentication Java backend

Mermaid source

flowchart TD
    %% Phase 1: Security & Multitenancy
    subgraph Security_Phase ["1. Secure Entry (The Logical Wall)"]
        A[Login] --> B[JWT contains store_id]
        B --> C[API Call]
        C --> D[JwtAuthFilter sets TenantContext]
    end

    %% Phase 2: Order Creation (The 3 Sale Types)
    subgraph Order_Logic ["2. Order Engine (SaleType Branching)"]
        D --> E[createOrder]
        E --> F{Item.saleType?}

        %% ONHAND Path
        F -- ONHAND_ONLY --> G{Stock >= Qty?}
        G -- No --> H[Error: Sold Out]
        G -- Yes --> I[Deduct Stock & Status: RESERVED]

        %% PREORDER Path
        F -- PREORDER_ONLY --> J[Force PaymentType: PREORDER & Status: RESERVED]

        %% HYBRID Path
        F -- HYBRID --> K{Stock >= Qty?}
        K -- Yes --> I
        K -- No --> L{Stock > 0?}
        L -- Yes --> M[Split: Create Stock Order + Create Pre-Order]
        L -- No --> J
    end

    %% Phase 3: Lifecycle Paths
    subgraph Lifecycle_Paths ["3. Lifecycle Tracks"]
        I --> N{Path: On-Hand Fast Track}
        J & M --> O{Path: Pre-Order Supply Chain}

        %% On-Hand Path
        N --> P[Status: FULLY_PAID - Rank 6]
        P --> Q[Status: PACKED - Rank 7]

        %% Pre-Order Path
        O --> R[Status: DP_PAID - Rank 2]
        R --> S[Status: FOR_ORDERING - Rank 3]
        S --> T[Status: ORDERED_FROM_SUPPLIER - Rank 4]
        T --> U[Status: ARRIVED - Rank 5]
        U --> P
    end

    %% Phase 4: Final Fulfillment
    subgraph Fulfillment ["4. Final Fulfillment"]
        Q --> V[Status: SHIPPED - Rank 8]
        V --> W([Status: COMPLETED - Rank 9])
        
        %% Workflow Guards
        V -- "Guard" --> V1{Tracking # & Balance == 0}
        W -- "Guard" --> W1{Shipment == DELIVERED}
    end

    %% Styling
    style Order_Logic fill:#fff9c4,stroke:#fbc02d
    style Lifecycle_Paths fill:#e1f5fe,stroke:#01579b
    style Fulfillment fill:#e8f5e9,stroke:#2e7d32

What this diagram shows

This flowchart depicts the comprehensive lifecycle of an order in a backend system. It covers four main phases: Secure Entry (JWT-based multitenancy), Order Engine (branching logic based on Item.saleType for ONHAND_ONLY, PREORDER_ONLY, and HYBRID items, including stock checks and order splitting), Lifecycle Tracks (On-Hand Fast Track and Pre-Order Supply Chain with distinct status progressions), and Final Fulfillment (shipping and completion with guards).

When to use it

Use this diagram when designing or documenting an e-commerce system that requires complex order fulfillment logic based on product availability and different sales models (e.g., in-stock, pre-order, hybrid stock). It's ideal for illustrating the flow of orders through various states and how business rules influence these transitions.

How to adapt it for your project

This diagram can be adapted by adding more `saleType` options, introducing additional fulfillment paths for specific product categories, integrating external payment or shipping gateways, or modifying the status ranks and guard conditions to fit different business processes. The security phase can be expanded to include other authentication methods or authorization levels.

Key concepts