How aj976/bus_ticket_booking_system works
1. Overall shape
- This is a single-process Java 8 desktop application with a JavaFX UI.
- The architecture is layered: UI → service layer → domain model → file I/O, with a separate threading layer for asynchronous operations.
2. Domain model boundary
- The model package holds the core business entities: Bus, Route, Passenger, and Booking.
- Vehicle is the abstract base type, and Bus extends it, while Bookable defines the booking contract that Bus implements.
- This is where the app’s business state lives; the UI and file layer should treat these classes as the source of truth.
3. State and enums
- Business state is normalized through enums:
- SeatType for seat classification,
- BookingStatus for lifecycle state,
- BusStatus for availability state.
- These enums shape the booking rules and the presentation state shown in the UI.
4. Fleet management subsystem
- service/BusFleet is the catalog/registry for all buses.
- The README indicates it maintains both a list of buses and a route lookup map, so it acts as the primary in-memory index for search and availability.
- This is the boundary between route/bus inventory management and booking operations.
5. Booking coordination subsystem
- service/BookingManager is the main transactional service for booking and cancellation.
- It owns the rules around seat assignment, full-bus handling, waitlisting, and cancellation effects.
- This is the central orchestration point that connects fleet data, passengers, bookings, and status transitions.
6. Booking and waitlist behavior
- When a booking is attempted, BookingManager likely checks bus capacity and either confirms the booking or marks it waitlisted.
- Cancellation triggers downstream state changes, which is where waitlisted bookings can be promoted.
- The presence of WaitlistNotifier suggests waitlist promotion is treated as a separate coordination concern rather than being embedded entirely in the UI.
7. Concurrency boundary
- The threads package contains asynchronous wrappers around booking and cancellation actions:
- BookingThread
- CancellationThread
- WaitlistNotifier
- FileWriterThread
- These threads exist to keep the UI responsive and to model concurrent booking/cancellation behavior, with synchronization handled in the service layer.
- WaitlistNotifier uses classic monitor-style coordination (wait/notify), so concurrency is a real architectural concern rather than just background decoration.
8. Persistence and file handling
- fileio/FileHandler handles serialization and human-readable export.
- Persistent booking data is stored in bookings.dat, while exports produce booking_report.txt.
- This is a file-backed desktop app, not a database-backed one; the file layer is the persistence boundary.
9. UI composition
- ui/MainApp is the JavaFX application entry point and likely assembles the dashboard, search, booking, bookings list, and management screens.
- BusRow and BookingRow are presentation adapters for table rows, separating UI display structure from the underlying model objects.
- The UI appears to be responsible for user interaction only; it delegates business logic to services and persistence to FileHandler.
10. Primary data flow: browsing and search
- The user searches routes/buses in the JavaFX UI.
- MainApp queries the fleet service for matching buses, then displays them through table row wrappers.
- This flow is read-heavy and stays inside memory until the user initiates a booking or management action.
11. Primary data flow: booking
- Booking starts in the UI, then moves to BookingThread or directly into BookingManager.
- BookingManager updates bus availability and creates or updates Booking and Passenger state.
- The resulting booking status is reflected back to the UI and later persisted by the file layer.
12. Primary data flow: cancellation and waitlist promotion
- Cancellation begins in the UI and is processed through CancellationThread into BookingManager.
- If a seat opens, waitlisted entries can be promoted, with WaitlistNotifier coordinating that transition.
- This creates a feedback loop from cancellation back into booking fulfillment.
13. Primary data flow: persistence and export
- Bookings are serialized to bookings.dat for recovery between runs.
- A separate export path writes a human-readable report file for management use.
- FileWriterThread suggests autosave is periodic and detached from direct user actions.
14. Architectural boundaries to draw
- Draw four main boxes: JavaFX UI, booking/fleet services, domain model, and file persistence, with a side box for background threads.
- The key dependency direction is: UI calls services; services manipulate model objects; file I/O saves/loads model state; threads invoke services asynchronously.
- There are no external APIs or network services in this repository; the app is self-contained and file-driven.
Main entry points: BookingManager.java BookingManager · Bus.java Bus · FileHandler.java FileHandler · Booking.java Booking
Components 19
JavaFX UI
Entry point and table-row presentation adapters.
- MainApp · Application shell and primary UI coordinator.
src/ui/MainApp.java - BusRow · Table-row presentation for buses.
src/ui/BusRow.java - BookingRow · Table-row presentation for bookings.
src/ui/BookingRow.java
Services
Fleet registry and booking orchestration.
- BookingManager · Transactional booking and cancellation orchestration.
src/service/BookingManager.java - BusFleet · In-memory catalog and route lookup index.
src/service/BusFleet.java
Domain model
Core business entities and enums.
- Bus · Bookable fleet asset and availability holder.
src/model/Bus.java - Vehicle · Shared vehicle superclass for fleet entities.
src/model/Vehicle.java - Bookable · Booking capability contract implemented by buses.
src/model/Bookable.java - Route · Route definition used for lookup and display.
src/model/Route.java - Passenger · Customer identity participating in bookings.
src/model/Passenger.java - Booking · Booking record and lifecycle state container.
src/model/Booking.java - SeatType · Seat classification used by booking rules.
src/enums/SeatType.java - BookingStatus · Lifecycle state for booking records.
src/enums/BookingStatus.java - BusStatus · Availability state for buses.
src/enums/BusStatus.java
Background threads
Async wrappers for booking, cancellation, and autosave.
- BookingThread · Background booking execution wrapper.
src/threads/BookingThread.java - CancellationThread · Background cancellation execution wrapper.
src/threads/CancellationThread.java - WaitlistNotifier · Monitor-based waitlist promotion coordination.
src/threads/WaitlistNotifier.java - FileWriterThread · Background file write and export worker.
src/threads/FileWriterThread.java
File persistence
Serialization and export boundary.
- FileHandler · Persistence and report generation boundary.
src/fileio/FileHandler.java
Connections 34
- MainApp → BusFleet: searches · UI queries the fleet registry for routes and buses.
- MainApp → BookingManager: book/cancel · UI delegates booking actions to the transactional service.
- MainApp → FileHandler: load/save · UI triggers persistence and export operations.
- MainApp → BusRow: renders · UI presents bus results via row adapters.
- MainApp → BookingRow: renders · UI presents booking results via row adapters.
- BookingThread → BookingManager: executes · Async booking wrapper invokes the booking service.
- CancellationThread → BookingManager: executes · Async cancellation wrapper invokes the booking service.
- WaitlistNotifier → BookingManager: coordinates · Waitlist promotion is coordinated through booking state.
- FileWriterThread → FileHandler: writes · Background worker performs autosave and report export.
- BusFleet → Bus: indexes · Fleet registry stores and searches buses.
- BusFleet → Route: maps · Fleet registry maintains route lookups.
- BookingManager → Booking: creates · Service creates and updates booking records.
- BookingManager → Passenger: updates · Service manages passenger-linked booking state.
- BookingManager → Bus: allocates · Service reserves seats and updates bus availability.
- BookingManager → BookingStatus: sets · Service transitions booking lifecycle state.
- BookingManager → BusStatus: sets · Service updates bus availability state.
- BookingManager → SeatType: applies · Service enforces seat-class rules during booking.
- Bus → Vehicle: extends · Bus specializes the shared vehicle base type.
- Bus → Bookable: implements · Bus fulfills the booking contract.
- Bus → BusStatus: uses · Bus stores availability state.
- Bus → SeatType: uses · Bus tracks supported seat classifications.
- Booking → Passenger: references · Booking binds a passenger to a reservation.
- Booking → Bus: references · Booking points to the reserved bus.
- Booking → BookingStatus: uses · Booking carries lifecycle state.
- BusRow → Bus: displays · Row adapter formats bus state for the UI.
- BusRow → Route: displays · Row adapter shows route data alongside buses.
- BusRow → BusStatus: shows · Row adapter surfaces bus availability.
- BookingRow → Booking: displays · Row adapter formats booking records.
- BookingRow → Passenger: displays · Row adapter shows passenger details.
- BookingRow → BookingStatus: shows · Row adapter surfaces booking lifecycle state.
- FileHandler → Booking: serializes · File layer persists booking records.
- FileHandler → Bus: serializes · File layer persists fleet state.
- FileHandler → Route: serializes · File layer persists route data.
- FileHandler → Passenger: serializes · File layer persists passenger data.