An open API service indexing awesome lists of open source software.

https://github.com/fabioc-aloha/ai-wallpaper-generator

AI-powered wallpaper generator PWA optimized for iPhone 16 Pro using Azure serverless and Replicate AI
https://github.com/fabioc-aloha/ai-wallpaper-generator

ai azure azure-functions azure-static-web-apps ios iphone iphone-16-pro progressive-web-app pwa replicate serverless sveltekit typescript wallpaper-generator

Last synced: 18 days ago
JSON representation

AI-powered wallpaper generator PWA optimized for iPhone 16 Pro using Azure serverless and Replicate AI

Awesome Lists containing this project

README

          

# AI Wallpaper Generator - Development

This is the scaffolded MVP project using **SvelteKit** (frontend) + **Azure Functions** (backend).

## ๐Ÿ“ Project Structure

```
AlexWallpapers/
โ”œโ”€โ”€ frontend/ # SvelteKit PWA
โ”‚ โ”œโ”€โ”€ src/
โ”‚ โ”‚ โ”œโ”€โ”€ routes/ # Pages (+page.svelte)
โ”‚ โ”‚ โ”œโ”€โ”€ lib/ # Shared utilities & types
โ”‚ โ”‚ โ”œโ”€โ”€ stores/ # Svelte stores (wallpaper cache)
โ”‚ โ”‚ โ”œโ”€โ”€ service-worker.ts # PWA offline support
โ”‚ โ”‚ โ””โ”€โ”€ app.html # HTML template
โ”‚ โ”œโ”€โ”€ static/ # Static assets (icons, favicon)
โ”‚ โ”œโ”€โ”€ vite.config.ts # Vite + PWA config
โ”‚ โ””โ”€โ”€ package.json
โ”œโ”€โ”€ api/ # Azure Functions
โ”‚ โ”œโ”€โ”€ generate/ # POST /api/generate endpoint
โ”‚ โ”œโ”€โ”€ shared/ # Key Vault & Blob Storage utilities
โ”‚ โ”œโ”€โ”€ host.json # Functions runtime config
โ”‚ โ””โ”€โ”€ package.json
โ”œโ”€โ”€ docs/ # Planning documentation
โ”œโ”€โ”€ staticwebapp.config.json # Azure SWA config
โ””โ”€โ”€ README-DEV.md # This file
```

## ๐Ÿš€ Quick Start

### 1. Install Dependencies

```powershell
# Frontend
cd frontend
npm install

# API
cd ../api
npm install
```

### 2. Configure Local Settings

Edit `api/local.settings.json`:
```json
{
"Values": {
"KEY_VAULT_NAME": "your-keyvault-name",
"STORAGE_ACCOUNT_NAME": "your-storage-account",
"STORAGE_CONTAINER_NAME": "wallpapers"
}
}
```

### 3. Run Development Servers

**Terminal 1 - Frontend**:
```powershell
cd frontend
npm run dev
```
Opens at http://localhost:5173

**Terminal 2 - API**:
```powershell
cd api
npm start
```
Runs at http://localhost:7071

### 4. Test on iPhone

1. Get your local IP: `ipconfig` (look for IPv4)
2. Update `frontend/.env.development`:
```
PUBLIC_API_URL=http://YOUR-IP:7071/api
```
3. Open iPhone Safari: `http://YOUR-IP:5173`
4. Add to Home Screen for PWA mode

## ๐Ÿ”ง Development Workflow

### Frontend Development
```powershell
cd frontend
npm run dev # Start dev server
npm run build # Build for production
npm run preview # Preview production build
npm run check # Type checking
```

### API Development
```powershell
cd api
npm start # Start Functions runtime
npm run build # Compile TypeScript
npm run watch # Watch mode for TS
```

## ๐Ÿ“ Key Features Implemented

