← Works

Nutrition-products distributor · 2025 · Next.js · Bun · ElysiaJS · PostgreSQL · BullMQ

Every order, one source of truth.

A custom B2B sales, pricing and fulfilment platform for a growing distributor: every order priced correctly, approved properly, shipped traceably and reported on live.

Industry
Wholesale distribution (sports nutrition and health supplements)
Scope
Product design, full-stack engineering, background automation, deployment
Delivered
Web app · Business API · Background automation service · AI-assistant connector · Email notifications

01 / Challenge

Why did nobody know what had shipped, or what was left?

The client sells to retailers, wholesalers and regional stockists across several Indian states, from more than one warehouse. Each kind of buyer gets different prices. Orders arrived, got approved, and were packed and shipped through a mix of manual steps. Nobody had one clear view of what was ordered, what had shipped, and what was left in stock.

  • Sales team

    Had to work out discounted prices by hand for each customer tier, and couldn't easily track an order after handing it over.

  • Sales managers

    Had no reliable view of what their teams were selling, or of progress against yearly targets.

  • Accounts

    Had to chase invoices, credit notes and approvals across emails and files.

  • Warehouse and operations

    Had to track stock by batch and expiry date, and to record what physically left the building.

  • Owners

    Had no live picture of revenue, top customers, top products or best-selling brands.

Margins in distribution are thin. A pricing mistake, a lost shipment or expired stock costs real money.

One system where every order is priced correctly, approved properly, shipped traceably and reported on live.

02 / Solution

What does one system for every order look like?

A web platform that covers the whole order lifecycle, from the first quote to delivery and returns. A business engine sits behind it and enforces the rules. Each team works in the same app, but each person sees only what their role allows. An automation service runs in the background, and an AI-assistant connector lets approved staff ask questions of live sales, order and shipment data, seeing only what they are allowed to see.

What it covers

  • Customers

    Customer profiles with tax details, billing and shipping addresses, contacts, payment terms and an assigned account manager.

  • Catalogue

    Products organised by brand, series and group, plus promotional items (free samples and gifts) tracked separately.

  • Tiered pricing

    Pricing "slabs" (for example Retail, Wholesale and Stockist), each with its own discounts per product series or product. Prices and tax are worked out automatically.

  • Purchase orders

    Sales staff draft orders, submit them for approval, and managers approve or reject them. Overdue drafts get reminders and can be rejected automatically.

  • Pending orders

    Demand that can't be met yet is recorded, so it can be turned into a real order once stock arrives.

  • Sales orders

    Approved orders become numbered sales orders, with clear statuses from "awaiting invoice" through "partially dispatched" to "delivered".

  • Shipments

    An order can ship in several parcels from different warehouses. Each parcel carries its invoice, packing slip, credit notes, courier and tracking details. Shipments can be exported.

  • Cancellations and returns

    Items can be cancelled in part or in full. Returns go through a quality check, then are either restocked or written off. Returns can also be rejected, with a recorded reason.

  • Inventory

    Stock is tracked by batch, with manufacturing and expiry dates, warehouse, and available versus reserved quantities. Alerts fire for low stock and approaching expiry.

  • Targets and analytics

    Yearly sales targets, plus revenue broken down by customer, product, brand, state and salesperson.

  • People and permissions

    Roles for admins, sales executives, sales managers, sales heads, accountants, warehouse staff, operations and production.

  • Audit trail

    Every important action is logged against the record it affected, including stock movements.

03 / Highlights

What keeps every order right?

Pricing that is always right

Each customer is linked to a pricing tier, and every tier holds its own discounts per product series and per product. Prices, discounts and tax on an order are calculated by the system, not by hand. When a price or discount changes, open orders are updated in the background. Orders that have already been approved stay as they were. Try changing a discount: the draft recalculates, the approved order doesn't move.

Dashboard / Slabs
Series B discount, Retail45%

PO #k858 · Retail · draftrecalculated

Whey 2 kg × 4 · 40% off₹19,198

Creatine 250 g × 20 · 45% off₹17,589

Pre-workout 25 serv × 10 · 45% off₹16,495

Total incl. 18% GST₹62,872

SO1247 · Retail · approved, locked₹62,872

FIG. 03.1 / PRICING TIERSinteractive mock

An order you can follow from start to finish

Every order moves through clear stages: draft, approval, invoicing, dispatch and delivery. One order can be split across several shipments and warehouses. Each shipment must have its packing slip before it can leave, so there is always a record of what went out. Try dispatching the parcel before and after attaching its slip.

Sales Order / SO1247
Awaiting shipment

Parcel #1 can't leave without its packing slip.

Awaiting

Whey 2 kg × 40

Creatine 250 g × 120

Pre-workout 25 serv × 60

Dispatched

  1. 01 · Admin approved PO #k858 → SO1247
FIG. 03.2 / SALES ORDERinteractive mock

Everyone sees exactly what they should

Permissions are set per role and per action, and can also be set on individual records. A salesperson sees only their own customers and orders. A manager also sees their team's. Admins and accounts see everything. This is enforced by the business engine itself, not just hidden in the screens, so it holds for the AI assistant too. Switch roles and ask again.

Signed in as Neha / Sales exec
  • SO1251 Bluebay TradersNeha
  • SO1249 Summit StoresNeha

AI assistant · “How many open orders are there?”

“2 open orders.” Same rule, enforced by the engine.

FIG. 03.3 / PERMISSIONSinteractive mock

Stock tracked to the batch

Inventory is held by batch, with manufacturing and expiry dates. That matters for products with a shelf life. When an order is confirmed, specific batches are reserved for it. Low-stock and expiry alerts go out automatically. Returned goods that pass the quality check go back into stock. Confirm an order and watch which batches it takes.

