A comprehensive bus ticket booking system with AI-powered search capabilities, built using FastAPI and a RAG (Retrieval-Augmented Generation) pipeline for intelligent query handling.
This application allows users to:
- π Search for buses using natural language queries
- π« Book tickets with basic information (name and phone number)
- π View and manage their bookings
- π Access detailed bus provider information (routes, fares, policies, contact details)
- π¬ Ask questions about bus services and get AI-powered responses
- RAG Pipeline Integration: Uses LangChain with Google Generative AI for intelligent query processing
- Vector Search: ChromaDB with sentence transformers for semantic search capabilities
- Natural Language Queries: Ask questions like "Are there any buses from Dhaka to Rajshahi under 500 taka?"
- SQLite Database: Reliable booking data persistence
- JSON-based Route Data: Flexible data management for districts, routes, and providers
- Complete CRUD Operations: Create, read, update, and delete bookings
- HTML/CSS/JS Frontend: Served directly by FastAPI via static files and Jinja2 templates
Bus-ticket-booking-application/
β
βββ backend/
β βββ main.py # FastAPI application entry point
β βββ database.py # SQLite database configuration
β βββ models.py # Pydantic models
β βββ rag_pipeline.py # RAG implementation
β βββ data_loader.py # Data loading utilities
β
βββ static/
β βββ css/
β β βββ style.css # Application styles
β βββ js/
β βββ main.js # Frontend JavaScript
β
βββ templates/ # Jinja2 HTML templates
β
βββ data.json # Main data file (routes, districts, providers)
β
βββ attachments/
β βββ hanif.txt # Hanif bus provider information
β βββ ena.txt # Ena bus provider information
β βββ ... # Other bus provider files
β
βββ bus_booking.db # SQLite database (auto-generated)
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker build instructions
βββ docker-compose.yaml # Docker Compose configuration
βββ .env # Environment variables (create this)
βββ README.md # This file
- Docker Desktop installed and running
git clone https://github.com/yourusername/Bus-ticket-booking-application.git
cd Bus-ticket-booking-applicationCreate a .env file in the root directory:
GOOGLE_API_KEY=your_google_api_key_here
DATABASE_PATH=./bus_booking.db
CHROMA_PERSIST_DIRECTORY=./chroma_dbTo get a Google API Key: Visit Google AI Studio, create a new key, and paste it above.
docker compose up --build| Service | URL |
|---|---|
| Web Frontend | http://localhost:8000 |
| FastAPI Swagger Docs | http://localhost:8000/docs |
| FastAPI Redoc | http://localhost:8000/redoc |
- Python 3.10
- pip
git clone https://github.com/yourusername/Bus-ticket-booking-application.git
cd Bus-ticket-booking-application
python -m venv venvActivate β Windows:
venv\Scripts\activateActivate β Mac/Linux:
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the root directory:
GOOGLE_API_KEY=your_google_api_key_here
DATABASE_PATH=./bus_booking.db
CHROMA_PERSIST_DIRECTORY=./chroma_dbuvicorn backend.main:app --reload --port 8000Then open http://localhost:8000 in your browser.
The image is based on python:3.10-slim-bookworm (Debian 12) which satisfies ChromaDB's sqlite3 >= 3.35 requirement. Key points:
numpy==1.26.4andtorch==2.1.0+cpuare installed first to prevent version conflicts- The full LangChain stack is pinned to ensure compatibility
libgomp1is included for PyTorch CPU threading support- FastAPI serves both the API and the HTML/CSS/JS frontend on a single port
8000
# Build and start
docker compose up --build
# Start in detached mode (background)
docker compose up -d --build
# View logs
docker compose logs -f
# Stop the application
docker compose down
# Stop and remove volumes
docker compose down -v
# Rebuild from scratch
docker compose build --no-cache
docker compose up# View running containers
docker ps
# View container logs
docker logs <container_name>
# Remove stopped containers
docker container prune
# Remove unused images
docker image prune- Data Ingestion β Bus provider information and route data are loaded from
data.jsonand.txtfiles inattachments/ - Embedding Generation β Sentence transformers convert text into vector embeddings
- Vector Storage β ChromaDB stores embeddings for fast semantic search
- Query Processing β User questions are embedded and matched against stored vectors
- Context Retrieval β Relevant information is retrieved from the vector database
- Response Generation β Google Generative AI (Gemini) generates natural language responses based on retrieved context
- "Are there any buses from Dhaka to Rajshahi under 500 taka?"
- "Show all bus providers operating from Chittagong to Sylhet."
- "What are the contact details of Hanif Bus?"
- "Can I cancel my booking for the bus from Dhaka to Barishal on 15th November?"
- "What is the privacy policy of Ena Paribahan?"
- "Which bus is cheapest from Dhaka to Cox's Bazar?"
Port already in use
# Windows β find and kill the process
netstat -ano | findstr :8000
taskkill /PID <PID> /FGoogle API Key Error
- Ensure your
.envfile contains a validGOOGLE_API_KEY - Check that the key has access to Generative AI services
ChromaDB sqlite3 Error (local only)
- Use Python 3.10+ and ensure your system sqlite3 is >= 3.35
- The Docker image handles this automatically via the
bookwormbase image
ChromaDB Permission Error
- Delete the
chroma_dbdirectory and restart the application
Database Locked
- Close any other processes accessing the SQLite database and restart the server
Module Not Found
- Ensure your virtual environment is activated
- Run
pip install -r requirements.txtagain
This project is open source and available under the MIT License.
Built with: FastAPI β’ HTML/CSS/JS β’ LangChain β’ Google Generative AI β’ ChromaDB β’ SQLite β’ Docker