Quicky Delivery Dispatch ERP
Quicky replaced manual call-center dispatching with a Next.js and PostgreSQL ERP that auto-assigns orders from a fair driver queue and notifies drivers and vendors over WhatsApp; it runs in production at Quicky.
- Role
- Lead developer
- Organization
Loadless.ai
- Context
- Employment project
- Client
- Quicky
- Period
- Jan 2026 to Apr 2026
- Stack
- Next.js
- JavaScript
- TypeScript
- PostgreSQL
- Prisma
- n8n
- Docker
- Caddy
- GitHub Actions
By Mahdi TalalPublished Updated
Quicky is a Lebanese delivery company whose call-center agents used to dispatch every order to drivers and vendors by hand. As lead developer at Loadless.ai, I rebuilt its n8n and Google Sheets prototype into a Next.js and PostgreSQL ERP that assigns orders from a fair FIFO driver queue with a five-level fallback (docs/queue-manager.md, Apr 2026), messages drivers and vendors on WhatsApp, and tracks commissions and payments. It runs in production at Quicky (reported by me, Sep 2026).
- Driver-selection levels
- 5
- Source: docs/queue-manager.md in the Quicky repository Apr 2026
The problem
For each order, an agent picked a driver and forwarded the details manually. That made dispatch slow and dependent on each agent's judgment, with no shared, consistent view of which driver was next or who had been waiting longest.
The first automation was a set of n8n workflows over Google Sheets and Respond.io: a queue manager, a driver-selection step and dispatch sub-workflows (n8n workflow exports, Jan 2026). It proved the flow. But a spreadsheet is a weak place to keep queue state that several workflows update, the business rules were spread across workflow nodes, and there was no real access control. Quicky needed a system of record that operators, team leaders and finance could all work in.
Constraints
- Keep WhatsApp where it already worked. Drivers and vendors receive Arabic messages on WhatsApp through the n8n and Respond.io setup already in use. The app had to feed that setup, not replace it.
- A business day that doesn't end at midnight. Operators work shifts, so every "today" filter uses a configurable business-day window, for example 04:00 to 04:00 during Ramadan (architecture.md, Apr 2026).
- Local payment reality. Amounts are in Lebanese lira or US dollars, and some payments go through a mobile wallet (schema.prisma, Apr 2026).
- Least privilege by role. Front-line agents shouldn't browse the whole order history, and only finance roles should touch commissions and payments.
- Speed. Most of the build happened between late January and late February 2026 (GitHub history), for a single-tenant deployment on one server with Docker and Caddy.
Architecture
- An agent creates an order with a customer, an address and a zone
- The queue manager picks a driver: manual, queue head, idle, stacked or none
- The order is assigned, the driver leaves the queue and the queue closes the gap
- The app builds an Arabic message and posts it to an n8n webhook
- n8n delivers it on WhatsApp through Respond.io
- A failed send marks the order webhook_failed, ready for a one-click retry
- On delivery the commission rate is snapshotted and the driver rejoins the queue
The queue manager is a small set of functions over the driver and order tables (architecture.md, Apr 2026). When a driver joins the queue, drivers with no deliveries yet today go first; a returning driver slots in after all of them but ahead of drivers who already have deliveries. When a driver leaves, the positions behind them shift up so the queue never has gaps. To pick a driver for an order, it tries five levels in order (docs/queue-manager.md, Apr 2026):
| Level | Method | Who it picks |
|---|---|---|
| 1 | Manual | The driver the agent chose, if on shift |
| 2 | Queue | The driver at the head of the queue |
| 3 | Idle fallback | Any on-shift driver not in the queue with no order in hand |
| 4 | Stacking | The on-shift driver whose current order was assigned earliest |
| 5 | None | Nobody: the order stays pending until a driver frees up |
A pending order is picked up automatically when a driver finishes an order or another driver ends a shift.
Scheduled orders reserve a driver now and send the message later, or defer the choice of driver until the scheduled time. A protected cron endpoint handles both, together with any vendor messages that are due.
WhatsApp dispatch. The app never talks to WhatsApp directly. It builds the Arabic message itself (new orders, updates and cancellations) and posts it to one of six n8n webhook endpoints with a 10-second timeout (integrations.md, Apr 2026). Every order response reports whether each webhook was sent, scheduled or failed. A failed driver message flips the order to webhook_failed, so an operator can see it and retry; vendor failures are logged.
Money. Driver shifts and breaks, a commission rate copied onto the order at delivery (so changing a driver's rate later doesn't rewrite history), a payments ledger with commission and wallet-return entries in either currency, and running and all-time balances per driver (schema.prisma and GitHub history, Feb 2026).
Roles and data windows. Five roles (admin, agent, manager, team leader and accountant) share one permission map, used by the API routes and the dashboard navigation. Some lists are also filtered by role: agents see the last 5 hours of orders, managers 24 hours and team leaders the current business day, and agents can't edit delivered orders (rbac.md, Apr 2026).
Delivery. A multi-stage node:22-alpine image is built in GitHub Actions, pushed to Docker Hub and deployed over SSH with Docker Compose, behind Caddy for automatic TLS and security headers.
Key decisions
Prototype or web app
| n8n and Google Sheets prototype | Next.js and PostgreSQL ERP (chosen) | |
|---|---|---|
| Queue state | Rows in a sheet, updated by several workflows | Typed, indexed columns in PostgreSQL |
| Business rules | Spread across workflow nodes | Pure functions in one queue manager, documented scenario by scenario |
| Access control | Sheet sharing | Role permissions checked in the API routes, plus role-scoped data windows |
| Operator interface | Sheets and chat | A dashboard with tables, filters, exports and voice notes |
| WhatsApp delivery | n8n and Respond.io | Still n8n and Respond.io, called by webhook |
The prototype showed the flow worked. The web app gave it one source of truth, access control and an interface finance could use. It also kept the part that was already reliable, WhatsApp delivery through n8n.
Fairness first, then a fallback that never drops an order
A plain round-robin would treat a driver with a busy day behind them the same as one who hasn't delivered yet. Putting zero-delivery drivers first spreads the work from the start of each shift. The fallback levels mean an order always ends up somewhere visible: with a driver, or explicitly pending, never silently lost.
Messages built in the app, delivered by n8n
Building the Arabic text in the app keeps the wording versioned and reviewable next to the order data. n8n stays a thin delivery layer. When a driver message can't be delivered, the order says so instead of failing quietly.
Results
- In production at Quicky, where it replaced manual dispatch (reported by me, Sep 2026).
- Lead developer: 223 of the 295 commits in the main repository are mine; the rest are merges and README edits from the organisation account (git log, Apr 2026).
- Handover-ready documentation: a 9-file developer guide covering architecture, data model, API, RBAC, integrations, deployment and the dashboard, plus a scenario-by-scenario queue document (docs/, Apr 2026).
- No volumes published. I don't publish order or vendor numbers for Quicky here.
What didn't work
- Make queue assignment transactional. The queue manager updates driver and order rows in separate calls, without a database transaction or row lock. Two orders created at the same moment could both pick the driver at the head of the queue. I'd claim the head in one transaction with row locking.
- Fix the edge cases I documented. Writing every scenario down made gaps visible: cancelling an order doesn't release the driver's order count or return them to the queue; the two shift endpoints place a returning driver differently; and each trigger assigns only one pending order (docs/queue-manager.md, Apr 2026). They're documented, not fixed.
- Test the queue logic. The repository has no automated tests. For functions that decide who gets paid work, that's the first thing I'd add.
- Finish admin-managed roles. I designed database-backed roles and permissions that an admin could edit in the dashboard (rbac_feature_update.md, Feb 2026), but it was never implemented, so roles still live in code.
- Safer deploys. A deploy recreates the container in place and fails the job if the health check doesn't pass within 60 seconds, but nothing rolls back and there's no blue-green step (deploy.yml, Feb 2026).
Stack
- App: Next.js 16 (App Router, custom Node server), React 19, Tailwind CSS 4, TanStack Table, NextAuth v5
- Data: PostgreSQL, Prisma 7 with the pg adapter, PgBouncer-compatible
- Integrations: n8n, Respond.io for WhatsApp, UploadThing for voice notes, SheetJS for exports
- Delivery: Docker (multi-stage
node:22-alpine), Caddy 2, GitHub Actions to Docker Hub with SSH deploys - Languages: JavaScript, with some TypeScript
Questions
How do you build a fair driver queue for a delivery app?
Keep queue positions in the database and change them through one module. In Quicky's ERP, drivers with no deliveries yet today join ahead of drivers who already have some, positions are compacted when anyone leaves, and assignment falls back from the queue head to idle drivers, then to stacking, then to an explicit pending state.
How do you send WhatsApp dispatch messages from a web app?
Separate composing from delivering. The app builds the message text and posts it to an automation webhook, here n8n in front of Respond.io, with a timeout. It records whether each send succeeded, so a failed message is visible on the order and can be retried.
When should you move an n8n and Google Sheets prototype to a real app?
When several workflows start updating the same state, when you need access control by role, or when non-technical staff need a real interface. Quicky's prototype proved the dispatch flow; the web app gave it a real database, one home for the business rules and role-scoped screens, while keeping n8n for WhatsApp delivery.
How do you limit what each role can see in an ERP?
Combine a permission map with data windows. Every API route checks the caller's role against the map, and list endpoints also narrow results by role: in Quicky's ERP, agents see recent orders only, managers a longer window and team leaders the current business day.