A full-stack web application that analyzes the sentiment of movie reviews using two approaches:
- Rule-based word analysis
- LLM-based classification via Google's Gemini API
Live Demo: https://sentiment-analyzer-sooty.vercel.app
This application supports two distinct approaches to sentiment classification:
- A curated list of positive, negative, and neutral words/phrases is used to assess the sentiment of the review.
- The algorithm counts occurrences of these keywords, while also handling edge cases such as:
- Negations (e.g., "not good" is treated as negative)
- Multi-word expressions (e.g., "highly recommend" is treated as positive)
- Neutral expressions (e.g., "okay", "average")
- The final sentiment (Positive, Negative, or Neutral) is determined based on the relative counts.
- An explanation with counts and a computed score is returned to help interpret the result.
Example:
Review: "Absolutely not great. I expected better." Sentiment: Negative Explanation: Rule-based: Score = -2.5 (Pos: 0, Neg: 2, Neutral: 0)
- Reviews are passed to the Google Gemini API with a prompt instructing it to classify sentiment as Positive, Negative, or Neutral.
- The model's textual response is parsed and matched to one of the three sentiment labels.
- A short explanation (e.g., "Gemini says: Mostly positive with uplifting words") is returned to provide interpretability.
- This method supports more nuanced or complex sentence structures.
- Analyze movie reviews using either LLM or rule-based logic
- View past analyses in a searchable, filterable, and sortable table
- Clear explanations provided for both analysis methods
- Delete entries with confirmation dialogs
- Method preference is remembered locally
- Next.js (App Router)
- Tailwind CSS for styling
- React Hot Toast for user feedback
- Express.js using ES Modules
- MongoDB Atlas for database
- Google Gemini API integration
- CORS, dotenv, and body-parser
sentiment-analyzer/
├── backend/ # Express.js API
│ ├── routes/ # Modular route handlers
│ ├── utils/ # Gemini and rule-based logic
│ ├── models/ # Mongoose schemas
│ └── app.js # Application entry point
│
├── frontend/ # Next.js application
│ ├── app/ # App Router pages
│ ├── components/ # Reusable UI components
│ ├── lib/ # API interaction helpers
│ └── tailwind.config.js # Tailwind CSS config
│
├── .env # Environment variables
└── README.md
- Clone the repository
git clone https://github.com/sourabhaprasad/sentiment-analyzer.git
cd sentiment-analyzer
- Backend Setup
cd backend
npm install
cp .env.example .env
# Fill in MONGO_URI and GEMINI_API_KEY
npm run dev
# Server runs at http://localhost:3001
- Frontend Setup
cd ../frontend
npm install
cp .env.example .env
# Add NEXT_PUBLIC_API_BASE_URL=http://localhost:3001
npm run dev
# Frontend runs at http://localhost:3000
Method | Endpoint | Description |
---|---|---|
POST | /analyze |
Analyze a movie review |
GET | /results |
Fetch all analyzed results |
GET | /results/:id |
Fetch details of a specific result |
DELETE | /results/:id |
Delete a specific result |
- Routes are modular and grouped by resource (
/results
,/analyze
) - Easy to extend: just add a new file in
routes/
and wire it inapp.js
- Shared logic like Gemini and rule-based models live in
utils/
- Environment and configuration values are centralized in
.env
This structure supports quick scalability with minimal boilerplate.
- Add confidence scores and probability output from LLM
- Build a dashboard to visualize sentiment trends over time
- Support multiple languages for international reviews
- Implement user authentication and history
- Enhance explanation by highlighting detected keywords