Syed Arfan
Add React frontend for Sentiment Analysis API
2857363

Sentiment Analysis Frontend

A modern React frontend for the Sentiment Analysis API, featuring real-time sentiment analysis, history tracking, and cache performance monitoring.

Features

  • Real-time Sentiment Analysis: Analyze text sentiment instantly
  • Visual Feedback: Beautiful emoji-based sentiment indicators
  • Confidence Scores: Progress bars showing prediction confidence
  • Analysis History: Browse and filter previous analyses
  • Cache Statistics: Monitor Redis cache performance
  • Responsive Design: Works on all devices (320px+)
  • Accessibility: WCAG AA compliant

Tech Stack

  • React 19 - UI library
  • TypeScript - Type safety
  • Vite - Build tool
  • Tailwind CSS 4 - Styling
  • Axios - HTTP client
  • Lucide React - Icons

Getting Started

Prerequisites

  • Node.js 18+
  • The Sentiment API backend running (see main README)

Installation

# Install dependencies
npm install

# Start development server
npm run dev

The app will be available at http://localhost:5173

Environment Variables

Create a .env file (copy from .env.example):

# API Base URL
VITE_API_BASE_URL=http://localhost:8000

Building for Production

npm run build

The built files will be in the dist/ directory.

Project Structure

src/
β”œβ”€β”€ components/          # React components
β”‚   β”œβ”€β”€ Header.tsx       # App header
β”‚   β”œβ”€β”€ Footer.tsx       # App footer
β”‚   β”œβ”€β”€ SentimentAnalyzer.tsx  # Main input/analysis
β”‚   β”œβ”€β”€ ResultCard.tsx   # Result display
β”‚   β”œβ”€β”€ HistoryList.tsx  # Analysis history
β”‚   └── CacheStats.tsx   # Cache dashboard
β”œβ”€β”€ hooks/               # Custom React hooks
β”‚   β”œβ”€β”€ useSentimentAnalysis.ts
β”‚   β”œβ”€β”€ useHistory.ts
β”‚   └── useCacheStats.ts
β”œβ”€β”€ services/            # API services
β”‚   └── api.ts           # Axios instance & endpoints
β”œβ”€β”€ types/               # TypeScript types
β”‚   └── index.ts
β”œβ”€β”€ utils/               # Utility functions
β”‚   β”œβ”€β”€ formatters.ts    # Date/number formatting
β”‚   └── validators.ts    # Input validation
β”œβ”€β”€ App.tsx              # Root component
β”œβ”€β”€ main.tsx             # Entry point
└── index.css            # Global styles

Deployment

GitHub Pages

The frontend is configured for GitHub Pages deployment. Push to main branch and the GitHub Actions workflow will automatically build and deploy.

Live URL: https://simplyarfan.github.io/Sentiment-API/

Other Platforms

  • Vercel: Connect your GitHub repo
  • Netlify: Connect your GitHub repo
  • Manual: Run npm run build and upload dist/ folder

API Endpoints Used

Endpoint Method Description
/analyze POST Analyze text sentiment
/history GET Get analysis history
/cache/stats GET Get cache statistics

License

MIT