Build a React-based chatbot interface that interacts with our backend API. When a user sends a message, the backend automatically generates and stores a bot response. This challenge assesses your ability to create a polished, functional chat interface with proper state management, error handling, and user experience considerations.
python3 main.pyThe server will run on http://localhost:8000
POST /api/message
Request Body:
{
"message": "string"
}Response (201 Created) with last 10 messages:
{
"user_message": {
"id": 1,
"username": "User",
"message": "Hello bot",
"timestamp": "2024-01-20T10:30:00.000Z"
},
"bot_response": {
"id": 2,
"username": "Bot",
"message": "Hello! How can I assist you today?",
"timestamp": "2024-01-20T10:30:01.000Z"
},
"messages": [
{
"id": 1,
"username": "User",
"message": "Hello",
"timestamp": "2024-01-20T10:30:00.000Z"
}
{
"id": 2,
"username": "Bot",
"message": "Hello! How can I assist you today?",
"timestamp": "2024-01-20T10:30:01.000Z"
}
]
}Error Response (400):
{
"error": "Message cannot be empty"
}GET /api/messages?limit=50&offset=0
Query Parameters:
limit(optional): Number of messages to retrieve (default: 50)offset(optional): Number of messages to skip for pagination (default: 0)
Response (200 OK):
{
"messages": [
{
"id": 1,
"username": "User",
"message": "Hello",
"timestamp": "2024-01-20T10:30:00.000Z"
},
{
"id": 2,
"username": "Bot",
"message": "Hello! How can I assist you today?",
"timestamp": "2024-01-20T10:30:01.000Z"
}
]
}- Message Display: Show all messages in a chat bubble format (User on right, Bot on left)
- Send Messages: Input field with send button to submit messages
- Auto-scroll: Automatically scroll to latest message
- Loading States: Show when waiting for bot response
- Error Handling: Handle network errors and display user-friendly messages
- Message History: Load and display conversation history on page load
- Use React (hooks preferred)
- Implement proper state management (Context API, Redux, or Zustand)
- Handle CORS (backend allows all origins)
- Responsive design that works on mobile and desktop
- Loading states for async operations
- Input validation (no empty messages)
- Typing indicator: Show "Bot is typing..." while waiting for response
- Message timestamps: Format timestamps nicely (e.g., "2:30 PM" or "2 minutes ago")
- Smooth animations: Message appearance, scroll behavior
- Keyboard shortcuts: Enter to send, Shift+Enter for new line
- Empty state: Nice UI when no messages exist
- Dark mode toggle: Support light/dark themes
- Message persistence: Save chat history in localStorage
- Accessibility: ARIA labels, keyboard navigation, screen reader support
- Mobile responsive: Works well on all screen sizes
- Unit tests: Testing critical chat functionality
- Component structure and reusability
- State management approach
- Error boundary implementation
- Code organization and naming conventions
- TypeScript usage (if applicable)
- Smooth interactions and feedback
- Loading and error states
- Responsive design
- Keyboard shortcuts
- Performance optimization (memo, useCallback, etc.)
- API integration patterns
- Error handling strategies
- Data flow architecture
- Browser compatibility
- Security considerations (XSS prevention)
- Create a new React application
- Implement the chat interface
- Include a README with:
- Setup instructions
- Architecture decisions
- Trade-offs made
- Future improvements
- Known limitations
- Bot responses are automatically generated when user sends a message
- Database persists to
chat_messages.dbfile - CORS is enabled for all origins
- No WebSocket support (use polling for real-time feel)
- Bot has a 0.5 second delay to simulate thinking
- Simple pattern-based responses (greetings, questions, general)
- Not differentiating User vs Bot messages visually
- Missing loading state while bot is "thinking"
- Not auto-scrolling to new messages
- Poor handling of rapid message sending
- Not clearing input after sending
- Memory leaks from polling intervals
- Direct DOM manipulation instead of React patterns
- Not handling Enter key for sending messages