How chetanaya/tweetsenseai works
Project Type and Purpose
• TweetSenseAI is a monolithic, full‑stack Python web application built with Streamlit.
File Structure
• Top‑level files only; no separate “frontend”/“backend” folders.
• app.py: the single entry point that defines UI (Streamlit) and orchestration.
• config.yaml + .env.example: configuration for API keys and app settings.
• requirements.txt: tech stack dependencies (e.g., streamlit, tweepy/twitterapi‑client, openai, pandas, plotly).
README Insights
• Confirms usage of: Streamlit (UI), Twitter API, OpenAI API, pandas (data), plotly/matplotlib (charts), CSV/JSON export.
• Mentions session state management (in‑memory state via Streamlit).
Main Components (to represent
a. User Interface Layer (Streamlit Web App)
– Hosted on Streamlit server, accessed via browser
– Sidebar for API key input, search parameters
– Main area: card/table/JSON views + charts + export buttons
b. Application Logic / Controller
– app.py handlers tie UI inputs to service functions
– Session State Manager (Streamlit session) to cache search results
c. Data Retrieval Service
– Twitter API Client (twitterapi.io or tweepy wrapper)
– Handles query construction, pagination, rate limiting
d. AI Analysis Service
– OpenAI Client for sentiment analysis & phrase extraction
– Manages prompts, receives model responses
e. Data Processing & Storage
– pandas DataFrames for transformations and aggregations
– In‑memory store via session state
– Export Module → CSV/JSON files (local download)
f. Visualization Layer
– Plotly or Matplotlib charts for metrics (volume, sentiment distribution)
– Table and card layouts rendered in Streamlit
g. Configuration & Environment
– config.yaml for default settings
– .env for secret keys (TWITTER_API_KEY, OPENAI_API_KEY)
Relationships & Data Flows
• User → (1) UI inputs parameters → Streamlit app
• Streamlit Controller → (2) invokes Twitter API Client → (3) returns raw tweet data
• Controller → (4) stores raw data in Session State → (5) invokes pandas for metrics
• Controller → (6) invokes OpenAI Client with tweet text → (7) receives sentiment/phrases → stores in Session
• Controller → (8) triggers Visualization Layer to render charts & tables
• User → (9) clicks “Export” → Export Module converts DataFrame → CSV/JSON download
Architectural Patterns & Design Principles
• Monolithic MVC‑style within a single process:
• Model: Data retrieval & processing (Twitter client, pandas)
• View: Streamlit UI components
• Controller: Handlers in app.py wiring UI ↔ services
• External Service Integration pattern for API clients
• Session State pattern for in‑memory caching between UI interactions