BrandLift.ai
Technical Overview & Architecture Guide
This document covers every technology used in the BrandLift platform — what it does, why it was chosen, how the components connect, and where the stack is heading. Written for onboarding engineers, outsourced support staff, and technical stakeholders.
What is BrandLift?
BrandLift is an AI-powered local business acquisition and web presence platform. It automates the entire journey from finding a small business online to converting them into a paying hosted website client — with minimal human intervention at each step.
System Architecture
The platform is a single Next.js application that acts as both the admin control plane and the client-facing web layer. External services are consumed via API — no microservices, no separate worker processes (except the scraper relay on Retina).
Technology Stack
Core Framework
| Technology | Version | What It Does | Why We Use It |
|---|---|---|---|
| Next.js | 14.1 | Full-stack React framework — API routes, SSR, middleware, static assets in one deployment. | Eliminates separate backend. App Router enables true Server Components, reducing client bundle size on data-heavy admin pages. |
| React 18 | 18.2 | UI component library. Runs server-side (RSC) and client-side with concurrent rendering. | Server Components let the 1,600-line Lead Reservoir page run entirely server-side — zero hydration cost for read-only data. |
| TypeScript | 5.3 | Statically typed JavaScript. Catches errors at compile time across 200+ API routes. | At 50,000+ lines, type safety is non-negotiable. Refactors that would silently break 30 files in plain JS are caught immediately. |
Data Layer
| Technology | Role | Why |
|---|---|---|
| MySQL | Primary relational database on localhost:3306. Stores all leads, proposals, accounts, email events, and site data. | Battle-tested for structured relational data. 30+ models with FK relationships benefit from SQL JOIN performance. Free on self-hosted VPS. |
| Prisma ORM v5 | Database client and schema manager. Generates TypeScript types from schema, handles migrations. | Eliminates SQL injection bugs and runtime type errors. Schema is single source of truth — change schema, all query types update automatically. |
AI & Intelligence
| Service | Model | Used For | Why |
|---|---|---|---|
| Google Gemini | gemini-2.5-flash | Taglines, SEO copy, proposal text, email subjects, crawler prompt optimization, OpenClaw extraction. | Flash tier balances speed and cost — most generation tasks complete under 2 seconds. Native SDK with structured JSON output reduces parsing errors. |
| Google Imagen 3 | imagen-3.0-generate-images-001 | AI logo generation — 4 logo variants per request based on industry, color, and font inputs. | Highest-quality image generation via Google AI Studio. Direct REST API, no third-party dependency. |
| Google PageSpeed | v5 API | Mobile and desktop performance scores (0–100) during SEO audit. | The authoritative performance score — what Google uses for rankings. Free API with generous limits. |
| Google Places | Places v1 | Local business discovery, ratings, location data for lead enrichment. | Most complete source of structured local business data available. |
Lead Generation & Outreach
| Service | Used For | Why |
|---|---|---|
| Oxylabs | Residential proxy network for scraping Google SERPs and directories without blocks. Max 5 concurrent sessions, 3 retries with backoff. | Residential IPs bypass anti-bot detection that blocks datacenter proxies. Realtime API returns fully rendered HTML — no headless browser needed for most pages. |
| Apollo.io | Contact enrichment — decision-maker names, emails, phone numbers from company domain. | Largest B2B contact database via API. Returns structured JSON with confidence scores. Often finds the exact owner/manager needed. |
| Instantly.ai | Production cold email sending — sequences, schedules, unsubscribe handling, delivery tracking via webhooks. | Specialized for cold outreach — handles warming, rotation across sending accounts, deliverability. Webhooks feed back into EmailEvent records. |
| Hunter.io | Domain-level email pattern discovery — finds most likely email format when Apollo has no direct contact. | Complements Apollo. Strong at inferring email patterns (first.last@company.com) when no direct contact exists. |
| Twilio | SMS outreach to carrier-verified mobile leads. | Carrier-verified mobiles convert better than cold email. Industry standard for programmable SMS with delivery receipts. |
Commerce & Infrastructure
| Service / Tool | Role | Why |
|---|---|---|
| Stripe | All payment processing — checkout sessions, subscriptions, billing portal, invoices, webhooks. | Standard for SaaS billing. Webhook-driven, no polling. Billing Portal lets clients self-manage without custom UI. |
| Hostinger API | Hosting slot management — sync available slots, track client assignments, query VM metrics. | BrandLift production infrastructure runs on Hostinger. API enables programmatic slot allocation. |
| PM2 | Process manager — keeps Next.js running, single fork mode on port 3001, 1GB memory ceiling, auto-restart. | ecosystem.config.js |
| Nginx | TLS termination, reverse proxy to :3001, serves static files from /public/ bypassing Node.js. | /etc/nginx/sites-available/brandlift-brain |
| Playwright | Contact form detection/submission during enrichment, template X-ray captures, screenshot generation. | More reliable than Puppeteer for modern SPAs. Stealth plugin bypasses bot detection on contact pages. |
| Remotion | Programmatic video rendering from React components. | Video creation with the same React/CSS skills already in the codebase. |
| Recharts | All data visualization — admin Command Center and Client Portal metrics. | Native React, composable, real DOM elements that respond to theme colors. |
| Sharp | Server-side image processing — resize, compress, convert uploaded assets. | Fastest Node.js image processing library. |
The Five Pipelines
A. Lead Discovery
Key files: lib/oxylabs-client.ts, /api/pipeline/route.ts. Unique on domain_key (normalized domain).
B. Enrichment Pipeline
Key files: lib/enrichment/dom-crawler.ts, lib/apollo-engine.ts, lib/hunter-client.ts.
C. SEO Audit
| Category | Max Points | Example Signals |
|---|---|---|
| Technical | 25 | HTTPS, viewport meta, PageSpeed mobile/desktop |
| On-Page SEO | 25 | Title tag, meta description, H1, JSON-LD schema |
| Content | 20 | Services/About/Contact pages, word count, image alt text |
| Local SEO | 20 | Phone, address, Google Maps embed, review mentions |
| Trust | 10 | HTTPS, contact form, privacy/terms links |
Key file: lib/site-auditor.ts. Results cached in LeadReservoir.site_audit_json.
D. Proposal Dispatch
Key files: lib/instantly-engine.ts, /api/leads/release. Auto-detects pathway: migrate (has website) or rebrand (new site).
E. Client Onboarding
Database Schema
-- Lead-to-client chain
LeadReservoir ──(1:many)──→ Proposal ──(many:1)──→ ClientAccount
│
├──→ SiteTemplate
└──→ GeneratedLogo
-- Email tracking
LeadReservoir ──(1:many)──→ EmailEvent (ON DELETE CASCADE)
-- Hosting allocation
HostingPlan ──(1:many)──→ ServerSlot
| Model | Key Fields | Purpose |
|---|---|---|
| LeadReservoir | domain_key, enrichment_status, target_score, site_audit_json | Every discovered prospect. Unique on domain_key. |
| Proposal | subdomain, client_id, lead_id, custom_data | Released proposals. custom_data stores pathway + brand kit. |
| ClientAccount | email, active_plan, portal_access | Portal login credential. JWT signed from this row. |
| EmailEvent | event_type, apollo_message_id | Full email lifecycle: SENT → OPENED → CLICKED → REPLIED. |
| GeneratedLogo | image_url, is_selected | Imagen 3 outputs stored for reuse across proposal sessions. |
| ServerSlot | status (AVAILABLE/ACTIVE) | One slot = one hosted client website on Hostinger. |
Infrastructure Layout
Brain Node (Primary)
Runs: Next.js 14, MySQL 8, Nginx, PM2 single fork on :3001
Static assets: Nginx serves /public/generated-logos/, /public/template-previews/, /public/videos/ directly from disk
Subdomains: Nginx wildcard *.brandlift.ai → all route to same Next.js app. Middleware rewrites {sub}.brandlift.ai → /portal/proposal/{sub}
Deploy Process
git pull npm run build # ~2 min Next.js production build pm2 restart brandlift-brain
Admin Tool Map
| URL | Name | Purpose |
|---|---|---|
/admin | Command Center | Home tile grid — entry point to all admin tools. KPIs, system event feed. |
/admin/leads | Lead Reservoir | Primary daily-use page. View, filter, release leads. Expandable rows show enrichment, email history, and actions. |
/admin/proposal-admin | Proposal Admin | All dispatched proposals — status, pathway, links to view or manage. |
/admin/proposal-preview | Proposal Preview | Side-by-side tabbed preview of both proposal templates (Web / No-Website). |
/admin/lead-engine | Lead Engine | Configure and trigger automated lead pipeline. Set target industry + city, run phases, monitor telemetry. |
/admin/hosting-slots | Hosting Slots | Visual grid of all Hostinger slots — AVAILABLE/ACTIVE/ERROR status. |
/admin/template-gallery | Template Gallery | Browse all template previews by industry. |
/admin/vault | Vault Manager | Full vault browser per category. Upload assets, set visibility/hero flags. |
/admin/media-library | Media Library | Browse and upload images across all industry categories. |
/admin/template-xray | Template X-Ray | Playwright-captured annotated screenshots. CSS calibration maps for brand injection. |
/admin/cms-white-label | CMS White Label | Configure WordPress admin branding — logos, CSS, footer text. |
/admin/crawling | OpenClaw Crawl | Manual crawl interface. URL + natural language extraction goal → structured data. |
/admin/openclaw | OpenClaw Probe | Deep AI-guided site intelligence extraction. |
/admin/settings | Global Settings | Pricing tier definitions and default email template subject/body. |
/admin/support-desk | Support Desk | Internal ticket console. View, comment, escalate to Hostinger. |
/admin/adam-config | ADAM Config | Knowledge base manager for the ADAM support AI. |
/admin/alert-config | Alert Config | Configure Slack/SMS alert routing by ticket type and priority. |
/admin/fleet-window | Fleet Window | Health monitor for Brain and Retina nodes. |
/admin/command-center | Command Center | Revenue charts, system events, client timeline, notification engine. |
/admin/site-builder | Site Builder | Headless GrapesJS editor for admins. Pick vault templates, inject brand data. |
External Services & API Reference
| Service | Env Var(s) | Regenerate At | If It Goes Down |
|---|---|---|---|
| Google Gemini | GEMINI_API_KEY | aistudio.google.com | Taglines, copy, OpenClaw fail. Proposals still render. |
| Google Imagen 3 | GOOGLE_API_KEY | aistudio.google.com | Logo generation fails. Everything else unaffected. |
| Google PageSpeed | PAGE_SPEED_INSIGHTS_API_KEY | console.cloud.google.com | SEO audit runs without performance scores. |
| Oxylabs | OXYLABS_USERNAME/PASSWORD | dashboard.oxylabs.io | Lead discovery pipeline halts completely. |
| Apollo.io | APOLLO_API_KEY | apollo.io/settings | Contact enrichment fails. Hunter fallback still runs. |
| Instantly.ai | INSTANTLY_API_KEY, INSTANTLY_CAMPAIGN_ID | app.instantly.ai | Proposal emails not sent. Release action completes but email step fails. |
| Hunter.io | HUNTER_API_KEY | hunter.io/api-keys | Email fallback discovery fails. Low impact. |
| Twilio | TWILIO_ACCOUNT_SID/AUTH_TOKEN | console.twilio.com | SMS outreach fails. Email pipeline unaffected. |
| Stripe | STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET | dashboard.stripe.com | No new checkouts. Webhooks stop — client accounts not provisioned after payment. |
| Hostinger | HOSTINGER_API_TOKEN | hpanel.hostinger.com | Slot sync and VM metrics fail. Existing clients unaffected. |
Scalability Roadmap
Current architecture is intentionally simple — a single server handles everything. Right for the current stage. Below is an honest assessment of limits and the scaling path.
Current Capacity
Comfortable at 50–200 active clients, 10,000+ leads, ~50 concurrent API requests before degradation. MySQL on localhost handles this range with <50ms median query time. PM2 single fork is a bottleneck under sustained Playwright/image-processing workloads.
Security Notes
| Layer | Mechanism | Cookie | Expiry |
|---|---|---|---|
| Admin access | Manual cookie set via /api/admin/set-admin-cookie. No password — admin access assumes trusted device. | bl_admin | Session |
| Client portal | Email + PBKDF2-SHA256 password. JWT signed with HMAC-SHA256 using PORTAL_JWT_SECRET. | bl_portal_session | 7 days |
| Admin emulation | Admin clicks "Client Portal" → emulate-client mints 2-hour JWT with emulated:true flag. | bl_portal_session | 2 hours |