Chatty is a full-stack AI chat app built as a TypeScript monorepo:
chatty-api: Hono API with Better Auth, Drizzle ORM, PostgreSQL, and OpenAI.chatty-fe: React + Vite frontend using TanStack Router and React Query.packages/shared-types: Shared TypeScript contracts used by both apps.
- Email/password auth with cookie sessions (Better Auth).
- Protected chat workspace with sidebar and chat history.
- Create chat from
/chats/newby sending the first prompt immediately. - Streaming chat responses in
/chats/:id. - Shared API/data types across frontend and backend.
- Graceful fallback response when
OPENAI_API_KEYis not set.
- Frontend: React 18, Vite, TanStack Router, TanStack Query, Tailwind CSS v4.
- API: Hono, Better Auth, Drizzle ORM, PostgreSQL, OpenAI SDK.
- Language: TypeScript (ESM).
chatty/
chatty-api/ # Backend API
chatty-fe/ # Frontend app
packages/
shared-types/ # Shared TS contracts
- Node.js 20+ (recommended)
- npm 10+
- PostgreSQL 14+ (or compatible)
Create chatty-api/.env:
DATABASE_URL=postgres://postgres:postgres@localhost:5432/chatty
BETTER_AUTH_SECRET=replace-with-a-long-random-secret
BETTER_AUTH_URL=http://localhost:3000
CORS_ORIGIN=http://localhost:5173
BETTER_AUTH_TRUSTED_ORIGINS=http://localhost:5173
# Optional (AI responses). If omitted, backend uses a local fallback response.
OPENAI_API_KEY=
OPENAI_MODEL=gpt-5Optional chatty-fe/.env:
# Optional for dev proxy target (defaults to http://localhost:3000)
VITE_API_PROXY_TARGET=http://localhost:3000
# Optional direct API base URL; if omitted, frontend uses /api
VITE_API_URL=/api- Install dependencies:
npm install-
Ensure PostgreSQL is running and
DATABASE_URLpoints to a valid DB. -
Create DB schema:
npm --prefix chatty-api run db:push- Run API and frontend in separate terminals:
npm --prefix chatty-api run devnpm --prefix chatty-fe run dev- Open:
- Frontend:
http://localhost:5173 - API:
http://localhost:3000
npm run dev
npm run build
npm run start
npm run db:generate
npm run db:migrate
npm run db:pushnpm run dev
npm run build
npm run typecheck
npm run serveBase URL: /api
Auth (Better Auth):
POST /api/auth/sign-up/emailPOST /api/auth/sign-in/emailPOST /api/auth/sign-outGET /api/auth/get-session
Chats:
GET /api/chatsPOST /api/chatsGET /api/chats/:idGET /api/chats/:id/messagesPOST /api/chats/:id/messagesPOST /api/chats/:id/messages/stream(SSE)
Notes:
- Chat routes require an authenticated session cookie.
- Chat responses use the latest message history slice for context.
user,session,account,verification(Better Auth tables)chat:id,created_by,title, timestamps
chat_message:id,chat_id,role(USER | ASSISTANT | SYSTEM),content, timestamps
- Frontend routes are file-based and generated by TanStack Router (
src/routeTree.gen.ts). - The new-chat composer is shared between
/chats/newand/chats/:id. - If OpenAI is unavailable or disabled, backend returns a fallback assistant message.
DATABASE_URL is not set: addchatty-api/.env.BETTER_AUTH_SECRET is not set: add a secure random secret.- CORS/auth cookie issues in dev: verify
CORS_ORIGIN,BETTER_AUTH_URL, and trusted origins match your frontend URL. - Frontend cannot reach API: set
VITE_API_PROXY_TARGETor run API on:3000.
Private/internal project unless you add a LICENSE file stating otherwise.