A production-ready Retrieval-Augmented Generation (RAG) chatbot built with FastAPI, Streamlit, AWS Bedrock, and ChromaDB. This enterprise-level application demonstrates modern software architecture, containerization, and cloud deployment practices.
Try the chatbot live: http://18.207.19.42:8501/
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Streamlit │ │ FastAPI │ │ AWS Bedrock │
│ Frontend │◄──►│ Backend │◄──►│ (Claude AI) │
│ (Port 8501) │ │ (Port 8000) │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ ChromaDB │
│ Vector Store │
└─────────────────┘
- Streaming Chat Interface: Real-time response streaming using Streamlit
- RAG Implementation: Retrieval-augmented generation with vector similarity search
- AWS Bedrock Integration: Claude 3 Haiku model for high-quality responses
- Vector Database: ChromaDB for efficient document storage and retrieval
- Containerized Deployment: Docker and Docker Compose for easy deployment
- CI/CD Pipeline: GitHub Actions for automated testing and deployment
- Health Monitoring: Comprehensive health checks and monitoring
- Production Ready: Proper logging, error handling, and security practices
- Docker and Docker Compose
- AWS Account with Bedrock access
- Python 3.11+ (for local development)
git clone <your-repository-url>
cd genai-rag-chatbot
cp .env.example .envEdit .env file with your AWS credentials:
AWS_ACCESS_KEY_ID=your_access_key_here
AWS_SECRET_ACCESS_KEY=your_secret_key_here
AWS_DEFAULT_REGION=us-east-1
BACKEND_URL=http://localhost:8000docker-compose up --build- Frontend (Streamlit): http://localhost:8501
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reloadcd frontend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
streamlit run app.pygenai-rag-chatbot/
├── backend/
│ ├── app/
│ │ ├── __init__.py
│ │ ├── main.py # FastAPI application
│ │ ├── models.py # Pydantic models
│ │ ├── services/
│ │ │ ├── __init__.py
│ │ │ ├── bedrock_service.py # AWS Bedrock integration
│ │ │ ├── embedding_service.py # Text embedding service
│ │ │ └── vector_store_service.py # ChromaDB operations
│ │ └── routers/
│ │ ├── __init__.py
│ │ └── chat.py # Chat endpoints
│ ├── Dockerfile
│ ├── requirements.txt
│ └── knowledge_base/
│ └── documents/ # Sample documents for RAG
├── frontend/
│ ├── app.py # Streamlit application
│ ├── Dockerfile
│ ├── requirements.txt
│ └── utils/
│ ├── __init__.py
│ └── api_client.py # Backend API client
├── .github/
│ └── workflows/
│ └── ci-cd.yml # GitHub Actions pipeline
├── docker-compose.yml
├── .env.example
├── .gitignore
└── README.md
POST /chat/- Send chat message (complete response)POST /chat/stream- Send chat message (streaming response)GET /chat/health- Chat service health check
GET /- API informationGET /health- Main health checkGET /docs- Interactive API documentation
import requests
# Send chat message
response = requests.post("http://localhost:8000/chat/", json={
"message": "What is AWS Bedrock?",
"max_tokens": 1000,
"temperature": 0.7
})
print(response.json()["response"])- Choose Ubuntu 22.04 LTS
- Configure security groups (ports 22, 8000, 8501)
- Assign elastic IP (optional)
# Update system
sudo apt update && sudo apt upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker ubuntu
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Reboot to apply changes
sudo reboot# Clone repository
git clone <your-repository-url>
cd genai-rag-chatbot
# Setup environment
cp .env.example .env
nano .env # Edit with your AWS credentials
# Deploy
docker-compose up --build -d
# Check status
docker-compose logs -f# Create runner directory
mkdir actions-runner && cd actions-runner
# Download runner
curl -o actions-runner-linux-x64-2.311.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.311.0/actions-runner-linux-x64-2.311.0.tar.gz
tar xzf ./actions-runner-linux-x64-2.311.0.tar.gz
# Configure runner (follow GitHub instructions)
./config.sh --url https://github.com/your-username/genai-rag-chatbot --token YOUR_TOKEN
# Install as service
sudo ./svc.sh install
sudo ./svc.sh start# Backend tests
cd backend
pytest tests/ -v
# Frontend tests (if implemented)
cd frontend
pytest tests/ -v
# Integration tests with Docker
docker-compose -f docker-compose.test.yml up --build# Check backend health
curl http://localhost:8000/health
# Check frontend health
curl http://localhost:8501/_stcore/health
# Check chat service health
curl http://localhost:8000/chat/health- AWS credentials are stored in environment variables only
- No hardcoded secrets in the codebase
- CORS is configured for frontend-backend communication
- Input validation and sanitization implemented
- Proper error handling without exposing sensitive information
- Structured logging throughout the application
- Health check endpoints for monitoring
- Docker container health checks
- Error tracking and reporting
Backend won't start:
- Check AWS credentials in
.envfile - Ensure ChromaDB directory has proper permissions
- Verify Docker containers can access environment variables
Frontend can't connect to backend:
- Check
BACKEND_URLin frontend environment - Ensure backend is running and healthy
- Verify network connectivity between containers
AWS Bedrock errors:
- Verify AWS credentials and region
- Check Bedrock model availability in your region
- Ensure proper IAM permissions for Bedrock access
Vector store issues:
- Check ChromaDB persistence directory permissions
- Verify documents are properly processed and embedded
- Monitor ChromaDB logs for errors
| Variable | Description | Example |
|---|---|---|
AWS_ACCESS_KEY_ID |
AWS access key for Bedrock | AKIA... |
AWS_SECRET_ACCESS_KEY |
AWS secret key | wJalrXUt... |
AWS_DEFAULT_REGION |
AWS region for Bedrock | us-east-1 |
BACKEND_URL |
Backend API URL for frontend | http://localhost:8000 |
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- AWS Bedrock for providing access to foundation models
- ChromaDB for the vector database solution
- FastAPI and Streamlit communities for excellent documentation
- The open-source community for various tools and libraries used
For questions or support, please contact me at fatulla@codage.az