Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš† Welcome to the Railway Ticket Booking System

Hey there! πŸ‘‹ I'm your ultimate railway ticket booking companion. Let me tell you what I can do for you...


What Am I All About? 🎯

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! πŸ›‘οΈ


What Can I Do For You? ✨

  • πŸ” 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/health endpoint 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.

What Powers Me? πŸ› 

My Frontend Brain (in client/)

  • 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

My Backend Heart (in server/)

  • 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

How I'm Organized πŸ“

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

Setting Me Up πŸš€

Step 0: MongoDB Setup

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 MongoDB

Or use MongoDB Atlas for cloud hosting: mongodb+srv://username:password@cluster.mongodb.net/railway_booking

Step 1: Configure Environment Variables

Backend (server/.env):

PORT=5000
MONGODB_URI=mongodb://localhost:27017/railway_booking

Frontend (client/.env):

VITE_API_URL=http://localhost:5000/api

Step 2: Install My Dependencies

# Backend
cd server
npm install

# Frontend
cd ../client
npm install

Step 3: Populate My Database

I come with pre-seeded trains (Rajdhani Express, Shatabdi Express, Duronto Express). Let's load them:

cd server
npm run seed

Step 4: Start Me Up! πŸŽ‰

Start 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


How to Talk to Me (API Reference) πŸ“‘

1️⃣ Check if I'm Alive

GET /api/health

Response:

{
  "status": "OK",
  "message": "Railway Booking API is running",
  "timestamp": "2026-09-13T12:45:00.000Z",
  "environment": "development"
}

2️⃣ Get All Trains

GET /api/trains

3️⃣ Search for Trains

GET /api/trains/search?from=Delhi&to=Mumbai&date=20/09/2026

Query Parameters:

  • from (required) β€” Source station
  • to (required) β€” Destination station
  • date (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
    }
  ]
}

4️⃣ Get Train Details

GET /api/trains/:id

See the train info and which seats are already booked.

5️⃣ Book a Ticket ✈️

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."
}

6️⃣ Retrieve Your Booking

GET /api/bookings/:bookingId

Example: GET /api/bookings/BK10234


My AWS Future 🌐

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)

Here's My Cloud Architecture:

  1. Route 53 β€” Global DNS routing
  2. Application Load Balancer β€” Distributes traffic, health checks via /api/health
  3. Auto Scaling Group β€” Automatically scales instances based on demand
  4. Multiple EC2 Instances β€” Stateless API servers across availability zones
  5. MongoDB Atlas β€” Managed cloud database with automatic failover
  6. CloudWatch β€” Monitoring and alerts
  7. AWS IAM β€” Security and access control
  8. GitHub Actions β€” Automated CI/CD pipeline for zero-downtime deployments

The Tech Stack at a Glance πŸ“Š

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

Quick Start TL;DR ⚑

# 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:5173

License πŸ“„

MIT License β€” Use me however you like! πŸŽ‰


Ready to book some trains? Let's go! πŸš†πŸ’¨

Built with ❀️ for seamless railway ticket reservations.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages