railease-railway-booking-system: RailEase Is a Train Booking App That Ships Its Own Confession Folder

A Spring Boot portfolio project where a fixed/ directory, a plaintext Gmail password, and a race condition on the last seat reveal what real reservation systems get wrong.

9 min read • View on GitHub • More from shivangikamadiya

A wide editorial illustration of a railway platform departure board seen from a distance, with a cutaway view of a single train seat beneath it. Two arms reach toward that seat from opposite edges of the frame, and a station clock above shows the same minute twice.
Two travelers, one seat. Every booking system is a fight over the same row in a database, and RailEase is honest enough to show the fight.
Key Takeaways

Most portfolio repositories get cleaned before they are published. Branches squashed, scratch files deleted, the messy middle erased. RailEase did not do that. Open the file tree and there is a directory named fixed/ sitting beside src/, outside the build path entirely, holding alternate versions of the app's most important classes.

The Folder That Shouldn't Exist

railease-railway-booking-system/
├── src/main/java/com/railease/...
├── fixed/
│   ├── BookingControllerSafe.java
│   ├── BookingServiceImplFixed2.java
│   ├── TrainFixed.java
│   └── TrainNoTicketPrice.java
├── sql/
│   ├── fix-database-issues.sql
│   └── fix-train-fares.sql
├── fix_fare.ps1
├── TODO.md
├── TODONE.md
└── 0)

The filenames tell the story. BookingControllerSafe implies a BookingController that was not safe. BookingServiceImplFixed2 implies a first fix that did not hold. fix_fare.ps1 is a PowerShell patch script at the root of a Java web application. And 0) is a file whose entire name is a keyboard slip that someone committed and never removed.

This is not carelessness for its own sake. It is a working document left in public, which makes it more instructive than a polished one. You can read the order in which the author found problems, because the evidence is still in the tree. The rest of this article asks the obvious question: what was being fixed?

The Race for the Last Seat

The class the fixed/ folder is chasing is BookingController.confirmBooking. It handles the moment a passenger commits to a seat, and it does the thing that looks obviously correct.

int availableSeats = bookingService.getAvailableSeats(trainNo, classType, date);
if (availableSeats < numberOfSeats) {
    throw new InsufficientSeatsException("Not enough seats available");
}
Ticket ticket = bookingService.createTicket(...);

Read it as three database operations in sequence: read the count, compare it in Java, write a ticket. Between the read and the write there is a window. Two travelers who both press Confirm inside that window both see availableSeats = 1, both pass the comparison, and both walk away with a ticket for the same seat.

undefined

The @Transactional annotation on the method does not close that window. At MySQL's default isolation level, REPEATABLE READ, both transactions get a consistent snapshot of the train row. Neither one blocks the other's read, and neither one learns that the other exists until it is far too late to matter.

There are three standard fixes, and they trade off differently.

  1. Pessimistic lock: issue SELECT ... FOR UPDATE on the train row at the top of the transaction. The second request waits, then reads the updated count. Correct and simple, but it serializes every booking against the same train.
  2. Optimistic lock: add a @Version column to Train and let Hibernate raise a conflict when two writers collide. Cheaper under low contention, but it needs a retry path the controller does not have.
  3. Conditional update: run UPDATE trains SET available_seats = available_seats - ? WHERE train_no = ? AND available_seats >= ?, then check the affected row count and reject on zero. One statement, no read at all.

The repository's fixed/BookingServiceImplSafe.java suggests the author was working through exactly this problem. What shipped inside src/main is still the unchecked version. That gap between the file in fixed/ and the file in src/ is the most honest thing in the repo.

A close-up editorial illustration of a hand gripping a rubber stamp, caught mid-arc above a stack of papers. The top sheet reads BookingController, and the edges of lower sheets are visible beneath it. An ink pad sits to one side, already smudged.
The fixed/ directory as a physical paper trail: alternate versions of the same class, stamped and set aside, never quite merged back.

Smart Cancellation, Actually Smart

