Back to PortfolioAI SaaSCase Study

Build
Vision AI

AI-powered construction platform automating quote generation, project tracking, and asset monitoring with predictive analytics.

Next.js 15React 19TypeScriptPostgreSQLOpenAIAnthropicReact KonvaInngest

🏗️ Project Overview

BuildVision is a sophisticated AI-powered construction estimation and takeoff application that revolutionizes construction project estimation by combining multi-provider AI integration, real-time collaboration features, multi-tenant SaaS architecture, and advanced canvas-based drawing tools for construction plan analysis.

Technical Specifications

  • Stack: Next.js 15, React 19, TypeScript
  • AI Integration: 5+ AI providers with fallbacks
  • Backend: PostgreSQL, Inngest, WebSockets
  • Scale: Multi-tenant enterprise SaaS

Core Features

  • • AI-powered quote generation (2-5 minutes)
  • • Real-time collaborative takeoffs
  • • Advanced canvas drawing tools
  • • Multi-provider AI architecture

🤖 Multi-Provider AI Architecture

AI Providers

  • • OpenAI (GPT-4, O1)
  • • Anthropic (Claude 3.5 Sonnet)
  • • Google (Gemini 2.0 Flash)
  • • Perplexity (Sonar Pro)
  • • Groq (High-speed inference)

Intelligent Routing

  • • Task-specific model selection
  • • Cost optimization algorithms
  • • Automatic failover systems
  • • Performance monitoring
  • • Exponential backoff retry

Processing Pipeline

  • • 5-phase generation pipeline
  • • Parallel processing with Inngest
  • • Real-time progress tracking
  • • Error recovery strategies
  • • Comprehensive logging

Intelligent AI Provider Selection & Fallback System

Built a sophisticated multi-provider AI architecture with intelligent routing based on task complexity, cost optimization, and real-time availability monitoring.

// Multi-provider AI architecture
export const AI_MODELS = {
  // OpenAI Models
  O1: "o1-2024-12-17",
  GPT: "gpt-4o",
  GPT_4O_MINI: "gpt-4o-mini",
  
  // Anthropic Models  
  SONNET: "claude-3-5-sonnet-20241022",
  
  // Google Models
  GEMINI_FLASH_WEB: "gemini-2.0-flash-exp",
  GEMINI_FLASH_THINKING: "gemini-2.0-flash-thinking-exp",
  
  // Perplexity Models
  PERPLEXITY_SMALL: "sonar",
  PERPLEXITY_LARGE: "sonar-pro",
} as const;

// Intelligent provider selection
export function getClientForModel(model: AIModel) {
  const modelId = AI_MODELS[model];
  
  if (modelId.includes("sonar")) {
    return { client: perplexity, type: "perplexity" };
  }
  if (modelId.includes("gemini")) {
    return { client: googleGenerativeAI, type: "google" };
  }
  if (modelId.includes("claude")) {
    return { client: anthropic, type: "anthropic" };
  }
  
  return { client: openai, type: "openai" };
}

// Automatic provider fallback
export async function callAIWithFallback(
  prompt: string, 
  primaryModel: AIModel,
  options: AICallOptions = {}
): Promise<AIResponse> {
  const providers = [primaryModel, 'gpt-4o-mini'];
  let lastError: Error;
  
  for (const [index, model] of providers.entries()) {
    try {
      const delay = Math.pow(2, index) * 1000;
      if (index > 0) {
        await new Promise(resolve => setTimeout(resolve, delay));
      }
      
      return await callAIProvider(prompt, model, options);
    } catch (error) {
      lastError = error;
      console.warn(`Provider ${model} failed, trying next...`);
    }
  }
  
  throw new Error(`All providers failed: ${lastError.message}`);
}

🎨 Advanced Canvas & Real-time Collaboration

React Konva Canvas with WebSocket Collaboration

