Shipping System
Architecture
Section titled “Architecture”Checkout Service ↓Shipping Provider Factory ├── Weight-Based Provider ├── Manual Provider ├── DHL Provider ├── FedEx Provider └── UPS Provider ↓Shipping Rates → Client selects → Order finalizedProvider trait
Section titled “Provider trait”#[async_trait]pub trait ShippingProvider: Send + Sync { fn id(&self) -> &str; fn name(&self) -> &str; fn is_available(&self) -> bool; async fn get_rates(&self, from: &Address, to: &Address, package: &Package, options: &RateOptions) -> Result<Vec<ShippingRate>>; // ...}Weight-based provider
Section titled “Weight-based provider”Default provider. Calculates rates based on:
- Total cart weight (from product weights)
- Destination country
- Zone-based rates per 0.5kg
Weight rounds up to nearest 0.5kg.
Zone rates
Section titled “Zone rates”Zone rates are per 0.5kg and configured in the weight-based provider, with a default fallback zone for unmatched destinations. Example:
| Zone | Rate/0.5kg |
|---|---|
| Domestic | $5.00 flat |
| Europe | $10.00 |
| Rest of world | $15.00 |
Full mechanics in the Shipping guide.
EU VAT
Section titled “EU VAT”For EU destinations, VAT is applied to items at the configured rate; shipping charges themselves are not taxed:
- A $10.00 item with a 20% VAT class → $2.00 VAT
- A $2.00 item with a 20% VAT class → $0.40 VAT
Package weight
Section titled “Package weight”Product weights are fetched from the database. Products without weight default to 0.5kg.
let weights = cart_service.get_product_weights(&product_ids).await?;let total_weight: Decimal = items.iter() .map(|item| { let w = weights.get(&item.product_id).copied().unwrap_or(dec!(0.5)); Decimal::from(item.quantity) * w }) .sum();Factory clone
Section titled “Factory clone”The ShippingProviderFactory must be cloned for the rate aggregator. Each provider is re-created in the clone (providers are stateless).