Deployment Guide
This guide covers deploying PocketKit to production using free hosting:
- Frontend (SvelteKit) → Vercel
- Backend (PocketBase) → Fly.io
Both platforms offer generous free tiers perfect for side projects and small applications.
Overview
Section titled “Overview”graph LR
A[GitHub Repository] -->|Auto Deploy| B[Vercel Frontend]
A -->|Auto Deploy| C[Fly.io Backend]
B -->|API Requests| C
C -->|Auth & Data| D[SQLite Database]
style A fill:#333,stroke:#666,color:#fff
style B fill:#000,stroke:#333,color:#fff
style C fill:#7c3aed,stroke:#5b21b6,color:#fff
style D fill:#2563eb,stroke:#1d4ed8,color:#fff
Part 1: Deploy Backend to Fly.io
Section titled “Part 1: Deploy Backend to Fly.io”Install Fly.io CLI
Section titled “Install Fly.io CLI”First, install the Fly.io CLI:
macOS/Linux:
curl -L https://fly.io/install.sh | shWindows:
powershell -Command "iwr https://fly.io/install.ps1 -useb | iex"Sign Up and Login
Section titled “Sign Up and Login”flyctl auth signup # Create account (or use flyctl auth login if you have one)Configure Your App
Section titled “Configure Your App”Update server/fly.toml with your app name:
app = 'your-app-name-server' # Change this to your unique nameprimary_region = 'ams' # Choose region closest to your usersUpdate PocketBase Version
Section titled “Update PocketBase Version”Check the latest PocketBase version at pocketbase.io and update server/Dockerfile:
ARG PB_VERSION=0.36.0 # Update to latest versionLaunch Your App
Section titled “Launch Your App”Navigate to the server directory and launch:
cd serverflyctl launchThis will:
- Read your
fly.tomlconfiguration - Create the app on Fly.io
- Open a browser to review settings
- Ask if you want to deploy now (say No - we need to set up storage first)
Create Persistent Storage
Section titled “Create Persistent Storage”PocketBase needs persistent storage for the SQLite database:
flyctl volumes create pb_data --region ams --size 1This creates a 1GB volume in the Amsterdam region (or your chosen region).
Deploy
Section titled “Deploy”Now deploy your app:
flyctl deployYour backend is now live at https://your-app-name-server.fly.dev
Set Up Admin Account
Section titled “Set Up Admin Account”Create a superuser account to access the PocketBase admin:
flyctl ssh console/pb/pocketbase superuser create admin@example.com yourpasswordOr update an existing one:
flyctl ssh console/pb/pocketbase superuser update admin@example.com newpasswordVerify Backend
Section titled “Verify Backend”Visit your app’s admin panel:
https://your-app-name-server.fly.dev/_Log in with your superuser credentials.
Part 2: Deploy Frontend to Vercel
Section titled “Part 2: Deploy Frontend to Vercel”Install Vercel CLI (Optional)
Section titled “Install Vercel CLI (Optional)”You can deploy via GitHub integration (recommended) or CLI:
yarn global add vercelpnpm add -g vercelnpm i -g vercelConnect to GitHub
Section titled “Connect to GitHub”- Push your code to GitHub (if not already there)
- Go to vercel.com
- Sign up or log in with GitHub
- Click Add New Project
- Import your PocketKit repository
Configure Project
Section titled “Configure Project”When setting up the project:
- Framework Preset: SvelteKit (should be auto-detected)
- Root Directory:
app - Output Directory:
.svelte-kit(default)
Build Command: yarn build (default)
Build Command: pnpm build
Build Command: npm run build (default)
Set Environment Variables
Section titled “Set Environment Variables”Add the following environment variable in Vercel:
Key: PUBLIC_POCKETBASE_URL
Value: https://your-app-name-server.fly.dev
To add this:
- Go to your project settings in Vercel
- Navigate to Environment Variables
- Add
PUBLIC_POCKETBASE_URLwith your Fly.io URL - Make sure it’s set for Production, Preview, and Development
Deploy
Section titled “Deploy”Click Deploy and Vercel will:
- Build your SvelteKit app
- Deploy it globally on their CDN
- Give you a production URL
Your frontend is now live at https://your-app-name.vercel.app
Part 3: Set Up Automatic Deployment
Section titled “Part 3: Set Up Automatic Deployment”Automatic Vercel Deployment
Section titled “Automatic Vercel Deployment”Vercel automatically deploys when you push to your main branch. No additional setup needed!
Automatic Fly.io Deployment
Section titled “Automatic Fly.io Deployment”Set up GitHub Actions to auto-deploy your backend:
1. Get Fly.io Deploy Token
Section titled “1. Get Fly.io Deploy Token”flyctl tokens create deployCopy the token that’s displayed.
2. Add Token to GitHub Secrets
Section titled “2. Add Token to GitHub Secrets”- Go to your GitHub repository
- Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
FLY_API_TOKEN - Value: Paste your token
- Click Add secret
3. Create GitHub Actions Workflow
Section titled “3. Create GitHub Actions Workflow”Create .github/workflows/fly-deploy.yml:
name: Deploy to Fly.io
on: push: branches: - main paths: - 'server/**'
jobs: deploy: name: Deploy PocketBase runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Check for changes id: changes run: | if git diff --quiet HEAD^ HEAD -- server/; then echo "no_changes=true" >> $GITHUB_ENV else echo "no_changes=false" >> $GITHUB_ENV fi
- name: Deploy to Fly.io if: env.no_changes == 'false' run: | cd server flyctl deploy --remote-only -a your-app-name-server env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}Now, when you push changes to the server/ directory, GitHub Actions will automatically deploy to Fly.io.
Deployment Architecture
Section titled “Deployment Architecture”graph TB
Dev[Developer] -->|git push| GH[GitHub]
GH -->|Webhook| V[Vercel]
GH -->|GitHub Action| F[Fly.io]
V -->|Deploy| CDN[Vercel CDN]
F -->|Deploy| VM[Fly.io VM]
VM -->|Persistent| Vol[Volume: pb_data]
Users[End Users] -->|HTTPS| CDN
CDN -->|API Calls| VM
style Dev fill:#10b981,stroke:#059669,color:#fff
style GH fill:#333,stroke:#666,color:#fff
style V fill:#000,stroke:#333,color:#fff
style F fill:#7c3aed,stroke:#5b21b6,color:#fff
style CDN fill:#000,stroke:#333,color:#fff
style VM fill:#7c3aed,stroke:#5b21b6,color:#fff
style Vol fill:#2563eb,stroke:#1d4ed8,color:#fff
style Users fill:#f59e0b,stroke:#d97706,color:#fff
Post-Deployment Checklist
Section titled “Post-Deployment Checklist”After deploying both frontend and backend:
- Visit your Vercel URL and verify the app loads
- Test registration at
/auth/register - Test login at
/auth/login - Verify the backend connection in browser DevTools (Network tab)
- Check PocketBase admin at
your-backend.fly.dev/_ - Verify auto-deployment by making a small change and pushing
Monitoring and Maintenance
Section titled “Monitoring and Maintenance”Fly.io Monitoring
Section titled “Fly.io Monitoring”View logs and monitor your backend:
flyctl logs # View recent logsflyctl status # Check app statusflyctl scale show # View current scalingFly.io Auto-start/Auto-stop
Section titled “Fly.io Auto-start/Auto-stop”The configuration in fly.toml includes:
auto_stop_machines = 'stop'auto_start_machines = truemin_machines_running = 0This means:
- Your app stops when idle (saves resources on free tier)
- Automatically starts when receiving requests
- First request after idle may take a few seconds
Vercel Monitoring
Section titled “Vercel Monitoring”- Go to your project dashboard on Vercel
- View Deployments for deployment history
- Check Analytics for traffic insights
- Monitor Functions for serverless function performance
Scaling Considerations
Section titled “Scaling Considerations”Free Tier Limits
Section titled “Free Tier Limits”Vercel Free Tier:
- 100 GB bandwidth per month
- Unlimited projects
- Automatic SSL
- Global CDN
Fly.io Free Tier:
- 3 shared-cpu-1x VMs
- 3GB persistent storage
- 160GB outbound data transfer
Upgrading
Section titled “Upgrading”As your app grows:
- Vercel: Upgrade to Pro ($20/month) for better analytics and team features
- Fly.io: Scale with
flyctl scale vmor add more regions
Troubleshooting
Section titled “Troubleshooting”Frontend Can’t Connect to Backend
Section titled “Frontend Can’t Connect to Backend”Check these common issues:
- Verify
PUBLIC_POCKETBASE_URLin Vercel environment variables - Ensure the URL starts with
https://(nothttp://) - Make sure there’s no trailing slash:
https://app.fly.dev✅ vshttps://app.fly.dev/❌ - Check CORS settings in PocketBase admin (should allow your Vercel domain)
Fly.io Deployment Fails
Section titled “Fly.io Deployment Fails”Common fixes:
- Ensure you created the persistent volume
- Check
fly.tomlapp name matches your actual app - Verify Dockerfile PocketBase version is valid
- Run
flyctl doctorto diagnose issues
Database Reset After Deployment
Section titled “Database Reset After Deployment”This happens if the persistent volume isn’t mounted correctly:
- Verify volume exists:
flyctl volumes list - Check
fly.tomlmounts configuration matches volume name - Volume must be in the same region as your app
Next Steps
Section titled “Next Steps”Now that your app is deployed:
- Learn about Authentication to customize the auth flow
- Set up custom domains in Vercel and Fly.io
- Configure email settings in PocketBase for password resets
- Add real-time features using PocketBase subscriptions