โœ… **Frontend (SvelteKit)**
- โœ… Text prompt input with validation
- โœ… Generate button with loading state
- โœ… Wallpaper preview & download
- โœ… Recent wallpapers grid (last 10)
- โœ… LocalStorage persistence
- โœ… Offline mode detection
- โœ… Service Worker caching
- โœ… PWA manifest (installable)
- โœ… iPhone-optimized UI (safe areas)

โœ… **Backend (Azure Functions)**
- โœ… POST /api/generate endpoint
- โœ… Zod request validation
- โœ… Replicate API integration (flux-1.1-pro)
- โœ… Key Vault secret retrieval
- โœ… Blob Storage upload
- โœ… Error handling & logging
- โœ… Managed Identity support

โœ… **Infrastructure**
- โœ… TypeScript throughout
- โœ… Environment configuration
- โœ… Static Web App routing
- โœ… CORS & security headers

## ๐Ÿ” Azure Setup Required

Before deploying, you need:

1. **Azure Static Web App** (Free tier)
2. **Azure Functions** Flex Consumption FC1
3. **Storage Account** (Hot tier) with `wallpapers` container
4. **Key Vault** with `REPLICATE-API-KEY` secret
5. **Application Insights** (optional, for telemetry)

See `docs/AZURE-SETUP.md` for step-by-step instructions.

## ๐Ÿงช Testing Checklist

- [ ] Generate wallpaper with simple prompt
- [ ] Download to iPhone Photos
- [ ] Set as wallpaper (lock/home screen)
- [ ] Test offline mode (airplane mode)
- [ ] View cached wallpapers offline
- [ ] Add to Home Screen (PWA install)
- [ ] Test with long prompts (500 chars)
- [ ] Test error handling (network failure)
- [ ] Check iPhone safe area rendering
- [ ] Verify HTTPS in production

## ๐Ÿ“Š Cost Tracking

**MVP Target**: $1.02/month for 200 wallpapers

Current setup:
- Static Web Apps: **Free tier** โœ…
- Functions FC1: ~$0.08/month (200 executions)
- Blob Storage: ~$0.02/month (10 wallpapers)
- Key Vault: ~$0.02/month (secret storage)
- Replicate: ~$0.90/month (200 ร— 20s ร— $0.000225/s)

**Total**: ~$1.02/month

Monitor in Azure Portal โ†’ Cost Management.

## ๐Ÿ› Troubleshooting

**Frontend won't start**:
```powershell
rm -r node_modules, package-lock.json
npm install
```

**API 500 errors**:
- Check `api/local.settings.json` has correct values
- Verify Azure resources exist (Key Vault, Storage)
- Check API key is in Key Vault as `REPLICATE-API-KEY`
- Review Function logs: `http://localhost:7071/admin/functions/generate`

**PWA not installing**:
- Must use HTTPS (production only)
- Check manifest at `/manifest.webmanifest`
- Verify service worker registered (DevTools โ†’ Application)

**iPhone connection issues**:
- Ensure same WiFi network
- Use IP address, not `localhost`
- Check Windows Firewall allows port 5173 & 7071

## ๐Ÿ“š Next Steps

1. โœ… **Week 1**: Complete Azure infrastructure setup
2. โณ **Week 2**: Deploy to Azure Static Web Apps
3. โณ **Week 3**: Test on iPhone, polish UI
4. โณ **Week 4**: Add style templates (optional)

See `docs/DEVELOPMENT-GUIDE.md` for detailed weekly plan.

## ๐ŸŽฏ MVP Scope

This scaffold includes **only** Phase 1 MVP features:
- Generate wallpaper from text prompt
- Download to Photos
- Last 10 wallpapers cached
- Offline viewing
- PWA installable

**Not included** (Phase 2/3):
- User authentication
- Payment system
- Style templates
- Generation history database
- Push notifications

Keep it simple, ship fast! ๐Ÿš€

---

**Ready to start?** Run `npm install` in both `frontend/` and `api/`, then see Quick Start above.