QueryBot is a chat application designed to simulate a conversation between a user and a bot. It allows the user to ask queries, and the bot responds with detailed answers, powered by a backend API. The app provides an interactive, real-time chat experience, with real-time responses and markdown support for text formatting.
- User Interaction: The user can input queries, and the bot will respond in real-time.
- Bot Responses: The bot's responses are dynamically generated and displayed with Markdown formatting support.
- Message Styling: Messages from the user are displayed on the right, while messages from the bot appear on the left.
- Loading State: The bot shows a loading animation when processing the user's query.
- Scrolling: The chat container auto-scrolls to the latest message, ensuring the user always sees the most recent messages.
- Frontend: React.js, Tailwind CSS, Lucide Icons, React Markdown
- Backend: Flask or Node.js (assuming backend is implemented and running on
http://127.0.0.1:5000/askfor this demo) - State Management: Zustand for managing global state
- Markdown Rendering: React Markdown with GFM (GitHub Flavored Markdown) plugin for Markdown rendering
- Icons: Lucide Icons for bot and user representation
git clone https://github.com/your-username/querybot.git
cd querybotnpm installThis will install all the necessary dependencies for the project.
For the demo to work, the app expects a backend API at http://127.0.0.1:5000/ask. If you don't have the backend ready yet, you can simulate the responses by modifying the axios call in App.js or use any mock API.
Once everything is set up, you can run the app in development mode.
npm startYour application will be available at http://localhost:3000 in the browser.
Here's a breakdown of the file structure:
/querybot
│
├── /src
│ ├── /components
│ │ ├── ChatContainer.jsx # Chat UI and message display
│ │ ├── InputBar.jsx # User input and message submission
│ │ ├── Navbar.jsx # Application header/navbar
│ ├── /store
│ │ ├── query.store.js # Zustand store for managing state (messages, loading state)
│ ├── App.jsx # Main component that ties everything together
│ ├── index.js # React entry point
├── /public
│ ├── index.html # HTML template
├── /node_modules # Dependencies
├── package.json # Project configuration and dependencies
├── tailwind.config.js # Tailwind CSS configuration
└── README.md # Project Documentation
ChatContainer.js: Displays the conversation, handling both user and bot messages. Messages are styled and rendered dynamically based on their sender.InputBar.js: Manages the user input, triggering the query submission to the backend and updating the message state.Navbar.js: Simple navigation bar for the app's UI.
query.store.js: Zustand store for managing the global state of messages and loading states. This store tracks the chat messages and whether the bot is loading a response.
When the user types a query and submits it:
- The query is sent to the backend API (
/ask). - The user's message is added to the message state and displayed on the right.
- While waiting for the response, a loading spinner appears.
- Once the response is received, the bot's message is added to the message state and displayed on the left.
Messages are styled using Tailwind CSS to distinguish between the user's messages and the bot's messages:
- User Messages: Displayed on the right with a blue background (
bg-blue-500) and white text. - Bot Messages: Displayed on the left with a gray background (
bg-gray-200) and black text. - Icons: The bot’s icon (
Bot) appears alongside the bot’s message, while the user’s icon (User2) appears with the user’s message. - Loading State: The bot's message container shows an ellipsis animation when the bot is "typing."
To improve user experience, the chat window auto-scrolls to the bottom to show the most recent messages using ScrollToBottom.
Both user and bot messages support Markdown rendering, allowing for text formatting (bold, italic, links, etc.) using the ReactMarkdown component with the remark-gfm plugin for GitHub-flavored markdown.
-
Keyboard Behavior: The app ensures that the messages container adapts to the height of the on-screen keyboard when using mobile devices. This may require additional customization depending on the environment.
-
Error Handling: In case of an error during the API request, a generic error message will be displayed instead of the bot’s response.
- Backend Integration: The backend is currently a mock API. Integrate with a real backend that processes queries and provides intelligent responses.
- User Authentication: Add user authentication for personalized experiences.
- Enhanced UI: Add features such as avatars for the bot, emojis, or richer text formatting.
- Message History: Store chat history in local storage or a database to retrieve and display previous conversations.
Feel free to open issues and pull requests! If you want to contribute, follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature-branch) - Commit your changes (
git commit -am 'Add feature') - Push to the branch (
git push origin feature-branch) - Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.