Back to projects

Saya: Filling the Gap Between Bolt and DHL for Affordable On-Demand Heavy Goods Delivery

In progress
apisoftware-engineeringmachine-learning
Master·Project start: 31.08.2025·by: Shams Ismayilova

Pages

Files

Technical Implementation

Saya is not just a marketplace - it is an intelligent logistics platform. Below is an overview of the technical architecture and the algorithmic decision-making layer built into the system.

AlgorithmInputOutputComplexity
Haversine Matchinglat/lng coordinatesDistance in kmO(n)
Offer Scoringprice, rating, distanceScore 0–1O(n)
Dynamic Pricingweight, distance, daySuggested price €O(1)
ETA Predictiondistance, time, weekdayDuration in minutesO(1)

SYSTEM ARCHITECTURE

Saya is built on a modern full-stack architecture:

  • Frontend: Next.js (React, TypeScript)
  • Database: PostgreSQL with Drizzle ORM
  • Payments: Stripe with webhook reconciliation
  • Notifications: Resend (email)
  • Shipment lifecycle: explicit state machine with transitions: created → offered → accepted → paid → picked up → in transit → delivered → completed

ALGORITHMIC FEATURES

  1. Geo-Aware Courier Matching Couriers see shipments sorted by proximity using the Haversine formula - pure mathematical distance calculation between two geographic coordinates, no external map API required.

Formula: d = 2r × arcsin(√(sin²(Δlat/2) + cos(lat1) × cos(lat2) × sin²(Δlon/2)))

Result: couriers see "2.7 km away" - nearest shipments appear first.

  1. Multi-Objective Offer Scoring When a customer receives offers, each offer is automatically scored:

score = 0.4 × price_score + 0.4 × courier_rating + 0.2 × distance_score

The top-scoring offer is marked "Recommended" with an explanation: higher rating, competitive price, closer location.

  1. Dynamic Pricing Suggestion When creating a shipment, the system suggests a fair price:

Suggested Price = Base Rate (5€) + Weight Factor (0.5€/kg) + Distance Factor (0.3€/km) + Weekend Multiplier (×1.2 on Sat/Sun)

The suggestion is non-binding where users can set their own price.

  1. ETA Prediction Estimated delivery time is calculated from shipment distance, pickup time, and weekday/weekend factor. Predicted vs actual completion time is stored for accuracy analysis.

  2. Logistics Intelligence Dashboard (Admin) An admin-only analytics section visualises real platform data:

  • Courier distance distribution
  • Suggested price vs accepted price comparison
  • Offer recommendation acceptance rate
  • ETA prediction accuracy
  • Delivery completion statistics

WHY EXPLAINABLE ALGORITHMS?

Haversine: efficient, no external API dependency, stable approximation of route proximity.


// lib/matching.ts
// Haversine formula: calculates great-circle distance between two points
export function haversineDistance(
  lat1: number, lng1: number,
  lat2: number, lng2: number
): number {
  const R = 6371; // Earth radius in km
  const dLat = (lat2 - lat1) * Math.PI / 180;
  const dLng = (lng2 - lng1) * Math.PI / 180;
  const a = Math.sin(dLat/2) ** 2 +
            Math.cos(lat1 * Math.PI/180) *
            Math.cos(lat2 * Math.PI/180) *
            Math.sin(dLng/2) ** 2;
  return R * 2 * Math.asin(Math.sqrt(a));
}

Weighted scoring: courier selection is multi-objective cheaper is not necessarily better if rating or distance is poor.

Heuristic pricing: transparency beats complexity in logistics, users can understand and trust the suggestion.

Code modules:

lib/matching.ts · lib/offer-scoring.ts · 
lib/pricing.ts · lib/eta.ts · lib/analytics.ts