Transform any news article into actionable sentiment insights with the power of AI
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.
- 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)
- 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
- 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
- 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
- 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
- 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
This project has been refactored to follow the Model-View-Controller (MVC) architectural pattern, providing clear separation of concerns, improved maintainability, and better testability.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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)
ArticleModel.js: Handles article data structure and validationSentimentModel.js: Manages sentiment analysis data and calculationsAnalysisModel.js: Combines article and sentiment data
analysis_model.py: Pydantic models for data validation and serialization
AnalysisView.js: Main analysis interface with MVC patternDashboardView.js: Dashboard visualization (planned)HistoryView.js: Analysis history display (planned)
AnalysisController.js: Manages application state and coordinates services
analysis_controller.py: Handles HTTP requests and coordinates services
AnalysisService.js: Main business logic for analysis operationsStorageService.js: Local storage managementApiClient.js: Backend API communication
analysis_service.py: Core analysis business logicweb_scraping_service.py: Web scraping and content extractionai_service.py: AI model operations
analysis_repository.py: Database operations with MongoDB and fallback
- Models: Handle data structure and business rules
- Views: Manage user interface and presentation
- Controllers: Coordinate between models and views
- Clear code organization
- Easy to locate and modify specific functionality
- Reduced coupling between components
- Each layer can be tested independently
- Mock dependencies easily
- Unit tests for models, integration tests for controllers
- Easy to add new features
- Modular architecture supports team development
- Clear interfaces between layers
- Models can be reused across different views
- Services can be shared between controllers
- Clear abstractions enable component reuse
# Frontend dependencies
npm install
# Backend dependencies
pip install -r requirements.txt# Copy environment template
npm run setup
# or manually: cp .env.example .env.localThe .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_tokenOption 1: MVC Architecture (Recommended)
# Terminal 1 - Backend (MVC)
npm run backend
# Terminal 2 - Frontend
npm run devOption 2: Legacy Architecture
# Terminal 1 - Backend (Legacy)
npm run backend:legacy
# Terminal 2 - Frontend
npm run devPOST /api/analyze- Analyze article from URLPOST /api/analyze-text- Analyze provided textGET /api/history- Get analysis historyGET /api/analysis/{id}- Get specific analysisGET /api/raw-sentiment?url={url}- Get raw sentiment data
DELETE /api/history- Clear analysis historyGET /api/stats- Get analysis statisticsGET /api/health- Health check
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage# Run Python tests
pytest backend/tests/
# Run with coverage
pytest --cov=backend backend/tests/# Test MVC structure
npm run mvc:test- Lazy Loading: Views load only when needed
- State Management: Centralized controller state
- Memory Efficiency: Proper cleanup and disposal
- Service Caching: AI models cached after first load
- Database Optimization: Efficient queries with fallbacks
- Error Recovery: Graceful degradation
- Input Validation: Models validate all inputs
- Error Boundaries: Controllers handle errors gracefully
- Rate Limiting: Service-level rate limiting
- Data Sanitization: Repository-level data cleaning
- Models: Validate data and throw validation errors
- Services: Handle business logic errors
- Controllers: Transform errors to HTTP responses
- Views: Display user-friendly error messages
- Models: Keep business logic in models
- Views: Keep presentation logic in views
- Controllers: Keep coordination logic in controllers
- Services: Keep reusable business logic in services
- Repositories: Keep data access logic in repositories
- Follow the established MVC structure
- Use dependency injection for services
- Implement proper error handling
- Write comprehensive tests
- Document public APIs
If you encounter any issues or have questions:
- Check the documentation
- Search existing issues
- Create a new issue
YASH NAYAN