Inventory / Whey 2 kg
BatchExpiryAvailableReserved
WH-04122027.01180
WH-05182027.06400
WH-06032027.11600
Free 118
FIG. 03.4 / INVENTORYinteractive mock

The system does the follow-up

A background service handles the routine work: email updates on orders and shipments, reminders about overdue purchase orders, low-stock and expiry flags, and an audit entry for each change. Admins can also pause all new order submissions with a single switch, for example during a stock count. Try submitting with the switch on, then off.

Purchase Orders / #m31c

Draft · ready to submit.

  1. Recalculate prices on PO #m31cidle
  2. Email manager: PO submitted for approvalidle
  3. Audit log: PO #m31c submitted by Nehaidle
FIG. 03.5 / AUTOMATIONinteractive mock

04 / Product

What does the team work in all day?

  1. 01 / Dashboard

    Orders, revenue and fulfilment at a glance

    The overview dashboard: orders, revenue, average order value and fulfilment time for any date range, with the revenue trend underneath.

    Overview dashboard with order, revenue and fulfilment figures and a revenue trend chart
    FIG. 04.1 / Dashboard
  2. 02 / Pricing tiers

    Every tier's discounts, side by side

    One place to see and edit discounts for every customer type, per series and per product.

    Slabs table with CNF, Retail and Wholesale discount columns per series and product
    FIG. 04.2 / Pricing tiers
  3. 03 / Purchase orders

    Drafts on their way to approval

    Purchase orders by customer, pricing tier, value and status, filterable by who created them.

    Purchase orders list with customer, slab, items, order value and draft status
    FIG. 04.3 / Purchase orders
  4. 04 / Sales order

    One order: what's left to ship

    Items still to ship, items already dispatched, order cost and a running audit log, with tabs for shipments, cancellations and returns.

    Sales order detail with items awaiting shipment, order cost and an audit log
    FIG. 04.4 / Sales order
  5. 05 / Shipments

    Every parcel, traceable

    Every shipment with its status, warehouse, invoice amount and courier, filterable and exportable.

    Shipments list with status, warehouse, invoice amount, date and courier
    FIG. 04.5 / Shipments
  6. 06 / Inventory

    Stock down to the batch

    Inventory by product, expanded to show each batch's dates, price and available quantity, with low-stock flags.

    Inventory list expanded to a batch row with manufacturing and expiry dates
    FIG. 04.6 / Inventory

05 / Architecture

How do the rules stay in one place?

StaffbrowserWeb appBusiness engineAPI · permissionsJob queueAutomation workerprices · alerts · auditEmail alertsAI assistantMCP · OAuthDatabaseFile storageinvoices · slips
FIG. 05 / FROM ORDER TO ALERT
x 0 / y 0
  1. 01One place for the rulesAll pricing, approval and permission logic lives in the business engine. Every screen and the AI assistant follow the same rules.
  2. 02Slow work happens in the backgroundRecalculating prices and sending emails never slows down the person placing an order.
  3. 03Changes are hard to breakThe app and the engine share one definition of every piece of data. A change on one side that would break the other is caught before release.
  4. 04Built to growEach part can be scaled or updated on its own, and new features plug into the same pattern.

06 / Stack

What is it built with?

Web app
Next.js 16, React 19, Tailwind CSS, Radix UI, TanStack Query & Table, Recharts
Business API
Bun, Elysia, TypeBox validation, OpenAPI docs
Type-safe client
Eden Treaty (generated from the API's own types)
Authentication & roles
Better Auth with custom role-based access control
Database
PostgreSQL 17, Drizzle ORM
Background jobs & events
BullMQ on Redis
AI connector
Model Context Protocol (MCP) server with OAuth
Email
React Email, Resend
Files
Flystorage (local or cloud object storage)
Infrastructure
Docker, Docker Compose, GitLab CI/CD (staging and production pipelines)

07 / Delivered

What did the client receive?

  1. 01Web applicationDashboards and full management screens for customers, catalogue, pricing, orders, shipments, returns, inventory, targets and users.
  2. 02Business APIA documented API covering every feature, with permission checks on each action.
  3. 03Automation serviceBackground price syncing, low-stock and expiry alerts, purchase-order reminders, automatic rejection of stale orders, and audit logging.
  4. 04AI-assistant connectorSecure, permission-aware access for AI assistants to ask questions about sales, orders, shipments, cancellations and pending orders.
  5. 05Email notificationsBranded templates for order, shipment, stock and batch events, plus password resets.
  6. 06Deployment pipelineContainerised services with automated build and deploy for separate staging and production environments.
  7. 07DocumentationArchitecture, API, database, features, configuration, deployment and monitoring guides, plus a design spec and plan for each major feature.

08 / Impact

What changed for the business?

  • One version of the truth

    Sales, accounts, warehouse and management all work from the same live data.

  • Fewer pricing errors

    Tier discounts and tax are applied automatically and kept in sync when prices change.

  • Full traceability

    Every order, shipment, stock movement and return has a history of who did what and when.

  • Better stock control

    Batch and expiry tracking, plus automatic alerts, help prevent stock-outs and write-offs.

  • Faster answers

    Managers can check performance on the dashboard, or just ask the AI assistant.

  • Safe to delegate

    Role-based access lets the business add staff without exposing data they shouldn't see.

09 / What's next

Where does the platform go from here?

  1. 01In-app AI chatA chat screen inside the web app is already in place and marked "coming soon".
  2. 02Accounting and payment integrationsConnecting invoices and payments to the accounting system and to payment gateways.
  3. 03Mobile accessA mobile experience for sales staff in the field.
  4. 04Deeper reporting and exportsMore advanced reports, and exports for every type of record.