This project now ships both the React client and a shared /api/analyze endpoint so we can call Gemini, GPT‑4o, and future providers without exposing API keys in the browser.
Originally, this project was prototyped in Google AI Studio before being moved into this standalone repository and deployment flow.
Prerequisites: Node.js 18+, Vercel CLI (or another way to serve /api/* functions).
- Install dependencies
npm install - Copy the sample env file and fill in the keys you plan to use
cp .env.local.example .env.local - When developing locally run both the Vercel dev server (for API routes) and the Vite client:
The default
vercel dev # serves /api/analyze on http://localhost:3000 npm run dev # serves the React app on http://localhost:5173
.env.local.examplealready pointsVITE_ANALYZE_URLathttp://localhost:3000/api/analyze. Overwrite this variable if your API lives elsewhere.
| Variable | Used by | Notes |
|---|---|---|
VITE_ANALYZE_URL |
Client | Optional. Defaults to /api/analyze in production. Set when the frontend should talk to a remote API instance. |
OPENROUTER_API_KEY |
Server | Required. We proxy every request through OpenRouter and expose only its curated model list in the UI. |
APPLE_IAP_ISSUER_ID |
Server | App Store Connect API Issuer ID (needed for receipt validation). |
APPLE_IAP_KEY_ID |
Server | Key ID associated with the App Store Server API private key. |
APPLE_IAP_PRIVATE_KEY |
Server | Contents of the .p8 private key used to call the App Store Server API. |
VITE_SUPABASE_URL / SUPABASE_URL |
Client/Server | Supabase project URL for the browser and serverless envs. |
VITE_SUPABASE_PUBLISHABLE_KEY |
Client | Publishable key for Supabase Auth (magic links). |
SUPABASE_SERVICE_ROLE_KEY |
Server | Service key used in API routes to send magic links and log throttling events. Keep server-side only. |
APP_BASE_URL |
Server | Redirect target for Supabase magic links. Must include the scheme, e.g., https://wecircle-assistent.vercel.app. |
RATE_LIMIT_SALT |
Server | Secret salt used when hashing IPs for throttling login requests. |
Deployments on Vercel should configure these vars in the project settings so that /api/analyze can authenticate to OpenRouter at runtime.
- Install the Supabase CLI and authenticate once:
npm install -g supabase && supabase login - Link the CLI to your project (replace
abcd1234with your project ref from the Supabase dashboard):
supabase link --project-ref abcd1234 - Apply the checked-in schema:
supabase db push
This executessupabase/migrations/20260204T000000_initial_product_schema.sql, which provisions:profiles,user_settings, anduser_plan_assignmentslinked toauth.usersbilling_plansplususage_countersfor future tier/limit enforcementauth_throttleplus indexes for rate-limiting the magic-link endpoint- RLS policies and triggers that keep
updated_atautomatically in sync.
- In the Supabase Dashboard → Authentication, enable Email (Magic Link) and add production/staging URLs in “Redirect URLs”. Optionally customize the email template for the brand.
- Set
SUPABASE_URL,SUPABASE_SERVICE_ROLE_KEY,VITE_SUPABASE_URL, andVITE_SUPABASE_PUBLISHABLE_KEYin.env.localand in Vercel project settings. - Users can now request a magic link on the login screen; the
/api/auth/send-magic-linkroute enforces per-email and per-IP throttling backed by theauth_throttletable before calling Supabase Auth. If you get redirected back to the login screen, double-check thatAPP_BASE_URLand the Supabase Site URL are set to the same production domain so the session can be exchanged correctly.
flowchart TD
U["User (iPhone browser)"] --> FE["React App (Vite, App.tsx)"]
FE --> IDX["IndexedDB (local item cache)"]
FE --> APIA["/api/analyze"]
FE --> APIL["/api/auth/send-magic-link"]
FE --> SB["Supabase (publishable key client)"]
APIA --> OR["OpenRouter / LLM providers"]
APIL --> SVC["Supabase service-role client"]
SVC --> SBAUTH["Supabase Auth + auth_throttle"]
SB --> SBAUTH
SB --> SBTBL["Supabase Postgres tables"]
SBTBL --> PRO["profiles / user_settings / user_plan_assignments"]
SBTBL --> ITEMS["user_items (shared item history)"]
SBTBL --> AUD["audit_events"]
FE --> SYNC["Item sync queue (localStorage)"]
SYNC --> SB
Notes:
user_settingsanduser_itemsare keyed byuser_id, so the same login shares data across browsers/devices.- IndexedDB remains local-first for responsiveness; background sync and retry queue make remote writes fault tolerant.
audit_eventscaptures item lifecycle and auth lifecycle events for traceability.
Before pushing or deploying, run the checks that Vercel also executes during npm run vercel-build:
npm run lint– ESLint (TypeScript + React rules) with warnings treated as failures.npm run test– Vitest in CI mode (runs the suite with JSDOM).npm run typecheck– Ensures the TypeScript project compiles withtsc --noEmit.
Vercel reads vercel.json and executes npm run vercel-build, which chains the three commands above before vite build. Any failing step stops the deployment.
This repo now includes a git pre-push hook at .githooks/pre-push that runs npm run vercel-build before pushes, so lint/test/typecheck/build failures are caught locally first.