CRMLogy — Enterprise CRM & Sales SaaS
Multi-Tenant Agency CRM with Automated Pipelines
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.
- 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
Ensuring zero cross-tenant data leakage while maintaining query performance across 5+ tenants sharing a single MySQL database.
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.
Zero cross-tenant incidents. Query performance maintained with < 5ms overhead per request.
Real-Time Pipeline Updates
Deal pipeline movements and lead assignments needed instant visibility across all team members without page refresh.
Integrated Pusher WebSockets with Laravel Echo. Pipeline state changes trigger broadcast events on private tenant channels. Client-side optimistic updates with server reconciliation.
< 50ms notification delivery. 100+ concurrent dashboard users without degradation.
Subscription Billing Automation
Managing agency subscriptions with prorated billing, plan upgrades/downgrades, and automated invoice generation.
Built a custom billing engine on top of Stripe Connect with webhook handlers for subscription lifecycle events, proration calculations, and automated PDF invoice generation.
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
1<?php23namespace App\Models\Scopes;45use Illuminate\Database\Eloquent\Builder;6use Illuminate\Database\Eloquent\Model;7use Illuminate\Database\Eloquent\Scope;89class TenantScope implements Scope10{11 public function apply(Builder $builder, Model $model): void12 {13 if ($tenantId = auth()->user()?->tenant_id) {14 $builder->where(15 $model->qualifyColumn('tenant_id'),16 $tenantId17 );18 }19 }20}