// Advanced drawing tools with calculations
export const useAreaSelection = () => {
  const [currentPolygon, setCurrentPolygon] = useState<Point[]>([]);
  const [completedAreas, setCompletedAreas] = useState<TakeoffArea[]>([]);
  
  const calculatePolygonArea = (points: Point[]): number => {
    // Shoelace formula for polygon area calculation
    let area = 0;
    const n = points.length;
    
    for (let i = 0; i < n; i++) {
      const j = (i + 1) % n;
      area += points[i].x * points[j].y;
      area -= points[j].x * points[i].y;
    }
    
    return Math.abs(area) / 2;
  };
  
  const convertPixelsToRealUnits = (pixelArea: number, scale: number) => {
    return pixelArea * Math.pow(scale, 2);
  };
  
  const handlePolygonComplete = useCallback((points: Point[]) => {
    const pixelArea = calculatePolygonArea(points);
    const realArea = convertPixelsToRealUnits(pixelArea, currentScale);
    
    const newArea: TakeoffArea = {
      id: generateId(),
      name: `Area ${completedAreas.length + 1}`,
      points,
      pixelArea,
      realArea,
      unit: 'sq_ft',
      color: generateAreaColor(),
      createdAt: new Date()
    };
    
    setCompletedAreas(prev => [...prev, newArea]);
    saveTakeoffArea(newArea);
  }, [completedAreas, currentScale]);
  
  return { currentPolygon, completedAreas, handlePolygonComplete };
};

// WebSocket real-time collaboration
const wss = new WebSocketServer({
  server,
  perMessageDeflate: {
    zlibDeflateOptions: { windowBits: 13, memLevel: 7 },
    threshold: 1024,
    concurrencyLimit: 10,
  },
  maxPayload: 16 * 1024 * 1024,
  clientTracking: true,
});

// Multi-tenant connection management
wss.on('connection', (ws, request) => {
  const connectionId = uuidv4();
  const url = new URL(request.url, `http://${request.headers.host}`);
  const takeoffId = url.searchParams.get('takeoffId');
  const userId = url.searchParams.get('userId');
  
  connections.set(connectionId, {
    ws, takeoffId, userId,
    lastActivity: Date.now(),
    isAlive: true
  });
});

Area Selection

Polygon-based precise measurements

Symbol Detection

AI-powered plan analysis

Real-time Sync

WebSocket collaboration

Export to Quote

Seamless AI integration

⚡ Event-Driven Background Processing

Inngest Workflow Engine

  • 5-Phase Pipeline: Validation → Generation → Processing → Export → Completion
  • Parallel Processing: 100+ concurrent quote generations
  • Automatic Retries: Exponential backoff with intelligent error handling
  • Real-time Progress: WebSocket updates during processing

Advanced Prompt Engineering

// Template-based prompt system
export const residentialPromptTemplate = (data) => {
  return `
You are an expert construction estimator with 20+ years 
of experience in residential projects.

CRITICAL INSTRUCTIONS:
- Provide detailed, itemized estimates with realistic pricing
- Include labor, materials, equipment, and overhead costs
- Consider regional pricing variations for ${data.location}
- Account for ${data.projectComplexity} complexity level

PROJECT SPECIFICATIONS:
Property Type: ${data.propertyType}
Square Footage: ${data.squareFootage} sq ft
Foundation Type: ${data.foundationType}

GENERATE COMPREHENSIVE QUOTE WITH:
1. EXECUTIVE SUMMARY
2. DETAILED SCOPE OF WORK  
3. ITEMIZED COST BREAKDOWN
4. PROJECT TIMELINE
5. TERMS AND CONDITIONS

FORMAT: Return as structured JSON matching QuoteResponse schema.
PRICING: Use current market rates for ${data.location} region.
ACCURACY: Aim for ±10% estimation accuracy.
`;
};

// Multi-stage generation pipeline
export const validateAndPrepareQuote = inngest.createFunction(
  { id: "quote-validation", retries: 2 },
  { event: "quote/generation.requested" },
  async ({ event, step }) => {
    const quote = await step.run('validate-quote', async () => {
      return await validateQuoteAccess(event.data.quoteId, event.user.id);
    });
    
    await step.run('prepare-context', async () => {
      return await prepareGenerationContext(quote);
    });
  }
);

🚀 Technical Innovation & Performance

Architecture Innovations

AI-First Architecture

Multi-provider AI integration with intelligent routing and automatic failover mechanisms

Real-time Collaboration

Custom WebSocket server with multi-tenant security and sub-50ms latency

Advanced Canvas Tools

React Konva-based drawing tools with precise real-world measurement calculations

Event-Driven Processing

Reliable background job processing with Inngest for 100+ concurrent operations

Performance Metrics

2-5min
Quote Generation
<50ms
WebSocket Latency
99.9%
AI Uptime
60fps
Canvas Performance

Portfolio Value Proposition

BuildVision demonstrates masterclass full-stack development combining cutting-edge AI integration, real-time collaboration, and sophisticated canvas tools. This project showcases advanced concepts in multi-provider AI architecture, WebSocket-based real-time systems, and event-driven processing at enterprise scale.