The refund logic is where the project stops looking like homework. Cancellation is not a boolean here. The app models time-based slabs: cancel far enough ahead and you get most of your money back, cancel late and the refund decays. CancellationRule holds the bands, RefundSlabDTO and RefundTimelineDTO shape them for the view, and cancellation-requests.html renders the schedule back to the passenger.

The exact percentages live as rows in the rule table rather than as constants in code, which is the right call. What matters is the shape:

Window before departureRefund directionWhy the rule exists
Well aheadNear full refundThe seat is resellable
Days outMost of the fareStill likely to resell
Day of travelRoughly halfHalf the value is already gone
Hours beforeSmall fractionThe seat probably travels empty
After departureNothingThere is nothing left to sell

The tickets table carries four overlapping date fields for cancellation and refund state: cancellation_requested_date, cancellation_decision_date, refund_date, and refund_processed_date. That is one or two too many, and a production system would collapse them into an explicit state machine with timestamps. But the underlying idea, a refund that decays with time and is configured rather than hard-coded, is the part most student projects skip entirely.

Spring Boot Without Spring Security

There is no Spring Security filter chain in this project. The only dependency pulled in is spring-security-crypto, used for BCrypt hashing. Authentication is a HandlerInterceptor registered in WebMvcConfig for /user/**, /admin/**, and /booking/**, with the public paths excluded.

That interceptor, SessionInterceptor, does three things. It lets a hard-coded list of paths through. It redirects to /login when session.getAttribute("activeUser") is null. And it rejects a non-admin who hits a path containing /admin/. The entire User entity is parked in the HttpSession as activeUser.

For a teaching project this is a defensible trade. You can read the whole authorization model in about forty lines, which is a real virtue when the point is learning. What you give up is the part that is genuinely hard to write yourself: CSRF tokens on the POST forms, session fixation defense at login, method-level authorization, and a filter that runs before your controllers rather than alongside them.

What the Audit Turns Up

None of the following is exotic. All of it is the ordinary residue of building quickly without a dedicated security pass.

IssueWhereSeverity
Gmail app password stored in plaintextapplication.properties, application-dev.propertiesCritical
Substring URI matching (uri.contains("/login"))SessionInterceptorHigh
/admin without a trailing slash skips the role checkSessionInterceptorHigh
download-pdf/{ticketId} exempt from the session checkWebMvcConfigHigh
ddl-auto=update against a live schemaapplication.propertiesMedium
show-sql=true and DEBUG logging on by defaultapplication.propertiesLow
Full User entity cached in the HttpSessionSessionInterceptorLow

The interceptor exempts /booking/download-pdf/ and /booking/view/ from the session check. If those handlers do not verify that the ticket belongs to the caller, and TicketIdGenerator produces guessable identifiers, then anyone can pull anyone's ticket. That is the classic insecure direct object reference, and it is worth patching before this project goes on a CV.

The plaintext Gmail credential is the one to fix first, and deleting the line is not the fix. It is in the git history now. Rotating the app password is the only remedy that actually works.

How It Stacks Up

RailEase is a crowded name. At least three unrelated repositories use it, which is worth knowing before you assume any of them share code or authorship. The closest technical sibling is a Java command-line reservation system with role-based menus and automatic waitlist promotion.

DimensionRailEase (this repo)baraiyash/Rail-Ease (CLI)A production system needs
InterfaceServer-rendered ThymeleafTerminal menusWeb, mobile, and API
AuthSession interceptor, no Spring SecurityRole-based CLI menusSpring Security, CSRF, MFA
Seat inventoryCheck-then-act, no lockWaitlist with auto-promotionPessimistic lock or atomic UPDATE
CancellationTime-based refund slabsCancellation plus waitlist promotionIdempotent refund reconciliation
PersistenceMySQL with ddl-auto=updateMySQL/MariaDB over JDBCVersioned migrations, no auto-DDL in prod
MealsE-pantry per trainNoneAncillary revenue engine

The third column is the interesting one. Real-time inventory, idempotent refunds, payment reconciliation, and CSRF protection are all missing here, and every one of them is a systems problem rather than a UI problem. That is the actual lesson of the repository, and the reason the fixed/ folder is worth more than a clean commit history.