Building a multi-tenant CRM that routes every lead in seconds, with Next.js and MongoDB

How GrowthPilot pulls leads from ads, WhatsApp, forms and APIs into one intake pipeline, routes them with lead pools and SLAs, works them in one inbox, and markets to them with campaigns, workflows and social posts.

DSDilawar Singh 4 min read 0 views
Building a multi-tenant CRM that routes every lead in seconds, with Next.js and MongoDB

Ask a sales team where they lose deals and the answer is rarely the pitch. It is the gaps: a Facebook lead that sat unanswered over a weekend, a WhatsApp enquiry nobody owned, the same person turning up three times from three channels, a campaign sent to someone who bought last week. GrowthPilot is our attempt to close those gaps in one product: a multi-tenant CRM and marketing platform, built with Next.js 15 and MongoDB, that captures leads from every channel, gets each one to the right rep within seconds, and then keeps marketing to them on email, SMS, WhatsApp and social.

This post walks through how it is put together.

The GrowthPilot website: an animated 3D lead-funnel hero, editable from the built-in CMS

One intake pipeline for every channel

Leads arrive from a long list of places: Facebook and Instagram Lead Ads, WhatsApp, Messenger and Instagram DMs, Google Ads and TikTok lead forms, LinkedIn, hosted and embedded web forms, a REST API with scoped keys, signed webhooks from Zapier, Make or any website, API connectors that pull records from an external API on a schedule, and imports of spreadsheets, PDFs and business cards.

The rule we set early was that all of them go through one ingest function. Whatever the channel, a lead is normalised, its contact is matched against existing contacts (so the same person from WhatsApp and a web form is one contact), a repeat enquiry joins the lead that is already open, and every step is written to the lead's timeline. Adding a channel means writing an adapter, not another copy of the business rules.

The leads table: every lead from every channel with owner, stage, score and SLA, filterable and exportable

Routing in seconds, fairly

Once a lead exists, someone has to own it. GrowthPilot uses lead pools. Each pool picks a strategy: round robin, weighted, load-balanced, by skills, language or territory, performance-weighted, or a claim queue where reps pick leads up themselves. Routing respects each agent's availability, capacity and working hours.

Each pool also has a first-response SLA measured in business hours. If nobody responds in time, the lead is reassigned or escalated, and the miss is recorded.

Lead pools: auto-distribution by round robin, weights, skills and territory, or claim queues, with SLAs

Scores that change the routing

Recording misses only helps if it changes behaviour. A points ledger awards points for fast responses and wins and deducts them for missed SLAs and overdue tasks. Nightly snapshots turn it into leaderboards, and the same scores feed the performance-weighted routing strategy, so reps who answer quickly get more leads.

Team scoring: the points ledger and leaderboard for fast responses, wins and missed SLAs

One inbox, one send path

Reps work conversations in a unified inbox: email, SMS, WhatsApp, and Facebook and Instagram DMs, each next to the lead's details, with templates and internal notes. Behind it, providers are pluggable: SMTP, Mailgun, Bird, Twilio, MSG91 (including India's DLT registration) and the WhatsApp Cloud API.

Every outgoing message, whether a rep's reply, a campaign or a workflow step, goes through the same send queue. Before anything leaves, it checks consent, the suppression list, WhatsApp's 24-hour customer-service window, quiet hours and frequency caps. Putting these rules in one place means a new feature can't accidentally message someone who opted out.

The unified inbox: WhatsApp, email, SMS and social DMs with templates, notes and the lead's context

Campaigns, workflows and social posts

Marketing uses the same contacts and the same send path. Emails are designed in a GrapesJS drag-and-drop builder; SMS and WhatsApp templates use merge tags and keep versions. Campaigns go to dynamic segments in throttled batches, with A/B tests that pick a winner by opens or clicks, open and click tracking, one-click unsubscribe and bounce handling.

Workflows run on a visual canvas: a trigger such as a new lead, a status change or no reply, followed by conditions, waits, A/B splits, sends, assignment, tags, tasks and webhooks. Each lead has a run history, so you can see which path it took. Social publishing covers Facebook Pages, Instagram and LinkedIn, with approvals, a content calendar and recurring posts.

The workflow builder: triggers, conditions, waits, sends and tasks on a visual canvas

Schedules that can't double-run

A lot of GrowthPilot happens on a timer: SLA checks, routing retries, campaign batches, workflow waits, API connector pulls, social posts and nightly scoring. On a server, a worker process runs them. On serverless hosting, a cron call hits one endpoint every minute instead. Each schedule is claimed in the database before it runs, so a worker and a cron call, or two overlapping cron calls, never do the same job twice.

AI that knows when to stay quiet

AI is optional and brings its own key. It qualifies leads with a score, intent and next best action, writes hand-over summaries and reply drafts, writes emails, SMS and subject lines, builds segments from plain English and maps fields on imports. Auto-replies are sent only when the model is confident, and a human reply always takes over. Without a key, every AI control shows a clear "connect your AI key" state and the rest of the product works normally.

Lead detail: contact and consent, routing history and timeline, with the stored AI qualification and next step

See it running

The video tour moves through the website, the dashboard, leads and the pipeline board, lead pools, scoring, the inbox, the email builder, campaigns, workflows and social publishing.

Video tour of GrowthPilot

You can also open the read-only live demo of the sample organisation and sign in with a one-click demo account for each role. Sends and social posts are simulated there. The full source is available as GrowthPilot on the DEV3 marketplace, and the case study covers the design decisions in more detail.

DS

Written by

Dilawar Singh

CTO, DEV3 Technologies · ClinicPro, Inventra & WorkPro

Dilawar Singh is the CTO of DEV3 Technologies. He leads the engineering of DEV3’s own products — ClinicPro, Inventra and WorkPro — which are built, sold and supported by the DEV3 team from Mohali, India.

Keep reading

All articles