Skip to content

bradmeyn/chatty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chatty

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.

Features

  • Email/password auth with cookie sessions (Better Auth).
  • Protected chat workspace with sidebar and chat history.
  • Create chat from /chats/new by 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_KEY is not set.

Tech Stack

  • Frontend: React 18, Vite, TanStack Router, TanStack Query, Tailwind CSS v4.
  • API: Hono, Better Auth, Drizzle ORM, PostgreSQL, OpenAI SDK.
  • Language: TypeScript (ESM).

Repository Layout

chatty/
  chatty-api/            # Backend API
  chatty-fe/             # Frontend app
  packages/
    shared-types/        # Shared TS contracts

Prerequisites

  • Node.js 20+ (recommended)
  • npm 10+
  • PostgreSQL 14+ (or compatible)

Environment Variables

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-5

Optional 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

Quick Start

  1. Install dependencies:
npm install
  1. Ensure PostgreSQL is running and DATABASE_URL points to a valid DB.

  2. Create DB schema:

npm --prefix chatty-api run db:push
  1. Run API and frontend in separate terminals:
npm --prefix chatty-api run dev
npm --prefix chatty-fe run dev
  1. Open:
  • Frontend: http://localhost:5173
  • API: http://localhost:3000

Scripts

Backend (chatty-api)

npm run dev
npm run build
npm run start
npm run db:generate
npm run db:migrate
npm run db:push

Frontend (chatty-fe)

npm run dev
npm run build
npm run typecheck
npm run serve

API Overview

Base URL: /api

Auth (Better Auth):

  • POST /api/auth/sign-up/email
  • POST /api/auth/sign-in/email
  • POST /api/auth/sign-out
  • GET /api/auth/get-session

Chats:

  • GET /api/chats
  • POST /api/chats
  • GET /api/chats/:id
  • GET /api/chats/:id/messages
  • POST /api/chats/:id/messages
  • POST /api/chats/:id/messages/stream (SSE)

Notes:

  • Chat routes require an authenticated session cookie.
  • Chat responses use the latest message history slice for context.

Data Model (High Level)

  • user, session, account, verification (Better Auth tables)
  • chat:
    • id, created_by, title, timestamps
  • chat_message:
    • id, chat_id, role (USER | ASSISTANT | SYSTEM), content, timestamps

Development Notes

  • Frontend routes are file-based and generated by TanStack Router (src/routeTree.gen.ts).
  • The new-chat composer is shared between /chats/new and /chats/:id.
  • If OpenAI is unavailable or disabled, backend returns a fallback assistant message.

Troubleshooting

  • DATABASE_URL is not set: add chatty-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_TARGET or run API on :3000.

License

Private/internal project unless you add a LICENSE file stating otherwise.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages