A modern, full-stack train ticket booking platform with secure authentication, payment processing, and real-time seat selection.
Features • Tech Stack • Quick Start • Documentation • Screenshots • API Docs
The Train Reservation System is an enterprise-grade web application designed to streamline train ticket booking. Built with Spring Boot and React, it provides a seamless experience for users to search trains, book tickets, make payments, and manage reservations. Administrators have full control over train schedules, stations, and system operations.
- 🔐 Secure Authentication: JWT + OAuth2 (Google) with BCrypt password encryption
- 💳 Payment Integration: Simulated payment gateway with retry mechanism
- 🎫 Real-time Seat Selection: Interactive coach layout with availability status
- 👥 Role-Based Access: Separate user and admin dashboards
- 📱 Responsive Design: Mobile-first UI built with Tailwind CSS
- 🚀 RESTful APIs: 30+ endpoints with comprehensive documentation
- ⚡ Modern Stack: Spring Boot 3.2, React 18, PostgreSQL 15
- Search trains by source, destination, and date
- View real-time seat availability
- Interactive seat selection with visual coach layout
- Multiple coach types (Sleeper, AC, General)
- Instant booking confirmation with PNR generation
- Card payment processing
- Test card support for development
- Payment retry mechanism for failed transactions
- Transaction history tracking
- Automatic refund on cancellation
- View all past and upcoming bookings
- Real-time booking status tracking (Pending, Confirmed, Cancelled)
- Easy cancellation with instant refunds
- Download ticket receipts
- Email notifications (coming soon)
- Email/Password registration and login
- Google OAuth2 single sign-on
- Automatic token refresh for seamless sessions
- Secure password reset (coming soon)
- Add, edit, and delete train schedules
- Manage train routes and timings
- Configure coach types and seat layouts
- Set pricing for different classes
- Real-time availability monitoring
- Create and manage stations
- Update station codes and locations
- Configure operational status
- Total trains, users, and bookings statistics
- Recent booking activity
- Revenue tracking (coming soon)
- User engagement metrics (coming soon)
| Technology | Version | Purpose |
|---|---|---|
| Spring Boot | 3.2.1 | Application framework |
| Spring Security | 6.x | Authentication & authorization |
| Spring Data JPA | 3.2.x | ORM and database operations |
| PostgreSQL | 15+ | Relational database |
| JJWT | 0.12.3 | JWT token generation/validation |
| BCrypt | - | Password hashing |
| Maven | 3.8+ | Build tool |
| Java | 17/21 | Programming language |
| Technology | Version | Purpose |
|---|---|---|
| React | 18.2.0 | UI library |
| Vite | 5.1.0 | Build tool & dev server |
| React Router | 6.22.0 | Client-side routing |
| Axios | 1.6.7 | HTTP client |
| Tailwind CSS | 3.4.1 | Utility-first styling |
| Lucide React | 0.315.0 | Icon library |
| date-fns | 3.3.1 | Date manipulation |
- Git: Version control
- PostgreSQL: Database management
- Postman: API testing
- VS Code: Development environment
Before you begin, ensure you have the following installed:
- Java: JDK 17 or 21
- Maven: 3.8+
- Node.js: 18+
- npm: 9+
- PostgreSQL: 15+
- Git: Latest version
git clone https://github.com/your-username/train-reservation-system.git
cd train-reservation-system# Login to PostgreSQL
psql -U postgres
# Create database
CREATE DATABASE train_reservation_db;
# Exit psql
\q
# Run initialization script
psql -U postgres -d train_reservation_db -f database/init.sqlcd backend
# Edit application.properties
# Replace database credentials and JWT secret
nano src/main/resources/application.propertiesImportant: Update these properties:
# Database
spring.datasource.url=jdbc:postgresql://localhost:5432/train_reservation_db
spring.datasource.username=YOUR_DB_USERNAME
spring.datasource.password=YOUR_DB_PASSWORD
# JWT Secret (Generate a strong secret)
jwt.secret=YOUR_256_BIT_SECRET_KEY_HERE
# OAuth2 Google (Get from Google Cloud Console)
spring.security.oauth2.client.registration.google.client-id=YOUR_CLIENT_ID
spring.security.oauth2.client.registration.google.client-secret=YOUR_CLIENT_SECRET# Build and run
mvn clean install
mvn spring-boot:run
# Backend runs on http://localhost:8080cd ../frontend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env (optional - defaults to localhost:8080)
nano .envnpm run dev
# Frontend runs on http://localhost:5173- Frontend: http://localhost:5173
- Backend API: http://localhost:8080/api
- Swagger UI (if configured): http://localhost:8080/swagger-ui.html
Email: user@example.com
Password: User@123
Email: admin@example.com
Password: Admin@123
Success: 4111 1111 1111 1111
Failure: 4000 0000 0000 0002
CVV: Any 3 digits
Expiry: Any future date
| Document | Description |
|---|---|
| API Documentation | Complete REST API reference with examples |
| Backend README | Backend architecture and setup guide |
| Frontend README | Frontend components and features |
| Quick Start Guide | 5-minute setup tutorial |
| Security Guide | Authentication and authorization details |
| Payment Module | Payment processing implementation |
| Implementation Summary | Technical implementation details |
train-reservation-system/
├── backend/ # Spring Boot Application
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/com/trainreservation/
│ │ │ │ ├── config/ # Configuration classes
│ │ │ │ ├── controller/ # REST Controllers
│ │ │ │ ├── dto/ # Data Transfer Objects
│ │ │ │ ├── entity/ # JPA Entities
│ │ │ │ ├── repository/ # Spring Data Repositories
│ │ │ │ ├── security/ # Security components
│ │ │ │ └── service/ # Business logic
│ │ │ └── resources/
│ │ │ └── application.properties
│ │ └── test/ # Unit & Integration tests
│ └── pom.xml
│
├── frontend/ # React Application
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ │ ├── common/ # Buttons, Inputs, Cards, etc.
│ │ │ └── layout/ # Navbar, Footer
│ │ ├── contexts/ # React Context (Auth)
│ │ ├── pages/ # Page components
│ │ │ ├── auth/ # Login, Register
│ │ │ ├── bookings/ # Booking management
│ │ │ ├── trains/ # Train search & seats
│ │ │ └── admin/ # Admin dashboard
│ │ ├── services/ # API service layer
│ │ └── App.jsx # Root component
│ ├── package.json
│ └── vite.config.js
│
├── database/
│ └── init.sql # Database initialization
│
├── documentation/ # Comprehensive docs
│ ├── API_DOCUMENTATION.md
│ ├── BACKEND_README.md
│ ├── SECURITY_GUIDE.md
│ └── PAYMENT_MODULE.md
│
└── README.md # This file
Clean, modern homepage with hero section and feature highlights
Search trains with source, destination, and date filters
Interactive coach layout with real-time seat availability
Secure payment form with test card support
User dashboard showing all bookings with status tracking
Administrative panel with statistics and management tools
CRUD operations for train schedules and routes
Fully responsive design on mobile devices
POST /api/auth/register # Register new user
POST /api/auth/login # Login with credentials
POST /api/auth/refresh # Refresh access token
GET /api/auth/me # Get current user
GET /api/auth/google # Google OAuth2 login URLGET /api/trains/search # Search trains
GET /api/trains/{id} # Get train by ID
GET /api/trains # Get all trains (Admin)
POST /api/trains # Create train (Admin)
PUT /api/trains/{id} # Update train (Admin)
DELETE /api/trains/{id} # Delete train (Admin)
GET /api/trains/{id}/seats # Get available seatsPOST /api/bookings # Create new booking
GET /api/bookings/{id} # Get booking by ID
GET /api/bookings/user/{userId} # Get user bookings
GET /api/bookings/pnr/{pnr} # Get booking by PNR
PUT /api/bookings/{id}/cancel # Cancel booking
GET /api/bookings # Get all bookings (Admin)POST /api/payments/process # Process payment
POST /api/payments/retry # Retry failed payment
GET /api/payments/{transactionId} # Get payment details
GET /api/payments/booking/{bookingId} # Get payment by booking
POST /api/payments/refund # Refund payment (Admin)GET /api/stations # Get all stations
GET /api/stations/{id} # Get station by ID
POST /api/stations # Create station (Admin)
PUT /api/stations/{id} # Update station (Admin)
DELETE /api/stations/{id} # Delete station (Admin)curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "User@123"
}'{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"email": "user@example.com",
"fullName": "John Doe",
"role": "USER"
}
}For complete API documentation with request/response schemas, see API_DOCUMENTATION.md.
┌──────────────┐ HTTP/HTTPS ┌──────────────┐
│ │ ← REST API Calls → │ │
│ React │ │ Spring Boot │
│ Frontend │ ← JWT in Headers → │ Backend │
│ (Port 5173) │ │ (Port 8080) │
└──────────────┘ └───────┬──────┘
│
│ JDBC
│
┌───────▼──────┐
│ │
│ PostgreSQL │
│ Database │
│ │
└──────────────┘
┌─────────────────────────────────────────────────────────┐
│ Security Layer │
│ • JWT Authentication Filter │
│ • OAuth2 Success Handler │
│ • CORS Configuration │
└────────────────────┬────────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────────┐
│ Controller Layer │
│ • REST Endpoints │
│ • Request Validation │
│ • Response Formatting │
└────────────────────┬────────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────────┐
│ Service Layer │
│ • Business Logic │
│ • Transaction Management │
│ • DTO Mapping │
└────────────────────┬────────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────────┐
│ Repository Layer │
│ • Spring Data JPA │
│ • Custom Queries │
│ • Database Operations │
└────────────────────┬────────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────────┐
│ Database │
│ • PostgreSQL │
│ • 10+ Tables with Relationships │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ App.jsx │
│ • BrowserRouter │
│ • AuthProvider (Context) │
└────────────────────┬────────────────────────────────────┘
│
┌────────────┼────────────┐
│ │ │
▼ ▼ ▼
┌────────┐ ┌─────────┐ ┌─────────┐
│ Layout │ │ Routes │ │Services │
│ Components│ │(Pages) │ │ Layer │
└────────┘ └─────────┘ └─────────┘
- JWT Tokens: Stateless authentication with access & refresh tokens
- BCrypt Hashing: Passwords hashed with 12 rounds
- OAuth2: Google Sign-In integration
- Role-Based Access: USER and ADMIN roles with method-level security
- Token Refresh: Automatic token renewal on expiration
- CORS: Configured for allowed origins
- CSRF Protection: Disabled for stateless JWT approach
- Input Validation: Bean Validation with custom constraints
- SQL Injection Prevention: Parameterized queries via JPA
- XSS Protection: Frontend sanitization
- HTTPS: SSL/TLS encryption in production
- Secure Headers: X-Frame-Options, X-XSS-Protection
- Password Policy: Minimum length, complexity requirements
- Session Management: Stateless with JWT
# Backend tests
cd backend
mvn test
# Frontend tests
cd frontend
npm test
# Integration tests
mvn verify- Unit Tests: Service layer logic
- Integration Tests: API endpoints with Testcontainers
- E2E Tests: Complete user flows (coming soon)
mvn clean package
java -jar target/train-reservation-backend-1.0.0.jar# Build image
docker build -t train-reservation-backend .
# Run container
docker run -p 8080:8080 \
-e DATABASE_URL=jdbc:postgresql://host.docker.internal:5432/train_reservation_db \
-e DATABASE_USERNAME=postgres \
-e DATABASE_PASSWORD=yourpassword \
-e JWT_SECRET=your-secret-key \
train-reservation-backendcd frontend
npm run build# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prodCreate a .env file in production:
# Backend
DATABASE_URL=jdbc:postgresql://your-db-host:5432/train_reservation_db
DATABASE_USERNAME=your-db-user
DATABASE_PASSWORD=your-db-password
JWT_SECRET=your-256-bit-secret-key
JWT_EXPIRATION=86400000
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
FRONTEND_URL=https://your-frontend-domain.com
# Frontend
VITE_API_BASE_URL=https://your-backend-domain.comContributions are welcome! Please follow these steps:
- 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
- Follow Java Code Conventions for backend
- Use ESLint/Prettier for frontend
- Write meaningful commit messages
- Add tests for new features
- Update documentation
Issue: Backend fails to start - "Port 8080 already in use"
# Find process using port 8080
lsof -i :8080
# Kill the process
kill -9 <PID>Issue: Database connection refused
# Check PostgreSQL is running
sudo service postgresql status
# Start if not running
sudo service postgresql startIssue: Frontend can't connect to backend
# Check VITE_API_BASE_URL in .env
echo $VITE_API_BASE_URL
# Should be http://localhost:8080Issue: JWT token expired error
- Tokens expire after 24 hours. Login again or use refresh token endpoint.
Issue: OAuth2 redirect fails
- Verify Google OAuth2 credentials in application.properties
- Check redirect URI is registered in Google Cloud Console
For more help, see QUICKSTART.md or open an issue.
- Email notifications for booking confirmation
- SMS alerts for journey updates
- Passenger multiple selection
- Ticket download as PDF
- Seat preference (window, aisle)
- Waitlist management
- Real-time train tracking
- Reviews and ratings
- Mobile app (React Native)
- AI-based seat recommendations
- Dynamic pricing
- Loyalty program
- Multi-language support
- Accessibility improvements
- Analytics dashboard
- Integration with real payment gateways
This project is licensed under the MIT License - see the LICENSE file for details.
Your Name
- GitHub: @your-username
- LinkedIn: Your Profile
- Email: your.email@example.com
- Portfolio: yourportfolio.com
- Spring Boot Team for the excellent framework
- React Team for the powerful UI library
- Tailwind CSS for the utility-first styling approach
- JWT.io for token implementation guidance
- PostgreSQL for the robust database
- All open-source contributors whose libraries made this project possible
If you found this project helpful, please consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs or issues
- 💡 Suggesting new features
- 🔀 Contributing code improvements
- 📢 Sharing with others
Made with ❤️ and ☕







