Path B quickstart
Path B is the full stack route. It uses:
- Hono on Cloudflare Workers (
backend/src/index.ts) - better-auth (
backend/src/auth.ts) - D1 + Drizzle (
backend/src/db/) - optional AI providers behind
/api/ai/chat - Alchemy or Wrangler for deployment
What you get
Section titled “What you get”- Auth: better-auth catch-all routes + custom Apple sign-in endpoint
- Backend: Hono on Cloudflare Workers
- Database: Cloudflare D1 (SQLite) via Drizzle ORM
- Rate limiting: middleware on
/api/ai/*that usesRATE_LIMIT_KVwhen bound and falls back to in-memory counters otherwise - AI proxy: Multi-provider chat with streaming SSE
- Deploy: Wrangler (
npm run deploy) or Alchemy (npm run alchemy:deploy)
1. Start the backend
Section titled “1. Start the backend”cd backendnpm installnpm run devThis starts a local Cloudflare Workers dev server on http://localhost:8787.
2. Verify the backend
Section titled “2. Verify the backend”curl http://localhost:8787/healthzYou should see:
{ "status": "ok", "environment": "development", "timestamp": "..." }3. Generate and open the iOS project
Section titled “3. Generate and open the iOS project”cd iosxcodegen generate --spec project.ymlopen SwiftLaunch.xcodeproj4. Configure the deployment path
Section titled “4. Configure the deployment path”AppConfig.current resolves deployment path at runtime.
To force Path B in local development, set the environment variable in your Xcode scheme:
SWIFTLAUNCH_DEPLOYMENT_PATH=fullStackThat value is read by AppConfig.runtime() in:
ios/SwiftLaunch/Core/Config/AppConfig.swift
Development apiBaseURL defaults to http://localhost:8787, matching wrangler dev.
5. Run
Section titled “5. Run”Select an iOS 17+ simulator and hit Cmd+R. The app connects to your local backend for auth, chat, and API calls.
Backend architecture
Section titled “Backend architecture”backend/├── src/│ ├── index.ts # Route mounts and middleware│ ├── auth.ts # better-auth setup│ ├── routes/│ │ ├── auth.ts│ │ ├── ai-proxy.ts│ │ ├── chat.ts│ │ ├── api.ts│ │ ├── profile.ts│ │ ├── settings.ts│ │ └── feedback.ts│ ├── middleware/│ │ ├── auth.ts│ │ └── rate-limit.ts│ ├── services/│ │ ├── ai-proxy.ts│ │ ├── chat-store.ts│ │ ├── users-store.ts│ │ └── providers/│ └── db/│ ├── schema.ts│ ├── client.ts│ └── repositories/├── migrations/├── wrangler.toml├── alchemy.config.ts└── alchemy.run.tsSet secrets
Section titled “Set secrets”For local development, add secrets to a .dev.vars file in backend/:
BETTER_AUTH_SECRET=your-secret-hereOPENAI_API_KEY=sk-...ANTHROPIC_API_KEY=sk-ant-...GEMINI_API_KEY=AIza...For production, use Wrangler:
cd backendwrangler secret put BETTER_AUTH_SECRETwrangler secret put OPENAI_API_KEYwrangler secret put ANTHROPIC_API_KEYwrangler secret put GEMINI_API_KEYDatabase
Section titled “Database”The D1 schema is defined in backend/src/db/schema.ts. Current tables:
| Table | Purpose |
|---|---|
users | Auth/user records |
sessions | Auth sessions |
accounts | OAuth/provider accounts |
verifications | better-auth verification records |
conversations | Chat conversations per user |
messages | Conversation messages |
user_settings | User settings |
api_usage | AI usage logging |
feedback | User feedback submissions |
Migrations live in backend/migrations/.
API routes
Section titled “API routes”Route mounts in backend/src/index.ts:
/api/auth/*/api/ai/chat/api/chat/*/api/user/profile/api/user/settings/api/feedback/api/health, /api/info, /api/me, /api/users*See the full API reference.
Deploy to production
Section titled “Deploy to production”Use the Cloudflare deployment guide for full setup.
Quick commands:
cd backendnpm run deploy # Wrangler deploy# ornpm run alchemy:deploy # Alchemy IaC deployThen update apiBaseURL inside AppConfig.production(for:) to your Worker URL.