Galaxy Chat
- Year
- 2025
- Role
- Design and engineering
- Status
- Live

Conversations worth returning to
I built Galaxy Chat to explore a personal AI assistant with streaming responses, persistent conversations, file uploads and memory. Messages can be edited or regenerated, so a conversation can develop beyond its first prompt.
Next.js handles the application, Clerk identifies the account, MongoDB stores conversations and the Vercel AI SDK streams model responses. Mem0 supplies optional context across chats.
How it works
Conversation history, model output and retrieved memory have separate responsibilities.
Next.js chat route
The route validates input, resolves the Clerk session and checks chat ownership. It loads prior messages before starting generation.
All implementation notes
Conversation flow
- Chat interface
- Messages retain structured parts for streamed content and attachments. Cloudinary uploads follow a separate route from conversation persistence.
- Next.js chat route
- The route validates input, resolves the Clerk session and checks chat ownership. It loads prior messages before starting generation.
- Model stream
- The Vercel AI SDK streams UI messages over server-sent events. Completion handlers persist the generated messages and record usage.
- MongoDB
- MongoDB stores conversations, message parts and usage. Optional TokenLens enrichment falls back to basic usage if its catalogue is unavailable.
- Mem0
- Mem0 retrieves context scoped to the authenticated user. Memory failures produce empty context or skip storage; conversation history is still available.
- Chat interface: submits a message (Next.js chat route).
- Next.js chat route: streams a response with history and memory context (Model stream).
- Next.js chat route: loads history and persists messages (MongoDB).
- Next.js chat route: retrieves and stores optional memories (Mem0).
Engineering decisions
- Check ownership before generation. The chat route validates input and verifies that an existing conversation belongs to the signed-in account.
- Preserve message structure. Messages retain parts for text and attachments. Completion handlers persist streamed output and record usage; Cloudinary uploads use a separate route.
- Memory is optional. Mem0 reads and writes are user-scoped and tolerate failure. History remains in MongoDB, while optional TokenLens enrichment falls back to basic model usage.
Try Galaxy Chat (opens in a new tab) or browse the source (opens in a new tab).