· 8 min read
How I built an AI interior design app
I recently moved into a new apartment, and it looked like a hospital waiting room. It had white walls, beige carpet and furniture from three different IKEA trips that somehow didn't match. I kept meaning to fix it but couldn't visualize what "better" actually looked like.
ChatGPT suggested "add some plants and a statement rug." Cool, thanks. That's like telling someone who can't cook to "just add flavor."
I wanted to see what my space could become. So I built a thing.
I wanted the flow to be very simple. You upload a photo of your room, pick a style, and get back three redesigned versions that keep your walls, windows, and doors exactly where they are, without the AI hallucinating extra doorways or removing your ceiling fan.
I built the whole thing in 3 weeks of focused work, using Claude Code to move fast.
Architecture
The backend lives on Railway because Vercel's serverless functions time out at 10 seconds, and AI generation takes 30+.
I went with Cloudflare R2 for storage because it has zero egress fees. S3 would bankrupt me with this many images.
The schema changed every week during development, and SQL migrations would've killed momentum, so MongoDB is a good fit.
User flow
The hard part was the photos people upload
I thought the hard part would be AI prompting, but it was dealing with whatever garbage users upload.
Someone sends you a 25MB HEIC file from their iPhone 15 Pro Max. Gemini doesn't know what to do with it, your bandwidth bill cries, and the request times out.
The fix:
1. Detect format from data URL
2. If it's HEIC/HEIF, convert to JPEG using heic-convert
3. Resize to max 4096x4096 (Gemini's limit)
4. Compress with mozjpeg at 92% quality
5. Result: 15MB down to 400KB
Storage costs dropped 90% and the timeouts stopped.
Three-stage AI pipeline
Every upload goes through three stages before Gemini generates anything.
Stage 1: validation
Gemini 2.0 Flash checks whether the photo is actually a room. If confidence is below 60%, the upload gets rejected, since there's no point burning API credits on someone's photo of their dog.
Stage 2: analysis
Next, the app works out what the space looks like:
-
Room type and dimensions
-
Structural elements (doors, windows, beams)
-
Current style assessment
-
Three recommended styles that would work
This context feeds into generation and lets me explain why certain styles were recommended.
Stage 3: generation
Gemini 2.5 Flash Image Preview does the actual generation, and the prompt structure matters:
Transform this [room_type] into [style] style.
CRITICAL: Keep ALL doors, windows, walls EXACTLY where they are.
DO NOT move, add, or remove structural elements.
Maintain 60-90cm walking space between furniture.
Style: [name]
Colors: [palette]
Materials: [list]
Key elements: [list]
[custom user instructions if any]
The three variations run in parallel with Promise.all(). If one fails, the others still complete.
21 design styles
Each style is a full configuration, like this one:
{
name: 'Japandi',
description: 'Japanese minimalism meets Scandinavian comfort',
colorPalette: ['#F5F2ED', '#D4C4B0', '#8B7355', '#2F2F2F', '#FFFFFF'],
keyElements: ['Low furniture', 'Natural textures', 'Minimal decor', 'Zen elements'],
materials: ['Bamboo', 'Rice paper', 'Natural linen', 'Light oak'],
lighting: 'Soft, diffused lighting with paper lanterns',
mood: 'Tranquil, balanced, and mindfully curated'
}
The AI uses all of this context. Styles get picked like this:
-
If the user picked a style, use that first and add 2 complementary styles
-
In reshuffle mode, pick randomly from all 21
-
With no preference, use the AI-recommended styles from the analysis step
Styles include: Modern Contemporary, Scandinavian, Industrial Chic, Luxury Modern, Mid-Century Modern, Japandi, Coastal Modern, Bohemian Luxe, Minimalist, Traditional Classic, Rustic Farmhouse, Art Deco, Mediterranean, Contemporary Eclectic, French Country, Urban Modern, Transitional, Tropical Paradise, Hollywood Glam, Nordic Minimalism, and a custom option.
Uploading to R2 without the AWS SDK
Cloudflare R2 is S3-compatible, but I didn't want the entire AWS SDK for something this simple, so I implemented AWS Signature V4 signing by hand:
1. Build canonical request (method, path, headers, payload hash)
2. Create string to sign (algorithm, timestamp, scope, request hash)
3. Generate signing key (HMAC chain: secret, then date, region and service)
4. Sign the string
5. PUT request with Authorization header
Each image gets uploaded twice, in parallel: WebP as the primary and PNG as the fallback. Public URLs go straight to Cloudflare's CDN with 1-year cache headers.
The credit system
There are three tiers:
-
Free: 5 generations per day (resets at midnight)
-
Starter: 25 one-time credits ($9.99), never expire
-
Pro: 60 per month with rollover ($19.99/month)
The tricky part is deciding which credits get used first when someone has purchased credits and a Pro subscription:
Priority order:
1. Bonus credits (admin gifts, promo codes) - use first, they're free
2. Monthly subscription allowance - expires end of month, use before they vanish
3. Purchased credits - paid real money, preserve as long as possible
Credits get deducted after a successful generation, so nobody gets charged for a failed request.
Promo codes
I built a simple promo system for marketing and customer support:
PromoCode {
code: "LAUNCH50"
credits: 10
maxRedemptions: 100
currentRedemptions: 0
expiresAt: Date
redeemedBy: [userId, ...] // prevent double redemption
}
When someone redeems a code, credits go into the promoRedeemedCredits bucket. They're tracked separately so I can see which codes are actually driving usage.
Plan upgrades
When a Starter user upgrades to Pro, their purchased credits become backup credits that kick in after the monthly allowance runs out, so users keep what they paid for.
Regional pricing
Not everyone pays in USD, so the system detects the user's region through:
1. CloudFlare headers (fast, usually accurate)
2. Client-provided timezone
3. IP geolocation APIs as fallback (ipapi.co, ip-api.com, ipinfo.io)
India gets INR pricing (₹599 for Starter, ₹999/month for Pro). US gets USD ($9.99, $19.99). DodoPayments handles the currency conversion.
To prevent VPN abuse, there's a security check that the payment amount matches the expected regional price within a 5% tolerance.
Payment flow
Soft delete and storage management
I can't keep every generated image forever, but deleting immediately makes users angry. So deletes are soft, with a 3-day grace period:
User clicks delete, which sets isDeleted = true, deletedAt = now
Cron job runs every 6 hours:
- Find images where isDeleted = true AND deletedAt < 3 days ago
- Delete from R2
- Remove from database
Exception: "liked" images skip deletion entirely
This nudges users to curate their favorites while keeping storage costs sane.
Likes and favorites
The "like" button is tied directly to storage policy.
GeneratedImage {
isLiked: false // user clicked heart
isPinned: false // saved to moodboard
isDeleted: false // soft deleted
expiresAt: Date // null if liked or pinned
}
Liked images:
-
Never auto-delete
-
Show up in "Favorites" tab on dashboard
-
Can be added to moodboards
Unliked images:
-
Get
expiresAtset to 3 days from creation -
Cron job cleans them up
-
Warning shown: "Like to keep forever"
Moodboards
Users can organize designs into collections, which is handy for planning a full home renovation or comparing styles.
Moodboard {
userId
name: "Living Room Ideas"
description: optional
isPublic: false // shareable link if true
items: [MoodboardItem, ...]
}
MoodboardItem {
moodboardId
imageId // ref to GeneratedImage
position: { x, y } // for drag-drop layout
notes: optional
}
When an image is added to a moodboard, isPinned gets set to true. Pinned images never expire, even if not liked.
Shareable moodboards have a public URL you can send to partners, designers, or contractors.
Admin panel
I needed visibility without diving into MongoDB Compass every time something broke, so I built a protected /admin route with these parts.
User lookup
-
Search by email
-
View their generated images
-
See plan, credits, usage stats
-
Gift credits manually (for bug compensation)
Analytics dashboard
-
Generations today/week/month
-
Error rate (goal: < 5%)
-
New signups
-
Revenue (from DodoPayments webhooks)
-
Most popular styles
Error monitoring
-
Real-time error log (auto-refreshes every 30s)
-
Filter by error code (403, 429, 500)
-
Color-coded severity
-
Direct links to user profiles for debugging
Content moderation
-
View all generated images
-
Flag/delete inappropriate content
-
Ban users if needed
Promo code management
-
Create new codes
-
Set redemption limits
-
Track which codes are performing
The admin check is simple:
user.isAdmin === true // set manually in DB for now
The role system is a single boolean for now, and if I need more granularity later I'll add it.
Gemini falls over under load, so everything retries
Gemini returns 503s and 429s under load, so instead of failing immediately, requests retry with backoff:
for attempt 1 to 3:
try:
return gemini.generate(prompt, image)
catch error:
if error is 503 or 429:
wait (2^attempt) seconds # 1s, 2s, 4s
continue
else:
throw error
User-facing errors get translated:
-
SAFETYshows "Image flagged by content filter" -
quotashows "High demand, try again in a few minutes" -
anything else shows "Something went wrong. Credits not charged."
Custom furniture
Users can upload photos of furniture they own (or want to buy) and have it incorporated into the design.
content = [
{ text: main_prompt },
{ image: room_photo }
]
for each furniture_photo:
content.append({ image: furniture_photo })
content[0].text += "Incorporate furniture from image N into the design"
gemini.generate(content)
It doesn't need fine-tuning, since Gemini's multimodal context window handles reference images directly.
Payment webhooks sometimes arrive twice
Payment webhooks can be retried, so DodoPayments might send the same event twice.
on webhook received:
event_id = webhook.id
if Payment.exists(webhook_events contains event_id):
return "already processed"
process payment
Payment.webhook_events.push(event_id)
This idempotency check keeps users from getting credited twice.
Console easter eggs
I added these because why not. Open dev tools and you'll find:
-
ASCII art cat welcome message
-
roomcraft.meow()plays an actual meow sound (base64 encoded audio) -
roomcraft.designTip()returns real interior design advice like "Use the 60-30-10 color rule" or "Place mirrors opposite windows to bounce light" -
roomcraft.showStyles()lists all 21 design styles -
roomcraft.surprise()random fun facts
The Konami code (up up down down left right left right B A) triggers:
-
Rainbow hue-rotation effect on the whole page
-
50 confetti particles falling with rotation animation
-
Console message: "You're awesome!"
There's also a hidden promo code (CURIOUS_CAT) for people curious enough to check the console.
What I'd do differently
I'd start with rate limiting. I added it after a surge of requests blew through my API quota, and it should've been there from day one.
I'd test with real iPhone photos earlier. HEIC handling started as an afterthought and ended up as a core part of the upload pipeline.
I'd build the admin panel sooner. I was digging through MongoDB Compass for way too long. A simple dashboard to view generations, gift credits, and check error rates would've saved hours.
How long a generation takes
How long one generation takes, stage by stage:
| Stage | Duration |
|---|---|
| Upload & format conversion | 1-2s |
| Room validation (Gemini) | 2-3s |
| Room analysis | 3-4s |
| Generate 3 designs (parallel) | 15-20s |
| Upload to R2 | 3-5s |
| Save to MongoDB | 1-2s |
| Total | 25-36s |
After a month of running:
-
Success rate: 94% (up from 71% before retry logic)
-
Storage per user: ~12MB (down from ~180MB before optimization)
-
Most popular style: Modern Contemporary (32%)
-
R2 vs S3 savings: ~$500/month on egress fees
The app works and people use it. I can finally see what my apartment could look like with furniture that matches.
Built by Koushith Amin. The code is messier than this post suggests. Used LLMs for grammar, typos etc.