How gpa95/ai_studybuddy works
Project type and purpose
• Type: Full-stack web application (lightweight)
• Purpose: Provide a chat-based UI for students to get explanations, summaries, and quizzes by leveraging Google’s Gemini 2.5 Flash AI API.
File structure
• Top-level files:
• main.py – entry point (Streamlit app)
• requirements.txt – Python dependencies
• assets/ – static resources (e.g., sample PDFs)
• components/ – UI widgets and handlers for chat, sidebar, and PDF uploads
• core/ – business logic modules (explainer, summarizer, quizzer, PDF handler, AI utilities)
• utils/ – helper for interacting with Gemini API
• Patterns:
• Separation of concerns: UI (components) vs core logic vs external API helpers
• No persistent database—stateless, relies on in-memory chat context and external AI service
Extract architecture insights from README
• Frontend: Streamlit app rendering components and managing user sessions
• Backend / AI Engine: Calls to Gemini 2.5 Flash API via utils/gemini_helper.py
• Security: Credentials managed in .env and st.secrets
• PDF processing: PyPDF2 inside components/pdf_handler.py and core/pdf_handler.py
Main components and their interactions
a. Frontend Layer (Streamlit UI)
• Blocks: Chat UI, Sidebar, File uploader (components/chat_ui.py, components/sidebar.py, components/pdf_handler.py)
• Orchestrator: main.py initializes UI and routes interactions to core modules
b. Core Processing Layer
• explainer.py, summarizer.py, quizzer.py: contain prompt templates and logic to frame queries
• ai_utils.py: common routines (e.g., formatting responses)
• pdf_handler.py: parse and extract text from uploaded PDFs
c. Integration Layer (utils)
• gemini_helper.py: wraps API calls, handles authentication and rate-limits
d. External Service
• Google Gemini 2.5 Flash API: generates natural language responses
e. Configuration & Secrets
• .env / st.secrets: store API keys and config
Relationships & data flow
1. User interacts with Streamlit UI → submits text or PDF
2. PDF handler extracts text (PyPDF2) → returns raw text
3. Core module (explainer/summarizer/quizzer) receives text or user query → builds prompt
4. gemini_helper.py sends prompt to Gemini API → receives response
5. ai_utils formats the response → Streamlit UI displays reply
Architectural patterns & principles
• Modular Separation: UI vs business logic vs API integration
• Statelessness: No persistent DB; session state lives in Streamlit memory
• Single Responsibility: Each module/class has a clear, isolated role
• Secure Configuration: Externalizes secrets, avoids hard-coding