Back to projects
Enterprise SaaS

CRMLogy — Enterprise CRM & Sales SaaS

Multi-Tenant Agency CRM with Automated Pipelines

LaravelPHP 8.1MySQLPusherREST APIMulti-TenancyRedisSanctum
System Throughput
50K+req/day
Notification Latency
<50ms
Tenant Isolation
100%
API Endpoints
89routes

All-in-one multi-tenant agency CRM SaaS for lead tracking, automated deal pipelines, subscription billing, team activity metrics, and communication workflows. Built to serve multiple agencies on a single infrastructure while maintaining strict data isolation.

Architecture & System Design

CRMLogy uses a middleware-based multi-tenant architecture where each agency operates as an isolated tenant on shared infrastructure. The system resolves tenant context from subdomain headers, applies global Eloquent scopes for data isolation, and uses Pusher WebSockets for real-time dashboard updates.

Request Flow
Client Request (Subdomain)
Tenant Resolution Middleware
Sanctum Auth Gate
TenantScope Global Scope
Business Logic Layer
Event Broadcasting (Pusher)
Real-Time Dashboard Update
  • Database-per-tenant considered but rejected for cost — used row-level isolation with composite indexes instead
  • Custom middleware resolves tenant from subdomain and injects tenant context into the service container
  • All Eloquent models use a TenantScope global scope that auto-filters queries by tenant_id
  • Redis-backed queue system for async job processing (email, reports, notifications)

Engineering Challenges

Multi-Tenant Data Isolation

Problem

Ensuring zero cross-tenant data leakage while maintaining query performance across 5+ tenants sharing a single MySQL database.

Solution

Implemented a TenantScope global scope on all models, composite indexes on (tenant_id, primary_key), and middleware-level tenant resolution. Added audit logging for all cross-tenant query attempts.

Result

Zero cross-tenant incidents. Query performance maintained with < 5ms overhead per request.

Real-Time Pipeline Updates

Problem

Deal pipeline movements and lead assignments needed instant visibility across all team members without page refresh.

Solution

Integrated Pusher WebSockets with Laravel Echo. Pipeline state changes trigger broadcast events on private tenant channels. Client-side optimistic updates with server reconciliation.

Result

< 50ms notification delivery. 100+ concurrent dashboard users without degradation.

Subscription Billing Automation

Problem

Managing agency subscriptions with prorated billing, plan upgrades/downgrades, and automated invoice generation.

Solution

Built a custom billing engine on top of Stripe Connect with webhook handlers for subscription lifecycle events, proration calculations, and automated PDF invoice generation.

Result

Fully automated billing. Zero manual intervention for plan changes.

Core Features

Lead Distribution Engine

Automated round-robin lead assignment with weighted scoring, priority routing, and real-time agent availability tracking.

Clean Code

TenantScope — Automatic Tenant Isolation
1<?php
2
3namespace App\Models\Scopes;
4
5use Illuminate\Database\Eloquent\Builder;
6use Illuminate\Database\Eloquent\Model;
7use Illuminate\Database\Eloquent\Scope;
8
9class TenantScope implements Scope
10{
11 public function apply(Builder $builder, Model $model): void
12 {
13 if ($tenantId = auth()->user()?->tenant_id) {
14 $builder->where(
15 $model->qualifyColumn('tenant_id'),
16 $tenantId
17 );
18 }
19 }
20}