AI Chat Assistant
ChatGPT Clone
Full-stack AI chat assistant with streamed replies, saved conversation history, image understanding and question answering over uploaded PDFs.
Overview
What the product does
A rebuild of a modern AI assistant's core experience. Users sign in, start a conversation and get an answer that streams in token by token and is saved to their account. Each reply can draw on images they attach or PDFs they upload, so the assistant can answer about a screenshot or from the contents of a document.
Problem
The problem it solves
A useful assistant needs more than a chat box in front of a model: history that lives on the server rather than in the browser, answers grounded in the user's own documents instead of general knowledge, and uploads that can't be used to reach another user's files or slip a non-image past the model.
My role
What I contributed
Designed and built both applications: the Next.js chat interface and the Express API behind it, covering streaming, the PDF retrieval pipeline, file uploads, authentication and persistence.
Solution
How the system was designed
A Next.js frontend proxies every /api request to an Express and TypeScript API on Bun, keeping auth cookies first-party. The Vercel AI SDK streams OpenAI replies, PostgreSQL through Prisma stores users, conversations, messages and images, and a LangChain pipeline indexes PDFs into Qdrant for retrieval-augmented answers. The server owns the conversation history, rebuilding the context from the database on every request.
Architecture
System architecture
Key features
What it does in practice
Replies stream in token by token through the AI SDK's UI message stream and can be stopped partway through. Users can regenerate a reply, retry a failed one or edit an earlier message, and answers render as GitHub-flavoured Markdown with syntax-highlighted code blocks.
Uploaded PDFs are chunked, embedded with text-embedding-3-large and indexed in Qdrant. A LangChain multi-query retriever rewrites each question several ways before searching, so passages are found even when the document is worded differently from the question.
Up to five PNG, JPEG, WebP or GIF images per message are passed to a vision-capable model, including messages with no text at all. Images are stored once and referenced by id, so the bytes are only loaded when the model or their owner needs them.
Conversations are saved to PostgreSQL, titled automatically from the first message and grouped by date in the sidebar. They can be renamed, pinned, archived and deleted, and found with a ⌘K command-palette search.
Better Auth with email and password or Google OAuth, using httpOnly session cookies. Private pages are protected by a session check against the backend rather than by trusting that a cookie exists.
Challenges
The interesting engineering problems
Technology
The stack behind it
- Next.jsReact Framework
- Express.jsHTTP Framework
- OpenAILLMs & Embeddings
- Vercel AI SDKLLM Streaming
- LangChainRetrieval Pipeline
- QdrantVector Database
- PostgreSQLRelational Database
- Prisma ORMType-Safe ORM
- Better AuthAuthentication
- BunRuntime & Package Manager
- TypeScriptType Safety
- ReactFrontend UI
- Tailwind CSSStyling System
- TanStack QueryServer State
- ZodSchema Validation
- DockerContainerization