How sameer19-03/order-routing-engine works
Purpose and entry points
Order Routing Engine is a full-stack logistics decision platform that assigns customer orders to warehouses using configurable weighted scoring, reserves stock, and records an AI-readable rationale. Backend startup is server/server.js; optional data bootstrap is server/seed.js. The React/Vite SPA starts at client/src/main.jsx and defines application navigation in client/src/App.jsx.
Client application and access boundary
The frontend is a protected operations console for dashboards, orders, inventory, warehouses, routing, settings, history, and maps. Authentication state is centralized in client/src/context/AuthContext.jsx; route gating is enforced by client/src/components/ProtectedRoute.jsx; the shared authenticated shell is client/src/components/Layout.jsx. API communication is centralized through client/src/api/axios.js.
API and authorization layer
Express exposes resource-oriented API modules, with routes delegating to controllers. JWT-based authentication and role enforcement form the backend boundary before protected operational actions. Key paths are server/server.js, server/middleware/authMiddleware.js, server/routes/routingRoutes.js, and server/controllers/routingController.js. Auth registration/login are handled through server/routes/authRoutes.js and server/controllers/authController.js.
Routing decision pipeline
Routing is the core transaction: receive an order, filter active warehouses and adequate inventory, calculate geographic distance, score candidates using configured distance/inventory/delivery/cost weights, select a warehouse, reserve inventory, generate an explanation, then persist assignment and decision history. The orchestration and scoring live in server/services/routingEngine.js, invoked via server/controllers/routingController.js; configurable scoring is managed through server/services/orderService.js and server/controllers/configController.js.
Persistent domain model
MongoDB via Mongoose stores operational state. Orders connect customer demand and fulfillment assignment in server/models/Order.js; per-warehouse product availability and reservation state are in server/models/Inventory.js; warehouse location/status are in server/models/Warehouse.js. Supporting persisted entities include catalog products, routing weights, user identities/roles, and explainable routing audit records in server/models/Product.js, server/models/RoutingConfig.js, server/models/User.js, and server/models/RoutingHistory.js.
Operations and visualization
Management pages manipulate the resource APIs for inventory, warehouses, products, and order lifecycle: server/controllers/inventoryController.js, server/controllers/warehouseController.js, and server/controllers/orderController.js. The SPA presents routing execution/history and Leaflet-based geographic visualization through client/src/pages/RoutingDecision.jsx, client/src/pages/RoutingHistory.jsx, and client/src/pages/WarehouseMap.jsx. Settings change the persisted scoring configuration via client/src/pages/RoutingSettings.jsx.
External services and background work
Required infrastructure is a MongoDB cluster, configured through MONGODB_URI. Groq’s Llama 3.1 is called after deterministic routing to turn decision facts into business explanations; integration is isolated in server/services/aiExplanation.js and requires GROQ_API_KEY. JWT signing requires JWT_SECRET. When enabled by environment configuration, a node-cron-driven order simulator generates workload through server/services/orderGenerator.js, rather than requiring external order ingress.
Main entry points: routingEngine.js Routing engine · server.js Express server · App.jsx App navigation · orderController.js Operations controllers
Components 22
Operations Console
- React/Vite SPA · Operations dashboards and management views.
client/src/main.jsx - App navigation
client/src/App.jsx - Auth state
client/src/context/AuthContext.jsx - Route gate
client/src/components/ProtectedRoute.jsx - API client
client/src/api/axios.js - Routing views & map · Decision, history, settings, and warehouse map views.
client/src/pages/RoutingDecision.jsx
Express API
- Express server
server/server.js - Auth API · Registration and login endpoints.
server/routes/authRoutes.js - JWT & role guard
server/middleware/authMiddleware.js - Routing controller
server/controllers/routingController.js - Operations controllers · Order, inventory, and warehouse lifecycle management.
server/controllers/orderController.js
Routing Pipeline
- Routing engine · Filters candidates, scores warehouses, selects and reserves stock.
server/services/routingEngine.js - Scoring configuration · Manages weighted distance, inventory, delivery, and cost scoring.
server/services/orderService.js - AI explanation · Converts deterministic decision facts into a business rationale.
server/services/aiExplanation.js - Order simulator · Optional node-cron order generation.
server/services/orderGenerator.js
Persistent Domain
- Orders
server/models/Order.js - Inventory · Per-warehouse availability and reservations.
server/models/Inventory.js - Warehouses · Warehouse location and active status.
server/models/Warehouse.js - Routing weights
server/models/RoutingConfig.js - Routing history · Explainable assignment audit records.
server/models/RoutingHistory.js
Infrastructure & AI
- MongoDB cluster · Operational state via Mongoose.
- Groq Llama 3.1
Connections 28
- React/Vite SPA → App navigation: boots
- App navigation → Auth state: uses
- App navigation → Route gate: gates routes
- App navigation → Routing views & map: renders
- Routing views & map → API client: calls
- API client → Express server: HTTP API
- Express server → Auth API: mounts
- Express server → JWT & role guard: protects APIs
- Express server → Routing controller: mounts
- Express server → Operations controllers: mounts
- Routing controller → Routing engine: invokes
- Routing engine → Scoring configuration: reads weights
- Routing engine → Orders: assigns order
- Routing engine → Inventory: checks and reserves
- Routing engine → Warehouses: filters and scores
- Routing engine → AI explanation: requests rationale
- AI explanation → Groq Llama 3.1: Llama request
- Routing engine → Routing history: records decision
- Scoring configuration → Routing weights: persists
- Operations controllers → Orders: manages
- Operations controllers → Inventory: manages
- Operations controllers → Warehouses: manages
- Order simulator → Routing engine: generates workload
- Orders → MongoDB cluster: stored in
- Inventory → MongoDB cluster: stored in
- Warehouses → MongoDB cluster: stored in
- Routing weights → MongoDB cluster: stored in
- Routing history → MongoDB cluster: stored in