🏠 AI Floor Plan Generator

House Floor Plan Generator

Enter your plot size, rooms, and entrance direction — get an instant 2D floor plan with optional Vastu Shastra compliance.

📐 Plot & Room Details
🧿
Apply Vastu Shastra
Align rooms as per Vastu principles
Vastu Rules Applied: Kitchen → South-East · Master Bedroom → South-West · Living Room → North/East · Bathrooms → West/North-West · Parking → North/East · Entrance on selected facing side.
🏗️ AI is designing your floor plan…
🏠 Generated Floor Plan
⚙️ How It Works
1

Enter Details

Plot size, rooms, entrance direction and Vastu preference

2

AI Designs

AI architect places rooms following civil engineering principles

3

Get SVG Plan

Download or print your 2D floor plan with room labels & dimensions

❓ Frequently Asked Questions
Is this Vastu floor plan accurate?
This tool applies standard Vastu Shastra rules: kitchen in South-East (Agni corner), master bedroom in South-West, living room in North/East, bathrooms in West/North-West. It provides a practical starting point — always verify with a professional Vastu consultant before construction.
What plot sizes are supported?
Supports Indian residential plots from 10×10 ft to 200×300 ft. Common sizes like 20×30, 30×40, 30×50, 40×60, 50×80 ft are all well-supported with realistic room layouts.
Can I use this plan for actual construction?
This is an AI-generated conceptual layout for visualization and planning purposes. For actual construction, the plan must be reviewed and approved by a licensed architect and structural engineer as per local municipal bye-laws.
Why is entrance direction important in Vastu?
In Vastu Shastra, North and East facing entrances are considered most auspicious as they allow morning sunlight and positive energy. South and West facing entrances require additional Vastu remedies for balance.
`; } // ─── API call & orchestration ────────────────────────────────────────────── async function generatePlan() { const p=getParams(); lastParams=p; if (+p.width<10||+p.length<10){alert('Please enter valid plot dimensions (minimum 10 ft).');return;} const btn=document.getElementById('generateBtn'); const spinner=document.getElementById('spinner'); const btnText=document.getElementById('btnText'); const progressArea=document.getElementById('progressArea'); const outputCard=document.getElementById('outputCard'); btn.disabled=true; spinner.style.display='block'; btnText.textContent='Generating…'; progressArea.style.display='block'; outputCard.style.display='none'; const msgs=[ '🏗️ AI architect is laying out your rooms…', '📐 Calculating positions and dimensions…', '🧿 Applying Vastu Shastra rules…', '🚪 Placing doors and connectivity…', '📊 Computing room areas…', '✅ Finalising JSON layout…', ]; let mi=0; const t=setInterval(()=>{mi=(mi+1)%msgs.length;document.getElementById('progressText').textContent=msgs[mi];},2500); try { const res=await fetch('/api/groq-proxy',{ method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({messages:[{role:'user',content:buildPrompt(p)}],model:'smart',maxTokens:3000}), }); if(!res.ok){const e=await res.json().catch(()=>({}));throw new Error(e.error||'Proxy error '+res.status);} const data=await res.json(); const raw=data.content||''; if(!raw) throw new Error('Empty response from AI'); const jsonData=extractJSON(raw); if(!jsonData.rooms||!jsonData.rooms.length) throw new Error('AI returned no rooms in JSON'); const html=renderFromJSON(jsonData,p); lastGeneratedHtml=html; renderPlan(html,p); } catch(e) { console.error('Floor plan error:',e); alert('Floor plan generation failed:\n'+e.message); progressArea.style.display='none'; } finally { clearInterval(t); btn.disabled=false; spinner.style.display='none'; btnText.textContent='✨ Generate Floor Plan'; } } function renderPlan(html,p) { const frame=document.getElementById('planFrame'); const outputCard=document.getElementById('outputCard'); const progressArea=document.getElementById('progressArea'); document.getElementById('planTitle').textContent=p.vastu==='Yes' ?`Vastu Floor Plan — ${p.width}×${p.length} ft, ${p.bedrooms} BHK` :`Generated Floor Plan — ${p.width}×${p.length} ft, ${p.bedrooms} BHK`; frame.srcdoc=html; frame.onload=()=>{try{const h=frame.contentDocument?.documentElement?.scrollHeight;if(h>200)frame.style.minHeight=h+'px';}catch{}}; progressArea.style.display='none'; outputCard.style.display='block'; outputCard.scrollIntoView({behavior:'smooth',block:'start'}); } function regenerate(){generatePlan();} function downloadPlan(){ if(!lastGeneratedHtml)return; const blob=new Blob([lastGeneratedHtml],{type:'text/html'}); const url=URL.createObjectURL(blob); const a=document.createElement('a'); a.href=url; a.download=`floor-plan-${lastParams.width}x${lastParams.length}-${lastParams.bedrooms}bhk${lastParams.vastu==='Yes'?'-vastu':''}.html`; a.click(); URL.revokeObjectURL(url); } function printPlan(){ const frame=document.getElementById('planFrame'); try{frame.contentWindow.print();} catch{const w=window.open('','_blank');w.document.write(lastGeneratedHtml);w.document.close();w.print();} } // ─── Prompt builder (requests JSON from AI) ──────────────────────────────── function buildPrompt(p) { const dir = p.direction; const W = +p.width, L = +p.length; const minArea = Math.floor(W * L * 0.90); // Coordinate orientation const dirCoord = {North:'top (y=0)', South:'bottom (y='+L+')', East:'right (x='+W+')', West:'left (x=0)'}; // Build ONLY the rooms the user requested — strict conditional const rooms = []; if (p.living === 'Yes') rooms.push(`- Living Room : min 12×14 ft`); if (p.kitchen === 'Yes') rooms.push(`- Kitchen : min 8×10 ft`); for (let i = 0; i < +p.bedrooms; i++) rooms.push(`- ${i===0?'Master Bedroom':'Bedroom '+(i+1)} : min ${i===0?'12×14':'10×12'} ft`); for (let i = 0; i < +p.bathrooms; i++) rooms.push(`- Bathroom ${i+1} : min 4×6 ft`); if (p.parking === 'Yes') rooms.push(`- Parking : min 9×18 ft`); rooms.push(`- Passage/Lobby : 3–4 ft wide corridor`); // Strict exclusion warnings const exclusions = []; if (p.parking !== 'Yes') exclusions.push('DO NOT include Parking or reserve any space for it'); if (p.kitchen !== 'Yes') exclusions.push('DO NOT include Kitchen'); if (p.living !== 'Yes') exclusions.push('DO NOT include Living Room'); // Vastu zone instructions const vastuBlock = p.vastu === 'Yes' ? ` VASTU RULES (MANDATORY — Vastu = Yes): Origin (0,0) = North-West corner. X increases East, Y increases South. Zone reference for ${W}×${L} ft plot: North zone : y < ${Math.round(L*0.33)} ft South zone : y > ${Math.round(L*0.67)} ft East zone : x > ${Math.round(W*0.60)} ft West zone : x < ${Math.round(W*0.40)} ft Placement rules: Kitchen → South-East (x≥${Math.round(W*0.55)}, y≥${Math.round(L*0.55)}) Master Bed → South-West (x≤${Math.round(W*0.45)}, y≥${Math.round(L*0.55)}) Living Room → ${dir==='North'||dir==='East'?'North or East zone (near entrance)':'near entrance on '+dir+' side'} Bathrooms → West or North-West (x≤${Math.round(W*0.40)}) — NEVER North-East Parking → ${dir} side (near entrance) Passage → central spine` : ` LAYOUT STYLE: Modern practical — no Vastu constraints. Maximise natural light and logical flow.`; return `You are a senior civil engineer designing a real house. Return ONLY valid JSON — no explanation, no markdown, no text outside JSON. ═══════════════════════════════ PLOT: ${W} ft wide (X) × ${L} ft tall (Y) ENTRANCE: ${dir} facing — main door on ${dirCoord[dir]} wall VASTU: ${p.vastu} TARGET BUILT-UP AREA: ≥ ${minArea} sq ft (90% of ${W*L} sq ft plot) ═══════════════════════════════ ROOMS TO INCLUDE (EXACTLY THESE — NO MORE, NO LESS): ${rooms.join('\n')} ${exclusions.length ? '🚫 STRICT EXCLUSIONS:\n' + exclusions.map(e=>' ✗ '+e).join('\n') : ''} ${vastuBlock} ═══════════════════════════════ LAYOUT RULES (ALL MANDATORY): 1. Every room: 0 ≤ x ≤ ${W}, 0 ≤ y ≤ ${L}, x+width ≤ ${W}, y+height ≤ ${L} 2. Zero overlaps — rooms share walls, not space 3. No floating rooms — every room must touch at least one other room or plot boundary 4. No large empty gaps — use every sq ft efficiently 5. Entrance → Living Room (must be adjacent) ${p.living==='Yes'?'':'— no Living Room, entrance leads to passage'} 6. Bedrooms accessible from passage or living room 7. Each room needs ≥ 1 door (coordinates on the room wall, not interior) 8. Each outer-wall room needs ≥ 1 window DOOR COORDINATE RULES (absolute feet, not relative): Top wall door: y = room.y exactly, x = somewhere along room top wall Bottom wall door: y = room.y + room.height, x = somewhere along room bottom wall Left wall door: x = room.x exactly, y = somewhere along room left wall Right wall door: x = room.x + room.width, y = somewhere along room right wall WINDOW COORDINATE RULES: { "x": number, "y": number, "width": windowWidthFt } Only on outer plot walls: y=0, y=${L}, x=0, or x=${W} ═══════════════════════════════ RETURN THIS JSON SCHEMA EXACTLY: { "plot": { "width": ${W}, "length": ${L} }, "rooms": [ { "name": "Living Room", "x": 0, "y": 0, "width": 16, "height": 18, "doors": [{ "x": 7, "y": 0 }], "windows": [{ "x": 2, "y": 0, "width": 4 }] } ] } Output starts with { and ends with }. Absolutely nothing else.`; }