How saram098/ai-powered-chatbot-for-coding-and-document-queries works
Project Type and Purpose
• This is a full-stack application with a clear separation between a FastAPI backend (for handling multiple query types with Groq API integration) and a Streamlit frontend (providing a user-friendly chat interface).
• Its main purpose is to process text, PDF documents, and audio queries for coding and document-related assistance, with chat histories stored per user.
Main Components
a. FastAPI Backend
• File: app.py
• Responsibilities:
• Handling incoming queries (text, document, audio)
• Communicating with the Groq API to generate responses
• Managing the query processing logic for different input types
• Key interactions: Receives queries from the frontend and returns response data.
b. Streamlit Frontend
• File: CodeGenie.py
• Responsibilities:
• Providing an interactive chatbot interface for users
• Uploading documents/audio or entering text
• Displaying chat history and responses
• Key interactions: Sends requests to the FastAPI backend and displays results.
c. Data Storage Components
• Chats Folder (auto-created): Stores user-specific chat histories in JSON format.
• Data Folder (auto-created): Holds user-uploaded PDFs and audio files.
d. Environment Configuration
• .env file: Contains vital configuration data like the BASE_URL and GROQ_API_KEY.
e. Dependencies and Frameworks
• FastAPI, Uvicorn – powering the backend server.
• Streamlit – powering the interactive frontend.
• Additional libraries for PDF (PyMuPDF) and audio (SpeechRecognition, pydub) processing.
Relationships and Interactions
• The backend processes these queries by:
• Managing file storage by saving relevant documents and user audio in the Data folder.
• Storing chat sessions in the Chats folder.
• From Frontend → Backend (user queries)
• From Backend → Groq API (model query)
• From Groq API → Backend (model response)
• From Backend → Frontend (final response)
• Configuration exchange where the .env file provides settings to both the backend and indirectly the frontend (when quoted as BASE_URL).
Architectural Patterns / Design Principles
• Separation of concerns: The frontend handles user interactions, while backend processes and business logic are decoupled.
• Modular design: Each component (query processing, file storage, chat history) is separate.
• Extensibility: The architecture allows the backend to easily update the model (as noted in the README, via the “query_groq” function).
• Under the Backend, add sub-components:
• Query Processing (function: query_groq)
• File management (Data and Chats folders)
• Environment Configuration (link to .env)
• For the Frontend, indicate the interactive UI and user entry points.
• How a text, PDF, or audio query flows from the Streamlit interface to the FastAPI backend.
• The backend sending a model query to and receiving a response from the Groq API.
• Saving of results in the chats folder and retrieval of stored files from the data folder.
• Annotations at each step if needed, noting the libraries or frameworks involved (e.g., “FastAPI”, “Uvicorn”, “Streamlit”).