Installation Guide
Installation Guide
Section titled “Installation Guide”This guide walks you through setting up ImageBot for local development and production deployment.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure you have:
- Node.js 18 or higher
- npm or yarn package manager
- Cloudflare Account (free tier works)
- Git for version control
Step 1: Clone Repository
Section titled “Step 1: Clone Repository”git clone https://github.com/your-org/imagebot.gitcd imagebotStep 2: Install Dependencies
Section titled “Step 2: Install Dependencies”npm installThis installs all required packages including:
- Astro frontend framework
- React for UI components
- Cloudflare Workers for backend
- Database and storage clients
Step 3: Cloudflare Setup
Section titled “Step 3: Cloudflare Setup”Install Wrangler CLI
Section titled “Install Wrangler CLI”npm install -g wranglerLogin to Cloudflare
Section titled “Login to Cloudflare”wrangler loginThis opens your browser for authentication.
Create D1 Database
Section titled “Create D1 Database”wrangler d1 create imagebot-dbImportant: Copy the database_id from the output.
Create R2 Bucket
Section titled “Create R2 Bucket”wrangler r2 bucket create imagebot-imagesStep 4: Configuration
Section titled “Step 4: Configuration”Update wrangler.toml
Section titled “Update wrangler.toml”Edit wrangler.toml and add your database ID:
[[d1_databases]]binding = "DB"database_name = "imagebot-db"database_id = "your-database-id-here" # ← Add your ID here
[[r2_buckets]]binding = "IMAGES"bucket_name = "imagebot-images"Set Environment Secrets
Section titled “Set Environment Secrets”# JWT Secret (generate a strong random string)wrangler secret put JWT_SECRET
# Stripe Keys (optional, for payments)wrangler secret put STRIPE_SECRET_KEYwrangler secret put STRIPE_WEBHOOK_SECRET
# Email Service (optional)wrangler secret put MAILERSEND_API_TOKEN
# GitHub OAuth (optional)wrangler secret put GITHUB_CLIENT_SECRETGenerate JWT Secret:
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"Create .env File
Section titled “Create .env File”cp .env.example .envEdit .env:
PUBLIC_API_URL=http://localhost:8787Step 5: Database Migration
Section titled “Step 5: Database Migration”Apply all database schemas:
# Core schemawrangler d1 execute imagebot-db --remote --file database/schema-init.sql
# Feature schemaswrangler d1 execute imagebot-db --remote --file database/license-certificates-schema.sqlwrangler d1 execute imagebot-db --remote --file database/multi-model-comparison-schema.sqlwrangler d1 execute imagebot-db --remote --file database/api-keys-schema.sqlwrangler d1 execute imagebot-db --remote --file database/teams-minimal.sqlwrangler d1 execute imagebot-db --remote --file database/batch-schema.sqlwrangler d1 execute imagebot-db --remote --file database/branding-schema.sqlwrangler d1 execute imagebot-db --remote --file database/prompt-packs-schema.sqlVerify database:
wrangler d1 execute imagebot-db --remote --command "SELECT COUNT(*) as table_count FROM sqlite_master WHERE type='table'"You should see 41+ tables.
Step 6: Local Development
Section titled “Step 6: Local Development”Start Frontend Dev Server
Section titled “Start Frontend Dev Server”# Terminal 1npm run devAccess at: http://localhost:4321
Start Worker Dev Server
Section titled “Start Worker Dev Server”# Terminal 2npm run worker:devWorker runs at: http://localhost:8787
Step 7: Verify Setup
Section titled “Step 7: Verify Setup”- Open
http://localhost:4321 - Click “Register” to create an account
- Try generating an image
- Check that it appears in the Gallery
Troubleshooting
Section titled “Troubleshooting”Database Connection Errors
Section titled “Database Connection Errors”# Check database existswrangler d1 list
# Verify binding in wrangler.tomlcat wrangler.toml | grep database_idWorker Deployment Issues
Section titled “Worker Deployment Issues”# Check Wrangler versionwrangler --version
# Clear cacherm -rf .wranglernpm run worker:devPort Already in Use
Section titled “Port Already in Use”# Kill process on port 4321kill $(lsof -t -i:4321)
# Or use different portnpm run dev -- --port 3000R2 Bucket Access
Section titled “R2 Bucket Access”# List bucketswrangler r2 bucket list
# Test uploadecho "test" > test.txtwrangler r2 object put imagebot-images/test.txt --file=test.txtProduction Deployment
Section titled “Production Deployment”See Deployment Guide for production setup.
Next Steps
Section titled “Next Steps”Additional Resources
Section titled “Additional Resources”Getting Help
Section titled “Getting Help”If you encounter issues:
- Check Troubleshooting
- Search GitHub Issues
- Join Discord Community
- Email: support@imagebot.com