Skip to content

yashnayan8795/Sentiment-Analysis-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“° SentiNews - Intelligent News Sentiment Analyzer

Transform any news article into actionable sentiment insights with the power of AI

Next.js React FastAPI MongoDB Redis

A comprehensive full-stack web application that analyzes the sentiment of news articles using AI-powered natural language processing. Built with modern technologies for production-ready performance and scalability.

🌟 Features

Core Functionality

  • URL-based Analysis: Analyze any news article by simply pasting its URL
  • AI-Powered Processing: Uses DistilBERT and T5-small models for accurate sentiment analysis and summarization
  • Real-time Visualization: Interactive charts and meters showing sentiment breakdown
  • Historical Tracking: Store and view analysis history with MongoDB persistence
  • Rate Limiting: Built-in protection against API abuse (100 requests/hour/IP)

User Experience

  • Dark/Light Theme: Seamless theme switching with system preference detection
  • Responsive Design: Optimized for desktop, tablet, and mobile devices
  • Interactive Dashboard: Comprehensive analytics and insights visualization
  • Error Handling: Graceful degradation and user-friendly error messages
  • Loading States: Smooth loading indicators and progress feedback

Technical Features

  • TypeScript to JavaScript: Fully converted for broader compatibility
  • Production Ready: Comprehensive error handling and resilient architecture
  • Modular Components: 45+ reusable UI components with Radix UI
  • Performance Optimized: Built-in caching and optimization strategies

πŸš€ Technology Stack

Frontend

  • Framework: Next.js 15.2.4 with App Router
  • Language: JavaScript (converted from TypeScript)
  • UI Library: React 19 with modern hooks
  • Styling: Tailwind CSS 3.4.17 with custom design system
  • Components: Radix UI primitives for accessibility
  • Charts: Recharts 2.15.0 for data visualization
  • Animations: Framer Motion 12.6.2
  • Theme: next-themes for dark/light mode
  • Forms: React Hook Form with Zod validation
  • State: Local React state with custom hooks

Backend

  • API Framework: FastAPI with async support
  • AI/ML: Hugging Face Transformers (DistilBERT + T5-small)
  • Web Scraping: BeautifulSoup4 + aiohttp
  • Database: MongoDB with connection pooling
  • Caching: Redis via Upstash for rate limiting
  • Environment: Python 3.8+ with uvicorn server

Infrastructure

  • Rate Limiting: Upstash Redis with in-memory fallback
  • Deployment: Vercel-ready with environment configuration
  • Testing: Jest with React Testing Library
  • Build Tools: Next.js with optimized production builds
  • Package Manager: pnpm for efficient dependency management

πŸ—οΈ MVC Architecture Overview

This project has been refactored to follow the Model-View-Controller (MVC) architectural pattern, providing clear separation of concerns, improved maintainability, and better testability.

Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        PRESENTATION LAYER                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Frontend (Next.js)           β”‚  Backend (FastAPI)              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚        VIEWS            β”‚  β”‚  β”‚     CONTROLLERS         β”‚    β”‚
β”‚  β”‚  - AnalysisView.js      β”‚  β”‚  β”‚  - AnalysisController   β”‚    β”‚
β”‚  β”‚  - DashboardView.js     β”‚  β”‚  β”‚  - DashboardController  β”‚    β”‚
β”‚  β”‚  - HistoryView.js       β”‚  β”‚  β”‚  - StatsController      β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        BUSINESS LAYER                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚       SERVICES          β”‚  β”‚  β”‚        MODELS           β”‚    β”‚
β”‚  β”‚  - AnalysisService      β”‚  β”‚  β”‚  - AnalysisModel        β”‚    β”‚
β”‚  β”‚  - StorageService       β”‚  β”‚  β”‚  - ArticleModel         β”‚    β”‚
β”‚  β”‚  - ApiClient            β”‚  β”‚  β”‚  - SentimentModel       β”‚    β”‚
β”‚  β”‚  - WebScrapingService   β”‚  β”‚  β”‚  - URLInputModel        β”‚    β”‚
β”‚  β”‚  - AIService            β”‚  β”‚  β”‚  - TextInputModel       β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        DATA LAYER                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚     REPOSITORIES        β”‚  β”‚  β”‚      DATABASES          β”‚    β”‚
β”‚  β”‚  - AnalysisRepository   β”‚  β”‚  β”‚  - MongoDB              β”‚    β”‚
β”‚  β”‚  - StorageRepository    β”‚  β”‚  β”‚  - Redis (Rate Limiting)β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚  - Local Storage        β”‚    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

Sentiment-Analysis-App/
β”œβ”€β”€ src/                          # Frontend MVC Structure
β”‚   β”œβ”€β”€ models/                   # Data Models
β”‚   β”‚   β”œβ”€β”€ ArticleModel.js       # Article data structure
β”‚   β”‚   β”œβ”€β”€ SentimentModel.js     # Sentiment analysis data
β”‚   β”‚   └── AnalysisModel.js      # Combined analysis model
β”‚   β”œβ”€β”€ services/                 # Business Logic Services
β”‚   β”‚   β”œβ”€β”€ AnalysisService.js    # Main analysis business logic
β”‚   β”‚   β”œβ”€β”€ StorageService.js     # Data persistence service
β”‚   β”‚   └── ApiClient.js          # API communication service
β”‚   β”œβ”€β”€ controllers/              # Controllers
β”‚   β”‚   └── AnalysisController.js # Main application controller
β”‚   β”œβ”€β”€ views/                    # View Components
β”‚   β”‚   └── AnalysisView.js       # Main analysis interface
β”‚   β”œβ”€β”€ styles/                   # Styling
β”‚   β”‚   └── mvc-styles.css        # MVC-specific styles
β”‚   └── app.js                    # Application entry point
β”œβ”€β”€ backend/                      # Backend MVC Structure
β”‚   β”œβ”€β”€ models/                   # Data Models
β”‚   β”‚   └── analysis_model.py     # Pydantic models
β”‚   β”œβ”€β”€ services/                 # Business Logic Services
β”‚   β”‚   β”œβ”€β”€ analysis_service.py   # Core analysis logic
β”‚   β”‚   β”œβ”€β”€ web_scraping_service.py # Web scraping logic
β”‚   β”‚   └── ai_service.py         # AI model operations
β”‚   β”œβ”€β”€ controllers/              # Controllers
β”‚   β”‚   └── analysis_controller.py # HTTP request handling
β”‚   β”œβ”€β”€ repositories/             # Data Access Layer
β”‚   β”‚   └── analysis_repository.py # Database operations
β”‚   └── main_mvc.py              # FastAPI application
β”œβ”€β”€ app/                         # Next.js App Router
β”‚   β”œβ”€β”€ api/                     # API Routes (Controllers)
β”‚   β”‚   β”œβ”€β”€ analyze/route.js     # Analysis endpoint
β”‚   β”‚   └── history/route.js     # History endpoint
β”‚   └── page.jsx                 # Main page component
└── components/                  # Legacy UI Components (for reference)

πŸ”§ MVC Components Breakdown

Models (Data Layer)

Frontend Models

  • ArticleModel.js: Handles article data structure and validation
  • SentimentModel.js: Manages sentiment analysis data and calculations
  • AnalysisModel.js: Combines article and sentiment data

Backend Models

  • analysis_model.py: Pydantic models for data validation and serialization

Views (Presentation Layer)

Frontend Views

  • AnalysisView.js: Main analysis interface with MVC pattern
  • DashboardView.js: Dashboard visualization (planned)
  • HistoryView.js: Analysis history display (planned)

Controllers (Business Logic Layer)

Frontend Controllers

  • AnalysisController.js: Manages application state and coordinates services

Backend Controllers

  • analysis_controller.py: Handles HTTP requests and coordinates services

Services (Business Logic)

Frontend Services

  • AnalysisService.js: Main business logic for analysis operations
  • StorageService.js: Local storage management
  • ApiClient.js: Backend API communication

Backend Services

  • analysis_service.py: Core analysis business logic
  • web_scraping_service.py: Web scraping and content extraction
  • ai_service.py: AI model operations

