AI Lead Conversion System for Real Estate

03/2025 — 04/2025
Multi-tenant coreDeterministic pipeline

The Problem

Disconnected CRM tools create leakage between first touch and booked appointment and make pipeline consistency hard to enforce.

The Solution

Built a multi-tenant conversion platform that unifies conversational capture, AI qualification, deal lifecycle management, and analytics. Enforced tenant isolation and deterministic stage transitions in Supabase-backed APIs, with optional async delivery via FastAPI and Redis.

Impact

Enterprise-grade conversion workflow with tenant isolation and reliable stage transitions.

Architecture

A Next.js frontend handles lead capture and deal pipeline visualization with React 19 server components for fast initial loads. FastAPI manages the AI qualification layer — receiving lead data, calling OpenRouter for scoring, and publishing results to a Redis queue for async processing. Supabase enforces row-level security for multi-tenant isolation, with PostgreSQL views that scope all queries to the authenticated tenant. Zod schemas validate all API boundaries between the frontend, FastAPI, and Supabase to prevent data inconsistencies across the pipeline.

Key Challenges

  • Multi-tenant data isolation was the hardest architectural constraint. A misconfigured RLS policy could expose one agency's leads to another. Wrote a test suite that impersonates different tenant JWTs and asserts that cross-tenant queries return empty results — ran this on every schema migration.
  • Deal stage transitions needed to be deterministic — agents couldn't skip stages or move backwards without an explicit override. Implemented a finite state machine in TypeScript that validates every transition against an allowed-transitions map before writing to Supabase.
  • FastAPI and Next.js needed to share Zod validation schemas without duplication. Extracted all shared schemas into a single TypeScript package imported by both the Next.js app and a Pydantic-compatible auto-generated Python schema, keeping both layers in sync.

Key Learnings

Multi-tenant architecture decisions made early are very hard to change later — RLS policies, schema namespacing, and JWT claim structure all need to be designed together from day one, not bolted on. I also learned that Redis as an async queue between FastAPI and Supabase adds meaningful complexity for modest throughput gains — for most real estate agency scales, a simpler Supabase edge function would have been sufficient.

Technologies

Next.js 16React 19TypeScriptSupabasePostgreSQLOpenRouterZodTailwind CSSFastAPIRedis