A professional AI chat assistant powered by Claude 3.5 Sonnet, built with Next.js and deployed on Google Cloud Run.
- 🤖 Real-time AI conversations with Claude 3.5 Sonnet
- 💬 Streaming responses for better user experience
- 📱 Fully responsive design for desktop and mobile
- 🔄 Session-based conversation management
- 🎨 Clean, business-like UI with TailwindCSS
- 🚀 Optimized for Google Cloud Run deployment
- Frontend: Next.js 15 (App Router), React 19, TypeScript
- Backend: Next.js API Routes, Hono
- Database: MongoDB with Prisma ORM
- AI: Anthropic Claude 3.5 Sonnet
- Styling: TailwindCSS
- Deployment: Google Cloud Run, Docker
- Node.js 20+
- Docker and Docker Compose (for MongoDB)
- Anthropic API key
- Google Cloud account (for deployment)
- Clone the repository:
git clone <repository-url>
cd ai-chat- Start MongoDB with Docker:
docker compose up -d mongodb- Install dependencies:
npm install- Set up environment variables:
cp .env.local.example .env.localEdit .env.local with your values:
ANTHROPIC_API_KEY=your_anthropic_api_key
MONGODB_URI=mongodb://localhost:27017/ai-chat
NEXT_PUBLIC_APP_URL=http://localhost:3000
- Generate Prisma client:
npx prisma generate- Run the development server:
npm run devOpen http://localhost:3000 to see the application.
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm test- Run testsnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage
/
├── app/ # Next.js app directory
│ ├── api/ # API routes
│ │ ├── chat/ # Chat endpoint
│ │ ├── session/ # Session management
│ │ └── health/ # Health check
│ ├── layout.tsx # Root layout
│ └── page.tsx # Home page
├── components/ # React components
│ ├── ChatInterface.tsx
│ ├── MessageList.tsx
│ ├── InputArea.tsx
│ └── TypingIndicator.tsx
├── lib/ # Utility libraries
│ ├── prisma/ # Prisma client
│ └── mastra/ # AI client
├── prisma/ # Database schema
└── __tests__/ # Test files
Stop MongoDB:
docker compose downView MongoDB logs:
docker compose logs mongodb- Build the Docker image:
docker build -t ai-chat .- Run the container:
docker run -p 3000:3000 --env-file .env.local ai-chat-
Ensure you have the gcloud CLI installed and configured
-
Deploy using the provided script:
./deploy.sh [PROJECT_ID] [REGION]- After deployment, set the environment variables in Cloud Run console:
- ANTHROPIC_API_KEY
- MONGODB_URI
- NEXT_PUBLIC_APP_URL
- GET
/api/health - Returns service health status
- GET
/api/session/new - Creates a new chat session
- POST
/api/chat - Body:
{ sessionId: string, message: string } - Returns: Server-sent events stream
- API keys are stored as environment variables
- Sessions expire after 24 hours
- Input validation on all endpoints
- Rate limiting considerations for production
- React.memo optimization for message components
- Streaming responses for real-time feel
- Standalone Next.js build for optimal Docker images
- Configured for 5-10 concurrent users
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the ISC License.