← Blog
phpsaasautomationwebdev

Anatomy of a Multi-Tenant SaaS CRM PHP Stack: A LeadHub Tour

An architecture tour of LeadHub, a self-hosted multi tenant SaaS CRM PHP script: tenancy, lead pipelines, web-to-lead forms, automations, and billing.

The build-vs-buy question for a CRM product has a specific shape in the PHP world. If you have ever scoped a multi tenant SaaS CRM PHP build, you know the lead table and the CRUD screens are the part you finish in a sprint. What eats the rest of the year is everything around them: tenant isolation, plan gating, subscription billing with tax-compliant receipts, signed webhooks, GDPR workflows, and every lead source your first paying customer asks about in week one.

Full disclosure: we build and sell LeadHub, the product this article walks through. Treat it as an architecture tour rather than a pitch - an inventory of what a shipping multi-tenant CRM script actually contains. LeadHub is a self-hosted Laravel 13 application with a Filament 4 admin panel, Livewire 3 reactivity and Tailwind CSS, shipped as complete unencrypted source with no IonCube, currently at version 2.0.9 (updated 2026-07-30).

Tenancy first: the multi tenant SaaS CRM PHP architecture

LeadHub treats the tenant, not the user, as the primary unit. Each tenant is a workspace with its own leads, pipelines, automations, sequences, forms, calendar and team, and isolation is enforced at the query level so tenants do not see each other’s leads, deals or settings. Access control spans six roles - super-admin, tenant owner, tenant admin, staff, viewer and customer - with granular permissions below that.

White-labeling is per tenant and covers the details that usually leak: logo, favicon, app name, footer links, and primary and accent colors flowing through the dashboard, admin panel, widget, forms, landing pages and emails. Each workspace also gets public surfaces that work without login: landing pages built from reusable blocks, shareable forms, a booking calendar with two-way Google Calendar and Microsoft Outlook sync, and team contact pages.

Above the tenants sits a super-admin panel where the platform owner builds plans with feature gates and usage limits, manages tenants, configures gateways, and watches MRR, ARR and churn. Two operator details stand out. One-click tenant impersonation runs as a 60-minute audited session, so you can troubleshoot a tenant without ever asking for a password. And plan feature flags can hide whole admin sections from the tenant admin per tier, so cheaper tiers simply see a smaller product. The panel itself can be locked to specific IP or CIDR ranges.

Web-to-lead capture from nineteen channels

Lead capture is where a hand-rolled CRM quietly becomes a maintenance treadmill, because every channel is its own integration. LeadHub ingests from nineteen channels natively. Social and ads cover Facebook Lead Ads, Instagram, TikTok, LinkedIn, X/Twitter, Snapchat and Pinterest; messaging covers WhatsApp, Viber and Telegram; paid search covers Google Ads, YouTube and Microsoft Ads; and the inbox-and-forms bucket covers IMAP email parsing, Typeform, JotForm, Calendly bookings and web forms. Manual entry adds bulk CSV import, copy-paste bulk add and a single-lead form, and a dedicated parser turns IndiaMART and Justdial directory enquiries into structured leads.

For your own properties there are three routes in. An embeddable JavaScript widget drops a branded capture form onto any website from a single snippet, matching the tenant’s brand colors and submitting cross-origin to the LeadHub backend, with multi-step support, file uploads and reCAPTCHA. Public shareable forms add conditional logic, QR codes and branded thank-you pages. And a RESTful API exposes leads, pipelines, deals, forms, automations, sequences and webhooks behind scoped API keys, with per-tenant rate limiting (60 requests per minute by default, configurable per plan) and interactive docs in every tenant dashboard.

Whatever the source, a lead arrives with its context attached: source, campaign, UTM tags, assigned user, pipeline stage, score, custom fields and a complete activity timeline.

Pipelines, sequences and a visual automation engine

The working surface is a drag-and-drop Kanban board with custom stages, colors, deal-value tracking and probability percentages; each tenant can create unlimited pipelines, so sales, onboarding, support and recruiting flows live side by side. A scoring engine reacts to field, behavior and engagement triggers, duplicate detection uses configurable email and phone fuzzy matching with a merge workflow that preserves activity history, and win/loss reasons are captured at close.

