← All write-ups

Architecting an Automated Fleet Lifecycle & Weekly Driver Settlement Engine with NestJS 11, Prisma v8 and Next.js 16

Enterprise FinTech & Fleet SaaS2 min read·Case study: Saleto

Commercial vehicle leasing companies face a recurring weekly bottleneck: calculating driver payouts across hundreds of vehicles when drivers switch cars mid-week, incur tolls, carry accident-deductible payment plans, or trigger short-rental penalties. Here is how I engineered Saleto Fleet Management using Next.js 16, NestJS 11, PostgreSQL 17, and Prisma v8 to turn manual spreadsheet reconciliations into an auditable, 100% automated settlement pipeline.

11. Freezing Rental Rates on Weekly Settlement Snapshots

A classic bug in rental and subscription ERPs is linking historical invoices directly to a vehicle's current daily or weekly rate. As soon as an admin updates a vehicle's rate, past weekly statements silently change.

In Saleto, every assignment creates an explicit DriverVehicleRental contract, and each DriverWeeklySettlement record snapshots the exact dailyRate, weeklyRate, and rentalDays active during that Monday-to-Sunday window—alongside tolls, short-rental penalties, and over-income adjustments.

  • Unique composite constraint on (driverId, weekEndDate) to prevent duplicate weekly ledgers
  • Immutable rate snapshots so historical driver statements never drift when fleet pricing changes
  • Explicit week-closure locking (isClosed, closedAt, closedById) to freeze audited payouts

22. Database-Driven Dynamic Cron Schedulers with Execution Audit Logs

Hardcoding cron expressions in backend code means operations teams cannot adjust payout or email times without a redeployment. I built a dynamic SettlementSchedulerService in NestJS that evaluates live database settings every minute with in-memory mutex locks.

Every automated or manual run writes a detailed SchedulerExecutionLog row with execution duration and a JSON breakdown of every affected driver, which admins can inspect or trigger on demand from the Next.js dashboard.

  • Sunday Reserve Deductions: Automatically deducts weekly installments from active DriverPaymentPlan balances
  • Sunday Short-Rental Penalty Calculation: Evaluates rental days and snapshots penalty charges
  • Monday 3-Wave Statement Sweeps & Tuesday Terminated Driver Debt Collection workflows

33. Atomic Driver-Vehicle Lifecycle Transitions

Assigning or dropping off a vehicle touches four tables simultaneously: updating the Driver's active vehicle, updating the Vehicle's active driver, closing the open DriverVehicleRental period, and appending rows to both VehicleStatusHistory and DriverStatusHistory.

I centralized all state transitions inside a transactional FleetLifecycleService so vehicles and drivers never end up in inconsistent or orphaned states.

44. Zero-Drift Schema Evolution with Prisma v8 Contract Migrations

For financial ledgers on PostgreSQL 17, schema drift between environments is unacceptable. Saleto uses Prisma v8 Contract-First migrations (contract.prisma -> contract emit -> deterministic migration plan & contract-hash rollbacks), giving the team verified forward and backward migration paths in Docker production deployments.

Need something similar built?

I build and ship platforms like this for startups and retailers. Tell me what you are trying to launch and I will reply with how I would approach it.