Hey there! π I'm your ultimate railway ticket booking companion. Let me tell you what I can do for you...
Picture this: You're planning a trip, scrolling through trains, picking your perfect seat, and in secondsβboom! π« Your ticket is confirmed with a beautiful digital receipt. That's me! I'm a full-stack, production-ready web application built to make railway ticket reservations smooth, fast, and incredibly reliable.
I'm powered by React (Vite) on the frontend, Node.js/Express.js APIs on the backend, and MongoDB for rock-solid data management. Oh, and I'm engineered with atomic seat reservations so you never get that dreaded "Seat already booked" moment when you're buying from two different browsers! π‘οΈ
- π Search Trains Like a Pro: Find trains by origin, destination, and travel date. I even handle case-insensitive searches because I'm smart like that!
- π Real-Time Seat Availability: See exactly how many seats are available (Available, Low Availability, or Sold Out). No surprises!
- πΊ Pick Your Perfect Seat: Choose your exact seat number interactively. See which seats are booked vs. free with visual feedback. You're in control!
- π Atomic Concurrency Protection: No double-booking nightmares! I use database-level atomic operations so even if 1000 people click at the same time, you're protected.
- π« Digital Ticket Confirmation: Get a beautiful ticket with your unique Booking ID (like
BK10234), complete with barcodes, journey details, and print/download options. - π Find Your Ticket Fast: Lost your booking? No problem! Use the PNR lookup modal to retrieve your ticket by Booking ID in seconds.
- βοΈ AWS-Ready: I come with a
/api/healthendpoint built for AWS Application Load Balancers, because I'm enterprise-grade! - π± Gorgeous UI: Clean travel theme with deep navy and azure colors, card layouts, mobile-friendly navigation, and helpful error messages.
- React 18 β Modern UI components
- Vite β Lightning-fast development and builds
- React Router DOM v6 β Smooth client-side navigation (
/,/results,/booking/:trainId,/confirmation/:bookingId) - Axios β Reliable API communication
- Lucide React β Beautiful icons
- CSS3 β Responsive, custom-designed, print-friendly styling
- Node.js β Asynchronous, event-driven runtime
- Express.js β RESTful API framework
- MongoDB & Mongoose β NoSQL database with ODM
- CORS β Cross-origin request handling
- Dotenv β Environment variable management
railway-ticket-booking/
β
βββ client/ # Frontend React app
β βββ src/
β β βββ components/
β β β βββ Navbar.jsx # Top bar + PNR lookup
β β β βββ Footer.jsx # Footer with HA badge
β β β βββ TrainCard.jsx # Train card display
β β β βββ SearchForm.jsx # Station & date picker
β β β βββ BookingForm.jsx # Passenger form & seat picker
β β β
β β βββ pages/
β β β βββ Home.jsx # Landing page
β β β βββ SearchResults.jsx # Search results view
β β β βββ Booking.jsx # Booking page
β β β βββ Confirmation.jsx # Ticket confirmation
β β β
β β βββ services/
β β β βββ api.js # API wrapper
β β β
β β βββ App.jsx # Routes configuration
β β βββ main.jsx # Entry point
β β βββ index.css # Styles
β β
β βββ .env # Frontend config
β βββ package.json
β βββ vite.config.js
β
βββ server/ # Backend Express app
β βββ config/
β β βββ db.js # MongoDB connection
β β
β βββ controllers/
β β βββ trainController.js # Train logic
β β βββ bookingController.js # Booking logic
β β
β βββ models/
β β βββ Train.js # Train schema
β β βββ Booking.js # Booking schema
β β
β βββ routes/
β β βββ trainRoutes.js # /api/trains endpoints
β β βββ bookingRoutes.js # /api/bookings endpoints
β β
β βββ seed/
β β βββ seedTrains.js # Initial data seeding
β β
β βββ .env # Backend config
β βββ package.json
β βββ server.js # Entry point
β
βββ .gitignore
βββ README.md
First, I need a database to store all those bookings! Make sure MongoDB is running:
# On Windows: Check if MongoDB is running
Get-Service *mongo*
# Start MongoDB if it's not running
net start MongoDBOr use MongoDB Atlas for cloud hosting: mongodb+srv://username:password@cluster.mongodb.net/railway_booking
Backend (server/.env):
PORT=5000
MONGODB_URI=mongodb://localhost:27017/railway_bookingFrontend (client/.env):
VITE_API_URL=http://localhost:5000/api# Backend
cd server
npm install
# Frontend
cd ../client
npm installI come with pre-seeded trains (Rajdhani Express, Shatabdi Express, Duronto Express). Let's load them:
cd server
npm run seedStart the Backend (runs on port 5000):
cd server
npm run devβ
Server: http://localhost:5000
β
Health check: http://localhost:5000/api/health
Start the Frontend (runs on port 5173):
cd client
npm run devβ
Open: http://localhost:5173
GET /api/healthResponse:
{
"status": "OK",
"message": "Railway Booking API is running",
"timestamp": "2026-09-13T12:45:00.000Z",
"environment": "development"
}GET /api/trainsGET /api/trains/search?from=Delhi&to=Mumbai&date=20/09/2026Query Parameters:
from(required) β Source stationto(required) β Destination stationdate(optional) β Travel date (DD/MM/YYYY)
Example Response:
{
"success": true,
"count": 3,
"searchCriteria": {
"from": "Delhi",
"to": "Mumbai",
"date": "20/09/2026"
},
"data": [
{
"_id": "670f...",
"name": "Rajdhani Express",
"trainNumber": "12952",
"from": "Delhi",
"to": "Mumbai",
"departureTime": "10:00 PM",
"arrivalTime": "08:00 AM",
"availableSeats": 42,
"totalSeats": 60,
"price": 2150
}
]
}GET /api/trains/:idSee the train info and which seats are already booked.
POST /api/bookings
Content-Type: application/json
{
"trainId": "670f...",
"passengerName": "Krishna",
"age": 21,
"seatNumber": 23
}Response (201 Created):
{
"success": true,
"message": "Booking confirmed successfully!",
"booking": {
"bookingId": "BK10234",
"trainId": "670f...",
"trainName": "Rajdhani Express",
"from": "Delhi",
"to": "Mumbai",
"passengerName": "Krishna",
"age": 21,
"seatNumber": 23,
"createdAt": "2026-09-13T12:45:30.120Z"
}
}If seat is already booked (409 Conflict):
{
"success": false,
"message": "Seat 23 is already booked. Please select another seat."
}GET /api/bookings/:bookingIdExample: GET /api/bookings/BK10234
I'm designed to scale! Here's how I'll run in the cloud:
[ Users ]
β
βΌ
[ Amazon Route 53 ]
β
βΌ
[ Application Load Balancer ]
β
ββββββββββββββββ΄βββββββββββββββ
βΌ βΌ
[ Availability Zone A ] [ Availability Zone B ]
[ EC2: Node.js API ] [ EC2: Node.js API ]
[ Auto Scaling Group ] [ Auto Scaling Group ]
β β
ββββββββββββββββ¬βββββββββββββββ
βΌ
[ MongoDB Atlas Cluster ]
(Multi-AZ Replica Set)
- Route 53 β Global DNS routing
- Application Load Balancer β Distributes traffic, health checks via
/api/health - Auto Scaling Group β Automatically scales instances based on demand
- Multiple EC2 Instances β Stateless API servers across availability zones
- MongoDB Atlas β Managed cloud database with automatic failover
- CloudWatch β Monitoring and alerts
- AWS IAM β Security and access control
- GitHub Actions β Automated CI/CD pipeline for zero-downtime deployments
| Component | Technology |
|---|---|
| Frontend | React 18 + Vite + React Router v6 |
| Backend | Node.js + Express.js |
| Database | MongoDB + Mongoose |
| API Communication | Axios + REST |
| Styling | CSS3 + Custom Design |
| Icons | Lucide React |
| State Management | React Hooks |
| Environment | Dotenv |
| Infrastructure | AWS (ALB, ASG, EC2, RDS/Atlas) |
| CI/CD | GitHub Actions |
# 1. Setup MongoDB
net start MongoDB
# 2. Backend setup
cd server
npm install
npm run seed
npm run dev
# 3. Frontend setup (new terminal)
cd client
npm install
npm run dev
# 4. Open browser
# http://localhost:5173MIT License β Use me however you like! π
Ready to book some trains? Let's go! ππ¨
Built with β€οΈ for seamless railway ticket reservations.