Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸš‚ RailBook β€” Full Stack Railway Ticket Booking System

A complete, production-ready railway ticket booking application built with React + Spring Boot


πŸ“‹ Table of Contents


Project Overview

RailBook is a full-stack railway ticket booking system modelled after Indian Railways. Users can search trains across 20 city pairs, select seats visually, fill passenger details, and complete payment through Razorpay β€” all within a polished, responsive UI that supports both dark and light themes.


Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Browser                          β”‚
β”‚  React 18 + Vite  Β·  Tailwind CSS  Β·  React Router  β”‚
β”‚  http://localhost:5173                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚  REST API (JSON)
                     β”‚  Axios + JWT Bearer token
                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                Spring Boot 3.2                       β”‚
β”‚  JWT Auth Β· Spring Security Β· Spring Data JPA        β”‚
β”‚  http://localhost:8080                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚  JDBC / Hibernate ORM
                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              MySQL 8  (railbook_db)                  β”‚
β”‚  10 tables Β· Auto-created Β· Auto-seeded              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                     β”‚
    β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
    β”‚  Razorpay  β”‚       β”‚ Gmail SMTP  β”‚
    β”‚  Payments  β”‚       β”‚   Emails    β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Repository Layout

railbook/
β”œβ”€β”€ README.md                       ← This file (full project overview)
β”‚
β”œβ”€β”€ railbook-frontend/              ← React Frontend
β”‚   β”œβ”€β”€ README.md                   ← Frontend-specific README
β”‚   β”œβ”€β”€ public/train-icon.svg       ← Custom train SVG favicon
β”‚   β”œβ”€β”€ .env                        ← API URL + Razorpay Key ID
β”‚   └── src/
β”‚       β”œβ”€β”€ api/                    ← Axios wrappers (7 files)
β”‚       β”œβ”€β”€ components/             ← Reusable UI (7 components)
β”‚       β”œβ”€β”€ context/                ← Auth + Booking + Theme state
β”‚       β”œβ”€β”€ hooks/                  ← useAuth, useTheme
β”‚       β”œβ”€β”€ pages/                  ← 19 pages / routes
β”‚       └── utils/                  ← helpers.js
β”‚
└── railbook-backend/               ← Spring Boot Backend
    β”œβ”€β”€ README.md                   ← Backend-specific README
    β”œβ”€β”€ pom.xml
    └── src/main/
        β”œβ”€β”€ resources/
        β”‚   └── application.yml     ← All credentials & config
        └── java/com/railbook/
            β”œβ”€β”€ config/             ← Security, CORS, DataSeeder
            β”œβ”€β”€ controller/         ← 6 REST controllers
            β”œβ”€β”€ dto/                ← 9 request + 11 response DTOs
            β”œβ”€β”€ entity/             ← 10 JPA entities
            β”œβ”€β”€ enums/              ← 5 enums
            β”œβ”€β”€ exception/          ← 8 exception classes
            β”œβ”€β”€ repository/         ← 9 repositories
            β”œβ”€β”€ security/           ← JWT filter + entry point
            β”œβ”€β”€ service/            ← 6 interfaces + 7 implementations
            └── util/               ← 4 mappers + PnrGenerator

Feature List

User

  • Register with name, email, password, phone
  • Login with JWT access token (24h) + refresh token (7 days)
  • Auto token refresh on expiry
  • User profile dropdown with sign out

Train Discovery

  • Search trains by From / To / Date / Passengers / Class
  • Smart search β€” matches on city name OR station name (e.g. "Kolkata" finds "Kolkata Howrah")
  • Browse all trains with live text search + type filter + class filter + sort
  • 48 pre-seeded trains across 20 bidirectional Indian city pairs

Booking Flow

  1. Search β€” enter route + date
  2. Select Train β€” filter by class, sort by price/rating/departure
  3. Select Seats β€” choose 1–6 passengers, pick seats on visual coach map
  4. Passenger Details β€” name, age, gender, berth pref, ID proof per passenger
  5. Payment β€” Razorpay checkout (Card / UPI / Netbanking / Wallet)
  6. Confirmation β€” E-ticket with PNR, passenger table, fare breakdown, print/share

Post-Booking

  • My Bookings β€” full history with status badges
  • PNR Status β€” live lookup by PNR number
  • Cancel Ticket β€” lookup by PNR with confirmation prompt
  • Email confirmation on booking (Gmail SMTP)

UI / UX

  • Dark / Light theme toggle β€” persists to localStorage, respects system preference
  • Fully responsive β€” mobile, tablet, desktop
  • 6-step booking progress stepper
  • Sticky booking summary sidebar with live fare calculation
  • Debounced station autocomplete (300ms)
  • Loading spinners on all async operations
  • Form validation with per-field error messages

Pages

Home Β· All Trains Β· Trains (search results) Β· Seats Β· Passengers Β· Payment Β· Confirmation Β· Login Β· Register Β· My Bookings Β· PNR Status Β· Help (FAQ) Β· Cancel Ticket Β· Contact Β· Refund Policy Β· Terms Β· Privacy Β· 404


Tech Stack Summary

Frontend

Framework React 18.2 + Vite 5.1
Styling Tailwind CSS 3.4 (dark mode: class)
Routing React Router DOM 6.22
HTTP Axios 1.6 with JWT interceptor
Icons Lucide React 0.383
State React Context API (Auth + Booking + Theme)
Payment Razorpay JS checkout widget

Backend

Framework Spring Boot 3.2.3
Language Java 21
Security Spring Security 6.2 + JJWT 0.12.5
Database MySQL 8 via Spring Data JPA + Hibernate 6.4
Payment Razorpay Java SDK 1.4.5
Email Spring Mail (Gmail SMTP)
Build Maven 3.9

Quick Start

Step 1 β€” Backend

# 1. Set your credentials in application.yml
#    - spring.datasource.password
#    - app.razorpay.key-id + key-secret
#    - spring.mail.username + password

cd railbook-backend
mvn clean install
mvn spring-boot:run
# β†’ http://localhost:8080
# β†’ DB auto-created, 48 trains auto-seeded

Step 2 β€” Frontend

# 1. Set .env
#    VITE_API_BASE_URL=http://localhost:8080/api
#    VITE_RAZORPAY_KEY_ID=rzp_test_XXXXXXXXXXXXXXXX

cd railbook-frontend
npm install
npm run dev
# β†’ http://localhost:5173

Step 3 β€” Open Browser

Navigate to http://localhost:5173, register an account, and book a train.


Full Booking Flow

[Home]           Search: Delhi β†’ Kolkata, 2 passengers
    ↓
[Train List]     Pick Rajdhani Express, 3A class β†’ click Book
    ↓
[Seats]          Set passengers = 2, pick 2 seats from coach map
    ↓
[Passengers]     Fill details for Passenger 1 & 2 + contact info
                 β†’ POST /api/bookings β†’ creates PENDING booking, returns PNR
    ↓
[Payment]        Select UPI β†’ click Pay β‚Ή4,XXX
                 β†’ POST /api/payments/create-order β†’ Razorpay order created
                 β†’ Razorpay checkout opens
                 β†’ POST /api/payments/verify β†’ HMAC verified β†’ CONFIRMED
                 β†’ Confirmation email sent
    ↓
[Confirmation]   E-ticket shown with PNR, passenger list, fare breakdown

Seeded Data

Stations (15)

New Delhi (NDLS), Kolkata Howrah (HWH), Mumbai Central (MMCT), Chennai Central (MAS), Bangalore City (SBC), Hyderabad (HYB), Pune (PUNE), Chandigarh (CDG), Bhopal (BPL), Jaipur (JP), Prayagraj (ALD), Lucknow (LKO), Patna (PNBE), Bhubaneswar (BBS), Amritsar (ASR)

Train Classes

Code Name
SL Sleeper
3A AC 3-Tier
2A AC 2-Tier
1A First Class AC
CC Chair Car
EC Executive Chair Car

Environment Setup Checklist

Backend application.yml

  • spring.datasource.password β€” your MySQL password
  • app.jwt.secret β€” change to a secure 64-char secret in production
  • app.razorpay.key-id β€” from Razorpay Dashboard β†’ Settings β†’ API Keys
  • app.razorpay.key-secret β€” same location (never expose this)
  • spring.mail.username β€” your Gmail address
  • spring.mail.password β€” Gmail App Password (not your login password)

Frontend .env

  • VITE_API_BASE_URL=http://localhost:8080/api
  • VITE_RAZORPAY_KEY_ID=rzp_test_XXXXXX β€” Key ID only (not secret)

Razorpay Setup

  1. dashboard.razorpay.com β†’ Sign up
  2. Switch to Test Mode (top right toggle)
  3. Settings β†’ API Keys β†’ Generate Test Key
  4. Copy Key ID β†’ frontend .env AND backend application.yml
  5. Copy Key Secret β†’ backend application.yml ONLY

Gmail App Password

  1. Google Account β†’ Security β†’ 2-Step Verification (enable)
  2. Security β†’ App Passwords β†’ Generate
  3. Use the 16-char password in spring.mail.password

API Overview

Base URL: http://localhost:8080

All protected endpoints require: Authorization: Bearer <accessToken>

Domain Public Endpoints Protected Endpoints
Auth POST /register, /login, /refresh POST /logout
Users β€” GET/PUT /users/me
Trains POST /trains/search, GET /trains/all, /trains/{id}, /trains/{id}/seats β€”
Stations GET /stations, /stations/search β€”
Bookings GET /bookings/pnr/{pnr} POST /bookings, GET /bookings, PATCH /{pnr}/cancel
Payments β€” POST /payments/create-order, /payments/verify

Known Limitations

Item Details
Contact form UI only β€” no email service integrated yet
Seat locking Seats marked BOOKED on POST /bookings β€” no real-time lock between concurrent users
Payment Test mode only β€” use Razorpay test card 4111 1111 1111 1111
Email Requires Gmail App Password and 2FA enabled
No admin panel Admin role exists in DB but no admin UI built yet

Bug Fixes History

# Bug Fix
1 Login fails after 1–2 days with "Duplicate entry for refresh_tokens" @Modifying @Query deleteByUserId() ensures DELETE flushes before INSERT
2 All Trains page returns 400 Bad Request Removed @NotBlank/@NotNull from TrainSearchRequest
3 No trains found for Kolkata β†’ Delhi search DataSeeder now seeds 48 bidirectional trains; search also matches city name
4 Seat page always shows "Choose 1 seat" even for multi-passenger Added passenger count selector (1–6) directly on SeatsPage
5 Register page: white text on white input in dark mode Added text-slate-800 bg-white to all inputs in RegisterPage.jsx
6 OAuth2 removed All Google/GitHub OAuth2 code removed from both frontend and backend

Future Roadmap

  • Contact Us β€” integrate EmailJS or Spring Boot /api/contact endpoint
  • Admin panel β€” manage trains, view all bookings, update seat counts
  • Real-time seat locking β€” Redis-based seat hold with 10-minute expiry
  • Waitlist / RAC support
  • Ticket PDF download
  • SMS notification via Twilio
  • Multi-language support (Hindi)
  • PWA β€” offline mode and home screen install

About

πŸš‚ Full-stack railway ticket booking system built with React + Spring Boot + MySQL. Features JWT auth, Razorpay payments, visual seat selection, dark/light theme, and 48 pre-seeded Indian train routes.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages