No description
Find a file
bananabas f3a304d613 feat: Add better-auth Drizzle schema
This commit introduces the Drizzle ORM schema for the `better-auth`
library. This includes tables for users, sessions, accounts,
verification, organizations, members, invitations, and passkeys, along
with their respective relations.

This schema provides the foundational database structure for user
authentication and authorization within the application, enabling
features like passkey sign-in, organization management, and invitation
handling.
2026-04-13 18:28:47 +01:00
.deployment i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
.github/workflows feat: add GitHub Actions ad-hoc iOS build workflow 2026-03-28 08:01:08 +00:00
apps feat: Add better-auth Drizzle schema 2026-04-13 18:28:47 +01:00
docs i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
packages/types i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
scripts chore: clean up project structure 2026-04-13 17:16:11 +01:00
.eslintrc.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
.gitignore i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
.prettierrc.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
AGENTS.md chore: clean up project structure 2026-04-13 17:16:11 +01:00
app.json fix: resolve React Native 0.76 + Expo 55 compatibility for old architecture 2026-03-27 17:24:57 +00:00
bun.lock feat: Add @simplewebauthn/server dependency 2026-04-13 18:03:55 +01:00
eas.json fix: resolve React Native 0.76 + Expo 55 compatibility for old architecture 2026-03-27 17:24:57 +00:00
FILE_STRUCTURE.txt chore: clean up project structure 2026-04-13 17:16:11 +01:00
FINAL_STATUS.txt chore: clean up project structure 2026-04-13 17:16:11 +01:00
package.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
PROJECT_STATUS.md added extra bits and bobs 2026-04-13 17:46:48 +01:00
README.md chore: clean up project structure 2026-04-13 17:16:11 +01:00
sst.config.ts i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
STATUS.txt chore: clean up project structure 2026-04-13 17:16:11 +01:00
tsconfig.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00
turbo.json i call bagsy on the initial commit 2026-03-27 17:05:28 +00:00

Bagsy — Family Shopping List App

A native iOS shopping list app built with Swift/SwiftUI and a TypeScript/Node.js backend.

What is Bagsy?

Bagsy lets families share and sync shopping lists in real time. Key features:

  • Passkey authentication (Face ID / Touch ID) + email/password fallback
  • Household management — invite family members via 6-character join codes
  • Shopping lists organized by store aisle
  • Real-time sync across devices via WebSocket
  • AI product suggestions (OpenRouter)
  • Barcode scanning support
  • Full dark mode

Architecture

/
├── apps/
│   ├── api/               # Next.js 16 backend (API routes only, port 3001)
│   │   ├── app/api/       # Route handlers (auth, households, lists, items, stores, ai)
│   │   ├── db/            # Drizzle ORM schema + PostgreSQL connection
│   │   ├── lib/           # auth.ts, websocket.ts, middleware
│   │   └── server.ts      # Custom HTTP server (WebSocket + local IP display)
│   │
│   └── ios/Bagsy/         # Native Swift/SwiftUI iOS app
│       └── Bagsy/ShopList/
│           ├── App/       # AppState & lifecycle
│           ├── Core/      # API client, Keychain, Cache, WebSocket, Theme
│           ├── Features/  # Auth, Lists, Stores screens
│           └── Models/    # Data models
│
└── packages/
    └── types/             # Shared TypeScript types

Stack

Layer Technology
iOS app Swift 5.9+, SwiftUI, Combine
Backend Node.js 20+, Next.js 16, TypeScript
Database PostgreSQL + Drizzle ORM
Auth Better Auth (passkey, email/password, magic link, organizations)
Real-time WebSocket (ws)
AI Vercel AI SDK + OpenRouter
Monorepo Turborepo + bun workspaces

Running Locally

Prerequisites

  • macOS 12+ with Xcode 14+
  • bun 1.2+
  • PostgreSQL 13+

1. Install dependencies

bun install

2. Configure the backend

cp apps/api/.env.example apps/api/.env.local

Edit apps/api/.env.local:

BETTER_AUTH_SECRET=$(openssl rand -base64 32)
BETTER_AUTH_URL=http://localhost:3001
DATABASE_URL=postgresql://user:password@localhost:5432/bagsy
OPENROUTER_API_KEY=sk-or-...   # optional, for AI suggestions
NODE_ENV=development
PORT=3001

3. Apply database migrations

cd apps/api
bun run db:push

4. Start the backend

cd apps/api
bun run dev
# Prints local network IP for iOS simulator/device

5. Open the iOS app

cd apps/ios/Bagsy
open Bagsy.xcodeproj
# Press Cmd+R in Xcode to build and run

Update the server URL in AppState.swift to match the IP printed by the backend:

let serverURL = URL(string: "http://192.168.x.x:3001")!

Deploying

The backend is a standard Next.js app with a custom Node server. Deploy to any provider that supports Node.js.

Vercel

cd apps/api
npx vercel deploy

Note: Vercel serverless functions don't support WebSocket. Use Railway or Render for full WebSocket support.

Railway / Render

  1. Connect your repository.
  2. Set the root directory to apps/api.
  3. Set build command: bun run build
  4. Set start command: bun run start
  5. Add environment variables (see below).

Required environment variables (production)

BETTER_AUTH_SECRET=<openssl rand -base64 32>
BETTER_AUTH_URL=https://api.yourdomain.com
DATABASE_URL=postgresql://...
OPENROUTER_API_KEY=...   # optional
NODE_ENV=production

iOS release build

cd apps/ios/Bagsy
xcodebuild archive -scheme Bagsy -configuration Release
# Upload via Xcode Organizer or Transporter.app

Auth Setup (Better Auth + Passkeys)

Auth is configured in apps/api/lib/auth.ts using Better Auth.

Plugins enabled:

  • organization — maps to Bagsy "households" (family groups)
  • passkey — WebAuthn / Face ID / Touch ID
  • magicLink — email magic links (logs to console in dev; wire up a mail provider for prod)

Key routes (all under /api/auth/[...all]):

Endpoint Description
POST /api/auth/sign-up/email Register with email + password
POST /api/auth/sign-in/email Sign in with email + password
POST /api/auth/passkey/generate-registration-options Begin passkey registration
POST /api/auth/passkey/verify-registration Complete passkey registration
POST /api/auth/passkey/generate-authentication-options Begin passkey sign-in
POST /api/auth/passkey/verify-authentication Complete passkey sign-in

Requirements:

  • PostgreSQL is required (passkey and organization tables need it)
  • BETTER_AUTH_SECRET must be set and stable (changing it invalidates all sessions)
  • BETTER_AUTH_URL must match the actual origin the app connects to (used as WebAuthn rpID)

iOS client uses @better-auth/expo for cookie/session management compatible with native HTTP clients.

Common Issues

iOS can't connect to API

  • Confirm backend is running: ps aux | grep node
  • Make sure the IP in AppState.swift matches what bun run dev printed
  • Device and Mac must be on the same Wi-Fi network

Passkey endpoints return empty responses

  • Ensure BETTER_AUTH_URL is set correctly in .env.local
  • The passkey plugin reads baseURL to derive the WebAuthn rpID
  • Restart the backend after changing env vars

Database connection errors

  • Confirm DATABASE_URL is set and PostgreSQL is running
  • Re-run bun run db:push after schema changes