LeadMachine (SaaS-AI)
Autonomous AI Business Platform for Enterprise Lead Discovery & Intelligence
ai_engine=Google_Gemini • rate_limit=PASS_REDIS • status=ENRICHED_200
LeadMachine (SaaS-AI) is an autonomous business platform engineered to automate lead discovery, structured firmographic enrichment, predictive outcome scoring, and strategic outreach. Built on Next.js 16 and Prisma ORM, it addresses common operational friction in modern B2B customer acquisition pipelines.
Triaging unstructured web inquiries and manual lead research causes severe response delays and lost revenue opportunities. Meanwhile, standard AI implementations often generate non-deterministic responses, lack rate-limiting protection, and risk exposing sensitive tenant context across shared models.
B2B sales teams, growth marketing agencies, and software startups requiring automated, high-precision prospect qualification without hiring dedicated research personnel.
- Designed end-to-end system architecture from database relational schemas to Next.js 16 UI and edge middleware.
- Implemented Upstash Redis rate-limiting guards to protect serverless functions and generative AI budget.
- Engineered Google AI (Gemini) prompt pipelines enforcing strict JSON schema parsing and fallback states.
- Created Prisma migration workflows and seed scripts ensuring database consistency across environments.
- Integrated Inngest event handlers for resilient background processing of lead enrichment queues.
LeadMachine (SaaS-AI) System Architecture
A three-tier modern SaaS architecture separating client-side presentation, edge-governed API logic with rate limiting, and an asynchronous data/AI pipeline with PostgreSQL persistence.
01. Presentation & Client Layer
Fast, responsive Next.js 16 App Router client with server-driven components.
Interactive overview of lead health, forecasts, and conversion funnels
Sortable, filterable list of prospective leads with enrichment status
Subscription tier management and Stripe customer billing portal link
02. API & Edge Security Layer
Edge-executed middleware and Next.js route handlers with defensive guards.
Token-bucket rate limiting defending AI endpoints against abuse & quota exhaustion
Verifies user permissions before accessing tenant analytics and data mutations
Processes invoice events and subscription state changes idempotently
03. Intelligence & Data Pipeline
AI model orchestration, background task processing, and relational storage.
Analyzes company domains, scores buyer readiness, and structures JSON payloads
Asynchronous task queue handling multi-step lead enrichment with retries
Primary relational datastore holding tenants, leads, logs, and billing state
Semantic retrieval across historical CRM conversations
- Next.js 16 App Router UI
- Prisma ORM Schema & Migrations
- PostgreSQL Database Connection
- Upstash Redis Rate Limiting
- Google AI / Gemini Pipeline
- Stripe Billing Webhook Integration
- Vector Embedding Store (pgvector)
- Microsoft 365 / Google Workspace Bi-Directional OAuth Mail Sync
#1: Defensive Edge Rate-Limiting with Upstash Redis
Decision RecordGenerative AI API endpoints incur direct cost per token and are vulnerable to malicious scraping or runaway loops.
Implemented Upstash Redis token-bucket rate limiting in middleware before any LLM API invocation or database compute is reached.
Adds a negligible ~15ms network hop to Redis on API requests, but completely eliminates runaway LLM billing spikes and denial-of-wallet vectors.
#2: Prisma Schema Migration Discipline over Ad-Hoc DB Writes
Decision RecordFast-moving prototype code often introduces database schema drift between local, preview, and production environments.
Enforced all database modifications through version-controlled Prisma migration files (migrations/) and explicit prisma.config.ts configuration.
Requires running migration scripts for every schema iteration instead of direct DB mutations, but ensures 100% reproducible environments and type safety.
#3: Asynchronous Enrichment Decoupling with Inngest
Decision RecordFirmographic scraping and LLM evaluation take several seconds, risking serverless HTTP gateway timeouts if handled synchronously.
Decoupled HTTP intake from enrichment work using Inngest event queues, returning an immediate 202 response to the user while background jobs execute.
Requires client polling or real-time event updates to reflect completed state, but prevents HTTP 504 timeouts and offers automatic retry backoff.
Upstash Redis rate-limiting guards applied on public routes with strict token bucket allocations per IP and tenant ID.
Role-based permissions governing administrative endpoints, restricting billing modifications to tenant owner accounts.
Audit trails recorded across administrative actions, documented in phase 48 observability and system readiness reports.
Repository Audit & Evidence // LeadMachine (SaaS-AI)
Verified software artifacts and production verification scope for LeadMachine (SaaS-AI)
Microsoft 365 OAuth sync and multi-tenant vector embedding collections are documented as planned future roadmap items; not yet merged into production main.
Configured Google AI Gemini prompts with strict JSON schema definitions and created Zod validation boundary checks to parse and sanitize all model responses.
Maintained explicit version-controlled migrations in the migrations/ folder and automated seed scripts to guarantee reproducible test environments.
Live Production Prototype. The core application, AI enrichment pipeline, Prisma migrations, and Stripe integration are deployed and operational at https://saas-ai-sooty.vercel.app.
- Vector embedding store with pgvector for semantic CRM lookups.
- Direct OAuth integration for Microsoft 365 and Google Workspace email dispatch.
- Team collaboration workspaces with granular sub-user permissions.
Related Systems in RANA.OS
View All Projects →KeyAbroad 2.0
Educational Consultancy Operations Platform & Student Application Engine
Biometric Attendance & HR Integration Engine
Hardware-to-Cloud Raw TCP/IP Socket Ingestion & Offline-Resilient Sync Daemon