A modern, real-time train search application for Indian Railways built with React, TypeScript, and Tailwind CSS. Get live train information, check PNR status, track trains, and find seat availability.
- Real-time Train Search: Search trains between stations with live data
- Auto-suggestion Search: Intelligent station search with suggestions
- PNR Status Check: Check booking status with real-time updates
- Live Train Tracking: Track train location and delays
- Seat Availability: Check real-time seat availability for all classes
- Route Information: Complete train route with station details
- Mobile Responsive: Beautiful UI that works on all devices
- Refresh Functionality: Real-time data refresh throughout the app
- Multiple API Support: Fallback to multiple APIs for reliability
- Frontend: React 18 + TypeScript
- Styling: Tailwind CSS
- Build Tool: Vite
- Icons: Lucide React
- Date Picker: React DatePicker
- HTTP Client: Axios
- Routing: React Router DOM
-
Clone the repository
git clone <repository-url> cd train-search-app
-
Install dependencies
npm install
-
Set up environment variables Create a
.envfile in the root directory:# RapidAPI Configuration (Optional - for enhanced features) VITE_RAPIDAPI_KEY=your_rapidapi_key_here # Indian Railways API (Optional - for enhanced features) VITE_RAILWAY_API_KEY=your_railway_api_key_here # App Configuration VITE_APP_NAME=TrainSearch VITE_APP_VERSION=1.0.0
-
Start the development server
npm run dev
-
Open your browser Navigate to
http://localhost:5173
The app works out of the box with free APIs:
- Indian Railways Free API
- Alternative Railway APIs
For better features and reliability, you can add:
- Sign up at RapidAPI
- Subscribe to "Indian Railways API"
- Get your API key
- Add to
.env:VITE_RAPIDAPI_KEY=your_key
- Visit Railway API
- Register and get API key
- Add to
.env:VITE_RAILWAY_API_KEY=your_key
- Enter source and destination stations (with auto-suggestions)
- Select journey date
- Click "Search Trains"
- View results with real-time availability
- Use filters to narrow down results
- Enter 10-digit PNR number
- Click "Check"
- View booking status and passenger details
- Refresh for latest updates
- Enter train number
- Click "Check"
- View current location and delays
- Switch to "Complete Route" tab for full journey
- Select a train from search results
- Click "Check Availability"
- Select travel class
- View real-time availability and fares
The app includes refresh buttons throughout:
- Station Search: Refresh suggestions
- Train Search: Refresh results
- PNR Status: Refresh booking status
- Live Status: Refresh train location
- Seat Availability: Refresh availability data
The app is fully responsive and optimized for:
- Mobile phones
- Tablets
- Desktop computers
- Touch interfaces
- Apple-inspired Design: Clean, modern interface
- Smooth Animations: Loading states and transitions
- Intuitive Navigation: Easy-to-use interface
- Error Handling: User-friendly error messages
- Loading States: Visual feedback during API calls
- Auto-suggestions: Smart station search
The app includes comprehensive error handling:
- Network connectivity issues
- API rate limiting
- Invalid inputs
- No results found
- Server errors
# Required for enhanced features
VITE_RAPIDAPI_KEY=your_key_here
VITE_RAILWAY_API_KEY=your_key_here
# Optional app configuration
VITE_APP_NAME=TrainSearch
VITE_APP_VERSION=1.0.0The app automatically tries multiple APIs in order:
- Free Indian Railways API
- RapidAPI (if configured)
- Railway API (if configured)
- Alternative free APIs
GET /trains?from=NDLS&to=BCT&date=2024-01-15
GET /stations?q=delhi
GET /pnr?pnr=1234567890
GET /live-status?train=12301
GET /route?train=12301
GET /availability?train=12301&from=NDLS&to=BCT&date=2024-01-15&class=SL
- Push code to GitHub
- Connect repository to Vercel
- Add environment variables in Vercel dashboard
- Deploy automatically
- Build the project:
npm run build - Upload
distfolder to Netlify - Add environment variables in Netlify dashboard
The app can be deployed to any static hosting platform:
- GitHub Pages
- Firebase Hosting
- AWS S3
- Cloudflare Pages
-
"API key not configured"
- Check your
.envfile - Ensure environment variables are loaded
- Restart the development server
- Check your
-
"No trains found"
- Verify station names are correct
- Check if the train runs on selected date
- Try different date ranges
-
"Rate limit exceeded"
- Upgrade to paid plan
- Use multiple API providers
- Implement caching
-
"Network error"
- Check internet connection
- Verify API endpoints are accessible
- Check CORS settings
- Check the browser console for error messages
- Verify API keys are correct
- Test with Postman or similar tools
- Check API documentation
- Contact API providers for support
- Fast Loading: Optimized bundle size
- Caching: Intelligent API response caching
- Retry Logic: Automatic retry on API failures
- Fallback APIs: Multiple API providers for reliability
- Environment Variables: API keys stored securely
- Input Validation: All user inputs validated
- Error Handling: No sensitive data exposed in errors
- HTTPS Only: Secure API communications
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Indian Railways for providing train data
- RapidAPI for API marketplace
- Vercel for hosting free APIs
- Open source community for tools and libraries
For support and questions:
- Create an issue on GitHub
- Check the API_SETUP.md file
- Review the troubleshooting section
Happy traveling! πβ¨