How cap-go/capgo works
Project Type & Purpose
• Project Type: Full‑stack, multi‑platform app (web SPA, iOS, Android) plus supporting serverless back‑ends.
• Purpose: “Capgo” provides instant over-the-air updates for Capacitor-based mobile apps. It has:
• A Vue3/Vite single‑page web app (also wrapped via Capacitor for mobile)
• Serverless APIs on Cloudflare Workers handling ~99% of traffic
• Supabase (Postgres + Functions + Triggers) for internal cron jobs, data storage, authentication, business logic
• Scripts to manage Stripe billing, S3 assets, migrations
File Structure & Key Components
• Frontend (src/, public/, index.html, Vite config)
• Mobile wrappers (android/, ios/) via Capacitor
• Cloudflare Workers (cloudflare_workers/)
• Supabase backend:
• Functions (supabase/functions/_backend & public)
• Database migrations & triggers (supabase/migrations, tests)
• Deployment workflows (GitHub Actions, Netlify, Fastlane, Codemagic)
• Utility scripts (scripts/) for data sync, billing, deployments
Main Components
a. Client Apps
• Web SPA (Vue3 + Vite + FormKit + Pinia)
• Mobile (Capacitor bridge → iOS / Android native shells)
b. Edge/API Layer
• Cloudflare Workers (REST endpoints for update manifest, file delivery, channels, stats)
c. Core Business Backend
• Supabase Functions & Triggers (CRUD APIs, cron jobs, RLS, business logic, replication)
• Postgres DB (with migrations, RLS policies)
d. External Services
• Stripe (billing, portal)
• AWS S3 / R2 (artifact storage)
• PostHog / Plausible (analytics)
• LogSnag / Discord (notifications)
e. CI/CD & Dev Tools
• GitHub Actions (build, test, bump, deploy)
• Netlify / Cloudflare Pages (web hosting)
• Fastlane / Codemagic (mobile app store deploy)
Relationships & Data Flows
• Clients → Cloudflare Workers (HTTPS requests for manifests, bundle downloads)
• Cloudflare Workers ↔ Supabase Functions (invoke internal APIs for auth, stats, channels)
• Supabase Functions ↔ Postgres DB (read/write via RLS)
• Triggers → Functions (on‑insert/update events drive cron & background processing)
• Billing workflows: Stripe webhooks → Supabase triggers → DB updates
• CI/CD pipelines → deploy front‑end & functions to CF, Netlify, Supabase
Architectural Patterns & Principles
• SPA + PWA on web; wrapped in Capacitor for native mobile
• Serverless microservices (CF Workers for edge/low‑latency API)
• Event‑driven backend (DB triggers + scheduled cron)
• Strict RLS and API surface broken into “public” vs “private” functions
• Infrastructure as Code (wrangler.json, supabase config, GitHub workflows)