Author: Nikhil Kumar
A production-ready, full-stack AI chatbot application featuring real-time sentiment analysis, multi-provider LLM support, and streaming responses.
- Features
- Tech Stack
- Project Structure
- Quick Start
- Environment Variables
- Deployment
- Documentation
- Contributing
- License
Analyzes user sentiment at both message and conversation levels using three switchable strategies:
| Strategy | Description | Best For |
|---|---|---|
| Structured Output | Single LLM call returns response + sentiment in JSON | Performance & efficiency |
| LLM Separate | Dedicated LLM call for detailed sentiment analysis | Accuracy & nuance |
| Google Cloud NLP | Google's Natural Language API for fast analysis | Production scale |
Conversation-Level (Tier 1): Aggregates all user messages to track overall emotional trajectory
Statement-Level (Tier 2): Analyzes each message individually with real-time visualization
- Google Gemini: 2.0 Flash, 1.5 Pro, 1.5 Flash
- OpenAI: GPT-4o, GPT-4o Mini, GPT-3.5 Turbo
- Hot-swappable at runtime via unified adapter interface
- Server-Sent Events (SSE) for token-by-token response streaming
- Live sentiment updates as conversations progress
- Visual trend charts powered by Recharts
- JWT-based authentication with configurable expiration
- Async bcrypt password hashing
- Per-user conversation isolation
- Fully async backend with
asyncpgand SQLAlchemy 2.0 - Redis caching via Upstash (serverless)
- Connection pooling for database scalability
| Technology | Version | Purpose |
|---|---|---|
| FastAPI | 0.115+ | Web framework |
| Python | 3.11+ | Runtime |
| SQLAlchemy | 2.0+ | Async ORM |
| PostgreSQL | (Neon) | Database |
| Upstash Redis | REST API | Caching & rate limiting |
| google-genai | 1.0+ | Gemini integration |
| OpenAI | 1.57+ | GPT integration |
| Pydantic | 2.10+ | Validation |
| structlog | 24.4+ | Structured logging |
| Technology | Version | Purpose |
|---|---|---|
| React | 19.2 | UI framework |
| TypeScript | 5.9 | Type safety |
| Vite | (Rolldown) | Build tool |
| TailwindCSS | 4.1 | Styling |
| TanStack Query | 5.90 | Server state |
| Recharts | 3.5 | Data visualization |
| Radix UI | Latest | Accessible components |
| Framer Motion | 12.23 | Animations |
Lia-assignment/
βββ backend/ # FastAPI Backend Service
β βββ app/
β β βββ api/ # REST API endpoints
β β β βββ routes/
β β β β βββ auth.py # Authentication routes
β β β β βββ chat.py # Chat & streaming routes
β β β β βββ health.py # Health check routes
β β β βββ deps.py # Dependencies (auth, rate limit)
β β β βββ schemas.py # Pydantic models
β β βββ core/ # Configuration & security
β β β βββ config.py # Settings management
β β β βββ security.py # JWT & password utils
β β β βββ logging.py # Structured logging
β β βββ db/ # Database layer
β β β βββ models.py # SQLAlchemy models
β β β βββ session.py # Async session factory
β β βββ services/ # Business logic
β β βββ chat.py # Chat orchestrator
β β βββ llm.py # LLM adapters (Gemini/OpenAI)
β β βββ sentiment.py # Sentiment strategies
β β βββ cache/ # Modular cache system
β β β βββ base.py # Base caching operations
β β β βββ conversation.py # Conversation caching
β β β βββ static.py # Static content caching
β β β βββ rate_limit.py # Rate limiting cache
β β β βββ user.py # User data caching
β β βββ rate_limit.py # Rate limiting service
β βββ alembic/ # Database migrations
β βββ tests/ # Pytest test suite
β βββ pyproject.toml # Python dependencies (uv)
β βββ render.yaml # Render deployment config
β
βββ frontend/ # React Frontend Application
β βββ src/
β β βββ components/
β β β βββ chat/ # Chat UI components
β β β β βββ ChatInterface.tsx
β β β β βββ ChatInput.tsx
β β β β βββ ChatSidebar.tsx
β β β β βββ ChatInspector.tsx
β β β β βββ MessageList.tsx
β β β βββ ui/ # Reusable UI primitives
β β β βββ AuthPage.tsx # Login/Register
β β β βββ MarkdownMessage.tsx
β β βββ context/ # React context (Auth)
β β βββ lib/ # Utilities & API client
β β βββ __tests__/ # Vitest test suite
β βββ package.json # Node dependencies (pnpm)
β βββ vite.config.ts # Vite configuration
β
βββ ARCHITECTURE.md # System architecture documentation
βββ README.md # This file
- Python 3.11+ with uv package manager
- Node.js 20+ with pnpm
- PostgreSQL database (or Neon account)
- Redis (or Upstash account)
- API Keys: At least one of Gemini or OpenAI
git clone https://github.com/your-username/Lia-assignment.git
cd Lia-assignmentcd backend
# Install uv if not installed
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create and configure environment
cp .env.example .env
# Edit .env with your credentials
# Install dependencies
uv sync
# Run database migrations
uv run alembic upgrade head
# Start development server
uv run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd frontend
# Create environment file
echo "VITE_API_URL=http://localhost:8000" > .env
# Install dependencies
pnpm install
# Start development server
pnpm devOpen your browser to http://localhost:5173
| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | β |
JWT_SECRET_KEY |
Secret for JWT signing (min 32 chars) | β |
GEMINI_API_KEY |
Google Gemini API key | β‘ |
OPENAI_API_KEY |
OpenAI API key | β‘ |
UPSTASH_REDIS_REST_URL |
Upstash Redis REST URL | β |
UPSTASH_REDIS_REST_TOKEN |
Upstash Redis token | β |
CORS_ORIGINS |
Allowed origins (comma-separated) | β |
GOOGLE_CLOUD_PROJECT |
GCP project for NLP API | β |
β‘ At least one LLM provider key is required
| Variable | Description | Required |
|---|---|---|
VITE_API_URL |
Backend API URL | β |
- Connect your GitHub repository to Render
- Render auto-detects
render.yamlconfiguration - Configure environment variables in Render dashboard
- Deploy automatically on push to main
- Import project to Vercel
- Set
VITE_API_URLto your Render backend URL - Deploy with automatic preview deployments
| Document | Description |
|---|---|
| ARCHITECTURE.md | System architecture & design patterns |
| backend/README.md | Backend setup & API reference |
| backend/ARCHITECTURE.md | Backend architecture details |
| backend/OPTIMIZATION_REPORT.md | Performance analysis & recommendations |
| frontend/README.md | Frontend documentation |
The project has comprehensive test coverage across both frontend and backend.
cd backend
uv run pytest # Run all tests
uv run pytest --cov=app # With coverage
uv run pytest tests/test_auth.py # Specific filecd frontend
pnpm test # Run all tests (watch mode)
pnpm test --run # Run once
pnpm test -- --coverage # With coverageTotal: 469 tests with sub-second individual test execution
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Please ensure:
- Tests pass (
uv run pytest/pnpm test) - Code follows existing style (Ruff for Python, ESLint for TypeScript)
- Documentation is updated if needed
This project is licensed under the MIT License. See LICENSE for details.
Built with β€οΈ using FastAPI, React, and modern AI