# devmohith/sentiment-analysis architecture

> Architecture diagram of the GitHub repository devmohith/sentiment-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devmohith/sentiment-analysis
- Repository: https://github.com/devmohith/sentiment-analysis

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        Browser["User Browser"]:::frontend
        Firebase["Firebase Hosting (CDN)"]:::frontend
    end

    subgraph "API Layer (GCP Cloud Run)"
        Flask["Flask Backend\nPOST /analyze"]:::backend
    end

    subgraph "AI Layer"
        Vertex["Vertex AI\nText-Bison Model"]:::ai
        IAM["GCP IAM\n(Service Account)"]:::security
    end

    Browser -->|"Loads SPA (HTTP GET)"| Firebase
    Firebase -->|"Serves Static Files"| Browser
    Browser -->|"POST /analyze (HTTPS)"| Flask
    Flask -->|"Invokes AI (gRPC/REST)"| Vertex
    Vertex -->|"Sentiment Response"| Flask
    Flask -->|"JSON Response"| Browser
    IAM --- Flask
    IAM --- Vertex

    click Browser "https://github.com/devmohith/sentiment-analysis/tree/main/sentiment_frontend/"
    click Firebase "https://github.com/devmohith/sentiment-analysis/tree/main/sentiment_frontend/"
    click main "https://github.com/devmohith/sentiment-analysis/blob/main/sentiment_frontend/src/main.jsx"
    click App "https://github.com/devmohith/sentiment-analysis/blob/main/sentiment_frontend/src/App.jsx"
    click AppCSS "https://github.com/devmohith/sentiment-analysis/blob/main/sentiment_frontend/src/App.css"
    click IndexCSS "https://github.com/devmohith/sentiment-analysis/blob/main/sentiment_frontend/src/index.css"
    click HTML "https://github.com/devmohith/sentiment-analysis/blob/main/sentiment_frontend/index.html"
    click Assets "https://github.com/devmohith/sentiment-analysis/tree/main/sentiment_frontend/src/assets/"
    click Vite "https://github.com/devmohith/sentiment-analysis/blob/main/sentiment_frontend/vite.config.js"
    click FEReadme "https://github.com/devmohith/sentiment-analysis/blob/main/sentiment_frontend/README.md"
    click ESLint "https://github.com/devmohith/sentiment-analysis/blob/main/sentiment_frontend/eslint.config.js"
    click BackendDir "https://github.com/devmohith/sentiment-analysis/tree/main/backend/"
    click MainPy "https://github.com/devmohith/sentiment-analysis/blob/main/backend/main.py"
    click Bg "https://github.com/devmohith/sentiment-analysis/blob/main/backend/.gitignore"
    click RootReadme "https://github.com/devmohith/sentiment-analysis/blob/main/README.md"

    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef backend fill:#DFFFE0,stroke:#28A745,color:#28A745
    classDef ai fill:#FFE8B0,stroke:#D97706,color:#D97706
    classDef security fill:#FFF4E5,stroke:#F59E0B,color:#B45309
```
