How devmohith/sentiment-analysis works
Project Type & Purpose
• This is a full-stack AI-powered sentiment analyzer.
• Frontend: React single-page app (Vite) hosted on Firebase Hosting.
• Backend: Python Flask microservice deployed on Cloud Run.
• AI Service: Google Cloud Vertex AI (Text-Bison PaLM 2 model).
File Structure Insights
• Top level:
• README.md – project overview & deployment URLs
• backend/ – Flask app (main.py defines the /analyze endpoint)
• sentiment_frontend/ – React app under Vite config
– public/ & src/ with App.jsx, assets, index.html, etc.
• No additional microservices; single API service.
• Deployment config implied by hosting URLs (Firebase for frontend, Cloud Run for backend).
Key README Details
• /analyze endpoint bridges React → Flask → Vertex AI.
• Uses GCP service-account for Cloud Auth.
• Deployed: Firebase Hosting (frontend), Cloud Run (backend).
• Real-time REST call for sentiment classification.
Main Architectural Components
a. User’s Web Browser (Client)
– Loads HTML/CSS/JS from Firebase Hosting.
– Runs React SPA (App.jsx → fetch/Axios call).
b. Firebase Hosting (Static CDN)
– Serves the React app.
c. Flask Backend (Cloud Run Microservice)
– Exposes POST /analyze endpoint.
– Handles CORS and request parsing.
– Authenticates to GCP using a service account.
– Invokes Vertex AI REST/gRPC API.
d. Vertex AI (Text-Bison Model)
– External GCP AI service that returns sentiment.
e. GCP Identity & Access Management
– Service account credentials stored as Cloud Run secrets/env vars.
Component Interactions & Data Flow
1. User enters text in React UI → clicks “Analyze.”
2. React app sends HTTP POST to Cloud Run URL (/analyze).
3. Flask service receives request → validates & forwards prompt to Vertex AI.
4. Vertex AI returns sentiment label.
5. Flask formats JSON response → sends back to React.
6. React updates UI with sentiment result.
Architectural Patterns & Principles
• Three-tier SPA architecture: Presentation (React), Application (Flask), AI Service (Vertex AI).
• Serverless deployment: frontend static hosting, backend container on Cloud Run.
• Clear separation of concerns: UI vs. business logic vs. AI inference.
• Secure service-to-service auth (GCP IAM service account).
Technologies & Frameworks
• Frontend: React.js, Vite, JSX, CSS
• Backend: Python Flask, CORS, Google Cloud SDK
• AI: Vertex AI Text-Bison (PaLM 2)
• Deployment: Firebase Hosting, Cloud Run, GCP IAM