A real-time chat application with specialized AI assistants built using WebSocket, Express.js, Next.js, and Groq API.
- Real-time Chat: WebSocket-based messaging for instant communication
- Specialized AI Assistants: 7 different AI experts (DevGPT, ChefGPT, DocGPT, LegalGPT, FitGPT, FinanceGPT, StoryGPT)
- Room-based Chat: Each AI assistant has its dedicated chat room
- User Authentication: JWT-based authentication with secure password hashing
- Responsive UI: Modern, dark-themed interface with Tailwind CSS
- Docker Support: Containerized microservices architecture
- HTTP Service (Port 3001): Express.js REST API with Prisma ORM and PostgreSQL
- WebSocket Service (Port 7070): Real-time chat handling
- Frontend (Port 3000): Next.js React application
- Docker and Docker Compose
- Node.js 18+ (for local development)
- PostgreSQL database
- Groq API key
-
Clone the repository
git clone <repository-url> cd websocket-ai-chat-app
-
Set up environment variables
cp .env.example .env
Edit
.envand add your configuration:DATABASE_URL="postgresql://username:password@localhost:5432/database_name" JSON_WEB_TOKEN_SECRET="your-super-secret-jwt-key-here" GROQ_API_KEY="your-groq-api-key-here"
-
Start the application
docker-compose up --build
-
Access the application
- Frontend: http://localhost:3000
- API: http://localhost:3001
- WebSocket: ws://localhost:7070
cd http
npm install
npx prisma generate
npx prisma db push
npx prisma db seed
npm run devcd websocket
npm install
npm startcd frontend
npm install
npm run dev| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Required |
JSON_WEB_TOKEN_SECRET |
JWT signing secret | "secretttt" |
GROQ_API_KEY |
Groq API key for AI responses | Required |
HTTP_SERVICE_URL |
HTTP service URL for WebSocket | http://localhost:3001 |
FRONTEND_URL |
Frontend URL for CORS | http://localhost:3000 |
PORT |
HTTP service port | 3001 |
POST /api/v1/user/signup- User registrationPOST /api/v1/user/signin- User loginPUT /api/v1/user- Update user profileGET /api/v1/user/:id- Get user by ID
POST /api/v1/chat- Send chat messageGET /api/v1/chat/history/:roomName- Get chat history
GET /api/v1/room/:name- Get room detailsGET /api/v1/dashboard- Get all available rooms
// Join a room
{
"type": "join",
"roomName": "room-DevGPT"
}
// Send chat message
{
"type": "chat",
"content": "Hello, how can you help me?",
"roomName": "room-DevGPT",
"userId": 123
}// Chat message received
{
"type": "chat",
"userMessage": { ... },
"aiMessage": { ... }
}
// Typing indicator
{
"type": "typing",
"roomName": "room-DevGPT",
"username": "john_doe"
}
// Error message
{
"type": "error",
"message": "Error description"
}- DevGPT - Programming and development assistance
- ChefGPT - Culinary guidance and recipes
- DocGPT - Medical consultation and health advice
- LegalGPT - Legal guidance and explanations
- FitGPT - Fitness coaching and workout plans
- FinanceGPT - Financial advice and budgeting
- StoryGPT - Creative writing and storytelling
- JWT-based authentication
- Password hashing with bcrypt
- Input validation and sanitization
- Rate limiting protection
- CORS configuration
- SQL injection prevention with Prisma
The application includes comprehensive error handling:
- Input validation
- Database error handling
- API timeout handling
- WebSocket connection management
- Graceful error responses
For production deployment:
- Use strong JWT secrets
- Configure proper CORS origins
- Set up SSL/TLS certificates
- Use environment-specific database URLs
- Configure proper logging
- Set up monitoring and health checks
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.