Skip to content

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
  • 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 uses RATE_LIMIT_KV when 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)
Terminal window
cd backend
npm install
npm run dev

This starts a local Cloudflare Workers dev server on http://localhost:8787.

Terminal window
curl http://localhost:8787/healthz

You should see:

{ "status": "ok", "environment": "development", "timestamp": "..." }
Terminal window
cd ios
xcodegen generate --spec project.yml
open SwiftLaunch.xcodeproj

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=fullStack

That value is read by AppConfig.runtime() in:

  • ios/SwiftLaunch/Core/Config/AppConfig.swift

Development apiBaseURL defaults to http://localhost:8787, matching wrangler dev.

Select an iOS 17+ simulator and hit Cmd+R. The app connects to your local backend for auth, chat, and API calls.

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.ts

For local development, add secrets to a .dev.vars file in backend/:

BETTER_AUTH_SECRET=your-secret-here
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GEMINI_API_KEY=AIza...

For production, use Wrangler:

Terminal window
cd backend
wrangler secret put BETTER_AUTH_SECRET
wrangler secret put OPENAI_API_KEY
wrangler secret put ANTHROPIC_API_KEY
wrangler secret put GEMINI_API_KEY

The D1 schema is defined in backend/src/db/schema.ts. Current tables:

TablePurpose
usersAuth/user records
sessionsAuth sessions
accountsOAuth/provider accounts
verificationsbetter-auth verification records
conversationsChat conversations per user
messagesConversation messages
user_settingsUser settings
api_usageAI usage logging
feedbackUser feedback submissions

Migrations live in backend/migrations/.

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.

Use the Cloudflare deployment guide for full setup.

Quick commands:

Terminal window
cd backend
npm run deploy # Wrangler deploy
# or
npm run alchemy:deploy # Alchemy IaC deploy

Then update apiBaseURL inside AppConfig.production(for:) to your Worker URL.