A sophisticated chatbot application built with FastAPI, React, and PostgreSQL with pgvector for semantic search capabilities.
For a demonstration of the system see the TCS Banking Assistant Demo Video.
- Features
- Tech Stack
- Prerequisites
- Getting Started
- Docker Commands
- Development
- Project Structure
- Environment Variables
- Troubleshooting
- FastAPI Backend: High-performance Python backend with async support
- React Frontend: Modern, responsive user interface
- PostgreSQL + pgvector: Vector similarity search for semantic capabilities
- Docker Support: Fully containerized development and deployment
- Hot-Reload: Automatic code reloading during development
- AI Integration: Google Gemini (generation + embeddings) with ethics-gated pipeline
- FastAPI: Modern Python web framework
- SQLAlchemy: SQL toolkit and ORM
- pgvector: Vector similarity search
- Uvicorn: ASGI server
- React: UI library
- Axios: HTTP client
- React Router: Navigation
- PostgreSQL: Relational database
- pgvector: Vector extension for embeddings
Before you begin, ensure you have the following installed:
- Docker: Version 20.10 or higher (Install Docker)
- Docker Compose: Version 2.0 or higher (usually included with Docker Desktop)
- Git: For version control
To verify your installation:
docker --version
docker-compose --versiongit clone <your-repository-url>
cd chatbotCopy the example environment file and configure your settings:
cp .env.example .envEdit .env and add your API key:
# Required: Add your Google AI API key
# Get one free at: https://aistudio.google.com/apikey
GOOGLE_API_KEY=your-google-api-key-here
# Optional: Modify ports and other settings as neededdocker-compose upThe services will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- PostgreSQL: localhost:5433
docker-compose updocker-compose up -ddocker-compose downdocker-compose down -vdocker-compose builddocker-compose up --builddocker-compose build backend
docker-compose build frontenddocker-compose logsdocker-compose logs -fdocker-compose logs backend
docker-compose logs frontend
docker-compose logs postgresdocker-compose restart backenddocker-compose stop backenddocker-compose start backenddocker-compose exec postgres psql -U postgres -d chatbot_dbdocker-compose exec backend alembic upgrade headdocker-compose exec backend alembic revision --autogenerate -m "description"docker-compose psdocker statsdocker-compose exec backend bash
docker-compose exec frontend shdocker-compose rmdocker system prune -aBoth frontend and backend support hot-reloading:
- Backend: Changes to Python files automatically restart the FastAPI server
- Frontend: Changes to React components automatically refresh the browser
- Add the package to
backend/requirements.txt - Rebuild the backend service:
docker-compose build backend docker-compose up -d
- Add the package to
frontend/package.json - Rebuild the frontend service:
docker-compose build frontend docker-compose up -d
Or install directly in the running container:
docker-compose exec frontend npm install <package-name># Backend tests
docker-compose exec backend pytest
# Frontend tests
docker-compose exec frontend npm testchatbot/
├── backend/ # FastAPI backend application
│ ├── pipeline/ # Core AI pipeline (runs in order, never skip steps)
│ │ ├── ethics_gate.py # Rules + zero-shot check (runs first — blocks/allows)
│ │ ├── classifier.py # Zero-shot: emotion, intent, situation
│ │ ├── strategy.py # Emotion-first YAML strategy selection
│ │ ├── generator.py # Gemini LLM with structured prompts
│ │ ├── critic.py # Score + optional rewrite (one pass max)
│ │ └── orchestrator.py # Coordinates the full pipeline
│ ├── strategies/ # Human-editable YAML strategy files
│ │ ├── blocked/
│ │ ├── soft_persuasion/
│ │ └── neutral/
│ ├── routers/
│ │ ├── chat.py # Main chat endpoint
│ │ └── conversations.py # Conversation CRUD
│ ├── models.py # SQLAlchemy models
│ ├── database.py # DB session management
│ ├── main.py # Application entry point
│ ├── Dockerfile
│ └── requirements.txt
├── frontend/ # React frontend application
│ ├── Dockerfile
│ ├── package.json
│ └── src/
├── docker/
│ └── init-db.sql # Database initialization
├── docker-compose.yml
├── .env.example # Environment variables template
├── .gitignore
└── README.md
See .env.example for all available configuration options.
GOOGLE_API_KEY: Your Google AI API key — used for Gemini LLM generation, embeddings, and the critic agent. Get one free at aistudio.google.com/apikeySECRET_KEY: Secret key for session management (change in production)
POSTGRES_USER: Database user (default:postgres)POSTGRES_PASSWORD: Database password (default:postgres)POSTGRES_DB: Database name (default:chatbot_db)POSTGRES_PORT: Host-side PostgreSQL port (default:5433)DATABASE_URL: Full connection string (default:postgresql://postgres:postgres@localhost:5433/chatbot_db)BACKEND_PORT: Backend port (default:8000)FRONTEND_PORT: Frontend port (default:3000)CORS_ORIGINS: Allowed CORS origins (default:http://localhost:3000)
If you see an error about ports already being in use:
# Change ports in .env file
BACKEND_PORT=8001
FRONTEND_PORT=3001
POSTGRES_PORT=5433# Check if PostgreSQL is healthy
docker-compose ps
# View PostgreSQL logs
docker-compose logs postgres
# Restart PostgreSQL
docker-compose restart postgresFor frontend hot-reload issues on Windows:
# Ensure polling is enabled in .env
CHOKIDAR_USEPOLLING=true
WATCHPACK_POLLING=true# Fix permission issues
sudo chown -R $USER:$USER .# Stop all services and remove volumes
docker-compose down -v
# Remove all images
docker-compose rm -f
# Rebuild from scratch
docker-compose build --no-cache
docker-compose up[Add your license information here]
[Add contribution guidelines here]
Questions or Issues? Please open an issue on GitHub.