Skip to content

akshaya-cp/J_Backend-Final

Repository files navigation

🚆 Train Booking System (Java CLI Project)

A clean and modular Train Ticket Booking System built in Java using a file-based JSON persistence layer. Designed to demonstrate strong fundamentals in OOP, file handling, CLI-based interaction, password encryption, and service-layer design — all without any external database or UI.


✨ Key Features

  • User Sign-up & Login (with password hashing using BCrypt)
  • Search trains by source and destination
  • Live seat selection and booking
  • View all personal bookings
  • Cancel ticket by Ticket ID
  • File-based JSON persistence
  • Clean Low-Level Design (LLD) structure with modular services

🧱 Low-Level Design (LLD Overview)

👤 User

  • name (String)
  • password (String, stored hashed)
  • hashedPassword (String)
  • ticketsBooked (List<Ticket>)
  • userId (UUID)

🎟️ Ticket

  • ticketId (UUID)
  • userId (UUID)
  • source (String)
  • destination (String)
  • dateOfTravel (ZonedDateTime)
  • train (Train)

🚂 Train

  • trainId (String)
  • trainNo (String)
  • seats (List<List<Integer>> - 2D layout)
  • stations (List<String>)
  • stationTimes (Map<StationName, Time>)

🛠 Tech Stack

Component Technology
Language Java 21
Build Tool Gradle
JSON Handling Jackson + jsr310 (for time)
Password Hash BCrypt (secure authentication)
Boilerplate Lombok (getter/setter cleanup)
Data Storage JSON (no external DB used)

⚙️ How It Works

🔐 Signup & Login

  • Users sign up with a password (hashed before saving).
  • On login, password is verified using BCrypt.checkpw().

🔎 Train Search

  • Trains are filtered by matching source and destination (in correct order).

💺 Seat Booking

  • Available seats are shown in a 2D matrix.
  • Seat is marked 1 when booked.

📂 Booking Persistence

  • Bookings are saved in users.json.
  • Seat availability updates in trains.json.

❌ Cancel Ticket

  • User enters ticket ID to cancel.
  • Ticket is removed from their booking list.

🚀 Getting Started

1. Clone the Repository

git clone https://github.com/yourusername/train-booking-java.git
cd train-booking-java

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages