DEV Community

Cover image for A Background-remover application finished by Ai
hui sun
hui sun

Posted on

A Background-remover application finished by Ai

I Built a Free AI Background Remover Using Cloudflare Workers + D1

I spent my weekend building an AI background remover website, with both frontend and backend deployed on Cloudflare, costing almost nothing. Here's my development journey and some lessons learned.

🌟 Project URL

https://zmjjkk.xyz

🔧 Tech Stack

  • Frontend: Static HTML + JavaScript (Cloudflare Pages)
  • Backend: Cloudflare Workers
  • Database: Cloudflare D1
  • AI Background Removal: Remove.bg API
  • Payment: PayPal

🚀 Features

  1. Free to Use: 3 free uses per day, no login required
  2. Google Login: Cross-device sync after login
  3. Credit Packs: Purchase credits via PayPal
  4. Membership: Monthly/Yearly unlimited plans

💡 Key Highlights

1. Benefits of D1 Database

Previously I used localStorage, so users would lose their data when switching devices. After switching to D1, once a user logs in, their credits and membership sync across all devices.

-- User table structure
CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  google_id TEXT UNIQUE,
  email TEXT,
  credits INTEGER DEFAULT 0,
  membership TEXT,
  membership_expire TEXT,
  total_used INTEGER DEFAULT 0
);
Enter fullscreen mode Exit fullscreen mode

2. Interesting Uses of Workers

Workers aren't just for APIs - they can also serve HTML pages directly. One Worker handles all routes:

// Home page
if (path === '/') {
  return new Response(HOME_PAGE, {
    headers: { 'Content-Type': 'text/html' }
  })
}

// Pricing page
if (path === '/pro') {
  return new Response(PRO_PAGE, {...})
}

// API endpoint
if (path === '/purchase' && method === 'POST') {
  return handlePurchase(request, env)
}
Enter fullscreen mode Exit fullscreen mode

3. PayPal Integration Lessons

Sandbox and production have different API addresses, and sandbox testing sometimes has weird CORS issues. The final solution was to provide a manual payment confirmation as a fallback, in case the automatic flow fails after user pays.

📊 Cost Estimate

Service Free Tier Overage
Workers 100,000 req/day $0.50/million
D1 5GB storage $1/GB/month
Pages 500MB Free
Remove.bg - $0.07/image

Currently with a few hundred visits per day, everything is within the free tier.

🔜 Future Plans

  • [ ] Add more AI features (background replacement, resize)
  • [ ] Batch processing support
  • [ ] Open API for developers

🤔 Reflection

This project made me rethink Cloudflare's product capabilities. The Workers + D1 + Pages combo is amazing for small to medium web applications - easy deployment, global CDN, and extremely low cost.

If you have similar ideas, try this stack! Feel free to ask questions in the comments!


Feel free to try https://zmjjkk.xyz and leave your feedback in the comments!

Top comments (0)