Project structure
One TypeScript monorepo (Turborepo + pnpm). Apps are what you run; packages are shared code, consumed as TypeScript source.
apps/
api/ Hono API: /api/auth/* (Better Auth) and your routes under /api/*
web/ Next.js App Router, Tailwind v4, shadcn/ui
mobile/ Expo Router, NativeWind
packages/
db/ Drizzle schema, migrations, database client
auth/ Better Auth config (organizations, admin, Expo) + shared client plugins
api-client/ Typed RPC client (hono/client) used by web and mobile
email/ Email templates and sender (SMTP or console)
config/ Shared tsconfig presets
deploy/ Dockerfile, docker-compose for a VPS, deploy scripts
docs/ This documentation
AGENTS.md Rules and recipes for AI coding agents (also used by CLAUDE.md and .cursor/rules)
How a request flows
- Web calls
/api/...on its own origin.apps/web/next.config.tsrewrites it to the API, so auth cookies stay first-party. - Mobile calls the API directly and sends the session cookie it keeps in SecureStore.
- API resolves the session with Better Auth, then runs your route. Every business query is scoped to the active organization.
- Both apps use
@repo/api-client, so request and response types come straight from the API routes. No code generation.
Naming
- Internal packages are
@repo/*, private, linked withworkspace:*. - Environment variables use standard names (
DATABASE_URL,BETTER_AUTH_SECRET, ...). Only kit-specific settings use theB2BKIT_prefix. Mobile reads onlyEXPO_PUBLIC_*.
Common commands
| Command | What it does |
|---|---|
pnpm dev |
API on :3001 and web on :3000 |
pnpm dev:mobile |
Expo dev server |
pnpm db:up / db:migrate / db:seed |
Start Postgres + Mailpit, apply migrations, add sample data |
pnpm db:generate |
Create a migration after you change packages/db/src/schema |
pnpm auth:generate |
Regenerate the auth tables after you change Better Auth plugins |
pnpm admin:grant <email> |
Make a user a platform admin |
pnpm typecheck / pnpm test |
Type-check everything / run API integration tests |