A real-time AI chat application built with Convex and React, featuring ChatGPT-like streaming responses using Convex Components.
This project demonstrates how to build a production-ready chat interface with real-time text streaming, similar to ChatGPT, without dealing with WebSockets or SSE protocols directly.
- 🚀 Real-time streaming text responses
- 💬 Conversation history management
- 🔐 Authentication with Convex Auth
- 🎨 Modern UI with Tailwind CSS
- 📱 Responsive design
- 🔄 Persistent chat sessions
- Frontend: React + TypeScript + Vite
- Backend: Convex (serverless backend platform)
- Streaming:
@convex-dev/persistent-text-streamingcomponent - Styling: Tailwind CSS
- Authentication: Convex Auth with anonymous sign-in
- Node.js 18+ and npm
- A Convex account (sign up at convex.dev)
- Clone the repository:
git clone https://github.com/hyochan/ai-chat.git
cd ai-chat- Install dependencies:
npm install- Set up Convex:
npx convex dev- In a new terminal, start the development server:
npm run dev- Open http://localhost:5173 in your browser
├── src/ # React frontend
│ ├── components/ # UI components
│ │ ├── MessageList.tsx # Chat message display with streaming
│ │ ├── ChatInput.tsx # Message input component
│ │ └── ApiKeyModal.tsx # API key configuration
│ └── App.tsx # Main application component
├── convex/ # Backend functions
│ ├── chat.ts # Chat logic and streaming
│ ├── auth.ts # Authentication setup
│ ├── schema.ts # Database schema
│ └── http.ts # HTTP routes for streaming
└── package.json # Dependencies and scripts
The app uses @convex-dev/persistent-text-streaming to handle real-time text streaming:
- Backend: When a message is sent, a unique
streamIdis created - Streaming: The
/chat-streamHTTP endpoint streams responses character by character - Frontend: The
useStreamhook subscribes to updates and displays them in real-time
- StreamingMessage: Displays messages with real-time streaming animation
- MessageList: Manages the chat conversation display
- ChatInput: Handles user input and message sending
The app uses Convex Auth with anonymous authentication for easy sign-in. You can modify this to add other authentication providers like Google, GitHub, etc.
The app supports two modes:
- Built-in AI: Uses a limited free tier (default)
- Custom OpenAI API Key: Users can provide their own API key for full access
Create a .env.local file:
VITE_CONVEX_URL=<your-convex-deployment-url>- Build the app:
npm run build- Deploy to Convex:
npx convex deploy- Deploy the frontend to your preferred hosting service (Vercel, Netlify, etc.)
- Frontend: Any static hosting service (Vercel, Netlify, Cloudflare Pages)
- Backend: Automatically hosted by Convex
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.