Repositories (Data Access)

Backend Repositories

  • analysis_repository.py: Database operations with MongoDB and fallback

πŸš€ Key MVC Benefits

1. Separation of Concerns

  • Models: Handle data structure and business rules
  • Views: Manage user interface and presentation
  • Controllers: Coordinate between models and views

2. Improved Maintainability

  • Clear code organization
  • Easy to locate and modify specific functionality
  • Reduced coupling between components

3. Better Testability

  • Each layer can be tested independently
  • Mock dependencies easily
  • Unit tests for models, integration tests for controllers

4. Scalability

  • Easy to add new features
  • Modular architecture supports team development
  • Clear interfaces between layers

5. Code Reusability

  • Models can be reused across different views
  • Services can be shared between controllers
  • Clear abstractions enable component reuse

πŸ› οΈ Installation & Setup

1. Install Dependencies

# Frontend dependencies
npm install

# Backend dependencies
pip install -r requirements.txt

2. Environment Configuration

# Copy environment template
npm run setup
# or manually: cp .env.example .env.local

The .env.local file will be created with default local development settings. You can modify it if needed:

# Frontend Configuration
NEXT_PUBLIC_BACKEND_URL=http://localhost:8000

# Database Configuration (Optional - app works without it)
MONGODB_URI=mongodb://localhost:27017

# Redis Configuration (Optional - falls back to in-memory)
UPSTASH_REDIS_REST_URL=your_redis_url
UPSTASH_REDIS_REST_TOKEN=your_redis_token

3. Run the Application

Option 1: MVC Architecture (Recommended)

# Terminal 1 - Backend (MVC)
npm run backend

# Terminal 2 - Frontend
npm run dev

Option 2: Legacy Architecture

# Terminal 1 - Backend (Legacy)
npm run backend:legacy

# Terminal 2 - Frontend
npm run dev

πŸ“Š API Endpoints (MVC)

Analysis Endpoints

  • POST /api/analyze - Analyze article from URL
  • POST /api/analyze-text - Analyze provided text
  • GET /api/history - Get analysis history
  • GET /api/analysis/{id} - Get specific analysis
  • GET /api/raw-sentiment?url={url} - Get raw sentiment data

Management Endpoints

  • DELETE /api/history - Clear analysis history
  • GET /api/stats - Get analysis statistics
  • GET /api/health - Health check

πŸ§ͺ Testing MVC Architecture

Frontend Testing

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

Backend Testing

# Run Python tests
pytest backend/tests/

# Run with coverage
pytest --cov=backend backend/tests/

MVC Architecture Test

# Test MVC structure
npm run mvc:test

πŸ“ˆ Performance Benefits

Frontend Performance

  • Lazy Loading: Views load only when needed
  • State Management: Centralized controller state
  • Memory Efficiency: Proper cleanup and disposal

Backend Performance

  • Service Caching: AI models cached after first load
  • Database Optimization: Efficient queries with fallbacks
  • Error Recovery: Graceful degradation

πŸ›‘οΈ Security & Error Handling

MVC Security Features

  • Input Validation: Models validate all inputs
  • Error Boundaries: Controllers handle errors gracefully
  • Rate Limiting: Service-level rate limiting
  • Data Sanitization: Repository-level data cleaning

Error Handling Strategy

  1. Models: Validate data and throw validation errors
  2. Services: Handle business logic errors
  3. Controllers: Transform errors to HTTP responses
  4. Views: Display user-friendly error messages

πŸ“š Learning Resources

Technology Stack

🀝 Contributing

MVC Development Guidelines

  1. Models: Keep business logic in models
  2. Views: Keep presentation logic in views
  3. Controllers: Keep coordination logic in controllers
  4. Services: Keep reusable business logic in services
  5. Repositories: Keep data access logic in repositories

Code Organization

  • Follow the established MVC structure
  • Use dependency injection for services
  • Implement proper error handling
  • Write comprehensive tests
  • Document public APIs

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the documentation
  2. Search existing issues
  3. Create a new issue

Author

YASH NAYAN


About

Welcome to new age Sentiment Analyzer!

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors