← projects
Next.js

AsroChat

AsroChat
Next.js
OVERVIEW

An AI chatbot platform supporting multiple providers (OpenAI, Gemini, Anthropic) with retrieval-augmented generation backed by a Postgres + pgvector store. Built with Next.js 15 and NextAuth.js for authentication, Tailwind CSS with shadcn/ui for the interface, and React Query for data fetching.

TECH STACK
Next.jsPostgreSQLpgvectorNextAuth.jsReact Query
KEY FEATURES
  • Multi-provider AI routing across OpenAI, Gemini, and Anthropic for each bot
  • Retrieval-augmented generation over uploaded training data via a Postgres + pgvector store
  • Streaming chat responses with per-bot conversation session management
  • Usage dashboard with per-bot analytics, credits, and pricing-plan alignment
HOW IT WORKS
  1. 01A user message hits the chat API route, validated and sanitized before processing
  2. 02The route loads or creates a chat session and stores the user's message
  3. 03The query is embedded and matched against uploaded training data via a Postgres + pgvector cosine-similarity search for RAG context
  4. 04The AI response is generated by trying Gemini, then Groq, then OpenRouter, skipping any provider currently in cooldown
  5. 05The response streams back over server-sent events and is persisted to Postgres
CHALLENGES

A chat API needs one reliable response even when a single AI provider is down, rate-limited, or slow. Solved with an automatic fallback chain (Gemini → Groq → OpenRouter) that tracks per-provider cooldowns, so a failing provider is skipped instantly on the next request instead of retried.

METRICS
17
DB models
51
API routes
35,448
TS/TSX LOC
47
npm dependencies