Marketing automations follow a trigger, condition and action model - round-robin assignment, lead scoring, SMS, webhooks and Slack notifications - and a Visual Flow Builder wires those nodes on a drag-and-drop canvas instead of a settings form. Email sequences run with delays, conditions, stop-on-reply and stop-on-won behavior plus open, click and reply tracking. Click-to-call and SMS run through Twilio or Plivo, chosen per workspace; calls are logged with status and duration, and Twilio calls add recording with AI transcription and summary.

Outbound webhooks fire on events such as lead.created, lead.stage_changed, deal.won, form.submitted and automation.triggered, with replay-safe HMAC signatures, secrets encrypted at rest, delivery logs, retry tracking and dead-letter alerts. There is also an optional AI layer - next-best-action suggestions, draft replies, score reasoning, an embeddable website chatbot and an autonomous email follow-up agent - but it is plan-gated, and the CRM runs fully without any LLM key.

Billing that survives an accountant

Monetization is built in rather than bolted on. Five gateways ship out of the box: Stripe with Hosted Checkout, the Customer Portal, recurring subscriptions and webhook idempotency; PayPal via the billing-subscriptions API with signed-webhook verification; Razorpay for the Indian market; Paystack for Sub-Saharan Africa; and manual bank transfer with super-admin confirmation. Plans carry monthly and annual pricing with a configurable annual discount, seat caps and usage limits; coupons support percentage or fixed-amount discounts, trial extensions and plan restrictions.

The details are the point. Receipts are sequentially numbered (LH-YYYY-NNNNNN) with EU VAT, US sales tax and per-tenant currency, refunds auto-generate negative credit notes, trials expire automatically, and dunning escalates payment-failure emails toward suspension. An affiliate engine tracks referral codes with recurring 20% commissions and a payout audit trail. If you have ever written invoice numbering and VAT logic by hand, you know how much of a build this one section represents.

Running it: shared hosting, security and GDPR

LeadHub is deliberately deployable where a lot of PHP still lives: shared hosting. A browser-driven installer handles setup with no SSH and no Composer, updates run migrations and clear caches from the browser, URL-based cron works with cPanel, an optional sync mail driver covers hosts where queue workers cannot run, and a health endpoint probes database, cache and storage with a 200 or 503 response. It needs PHP 8.4 or higher (8.5+ recommended), MySQL 5.7+ or 8.x with MariaDB 10.3+ supported, and Apache or Nginx.

Security includes TOTP two-factor authentication with recovery codes and per-role enforcement, an atomic cache-based brute-force lockout, trusted-proxy IP resolution behind Cloudflare or Nginx, and a password policy with a breach-database check on signup. The compliance suite covers an Article 28 data processing agreement as a public download, a cookie consent banner, Article 20 data export as a full ZIP, and Article 17 erasure as a 30-day cool-off workspace deletion. Retention policies purge audit logs, login attempts and webhook events, and tax receipts deliberately survive tenant erasure to meet the legally required 7-10 year retention.

When you should still build your own

An honest note, because this is where marketing pages usually go quiet. LeadHub is a Laravel application; if your team lives in Node, Python or Go, adopting a large PHP codebase carries a real cost even with clean source. Isolation is enforced at the query level inside one shared application, so if your compliance regime demands a physically separate database per tenant, this architecture is not that. It is also a commercial script rather than a community open-source project, and a young one at 27 sales on CodeCanyon, so you rely on vendor updates rather than a large third-party plugin ecosystem. And if the CRM itself is your differentiator, owning every line may justify the build time. LeadHub fits when the CRM is the vehicle rather than the product: an agency consolidating client leads, an internal sales team, or a niche SaaS where your edge is distribution and vertical fit, not pipeline plumbing.

If you are weighing a build against this, or want more detail on any subsystem above, ask in the comments - happy to go deeper on the tenancy or billing internals.

A copy of this article is also published on dev.to, where the comments are open.