# aj976/bus_ticket_booking_system architecture

> Architecture diagram of the GitHub repository aj976/bus_ticket_booking_system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aj976/bus_ticket_booking_system
- Repository: https://github.com/aj976/bus_ticket_booking_system

## Overview

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: [`src/service/BookingManager.java`](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/service/BookingManager.java) (BookingManager), [`src/model/Bus.java`](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Bus.java) (Bus), [`src/fileio/FileHandler.java`](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/fileio/FileHandler.java) (FileHandler), [`src/model/Booking.java`](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Booking.java) (Booking)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["JavaFX UI"]
  node_ui_mainapp["MainApp<br/>JavaFX entry<br/>[MainApp.java]"]
  node_ui_busrow["BusRow<br/>row adapter<br/>[BusRow.java]"]
  node_ui_bookingrow["BookingRow<br/>row adapter<br/>[BookingRow.java]"]
end

subgraph group_services["Services"]
  node_svc_bookingmanager["BookingManager<br/>booking service"]
  node_svc_busfleet["BusFleet<br/>fleet registry<br/>[BusFleet.java]"]
end

subgraph group_domain["Domain model"]
  node_model_bus["Bus<br/>vehicle entity<br/>[Bus.java]"]
  node_model_vehicle["Vehicle<br/>abstract base<br/>[Vehicle.java]"]
  node_model_bookable{{"Bookable<br/>contract<br/>[Bookable.java]"}}
  node_model_route["Route<br/>[Route.java]"]
  node_model_passenger["Passenger<br/>person entity<br/>[Passenger.java]"]
  node_model_booking["Booking<br/>reservation entity<br/>[Booking.java]"]
  node_enum_seattype{{"SeatType<br/>enum<br/>[SeatType.java]"}}
  node_enum_bookingstatus{{"BookingStatus<br/>enum<br/>[BookingStatus.java]"}}
  node_enum_busstatus{{"BusStatus<br/>enum<br/>[BusStatus.java]"}}
end

subgraph group_concurrency["Background threads"]
  node_thr_booking["BookingThread<br/>async booking<br/>[BookingThread.java]"]
  node_thr_cancellation["CancellationThread<br/>async cancel"]
  node_thr_waitlist["WaitlistNotifier<br/>coordination"]
  node_thr_filewriter["FileWriterThread<br/>autosave thread"]
end

subgraph group_persistence["File persistence"]
  node_persistence_filehandler["FileHandler<br/>file I/O<br/>[FileHandler.java]"]
end

node_ui_mainapp -->|"searches"| node_svc_busfleet
node_ui_mainapp -->|"book/cancel"| node_svc_bookingmanager
node_ui_mainapp -->|"load/save"| node_persistence_filehandler
node_ui_mainapp -->|"renders"| node_ui_busrow
node_ui_mainapp -->|"renders"| node_ui_bookingrow
node_thr_booking -->|"executes"| node_svc_bookingmanager
node_thr_cancellation -->|"executes"| node_svc_bookingmanager
node_thr_waitlist -->|"coordinates"| node_svc_bookingmanager
node_thr_filewriter -->|"writes"| node_persistence_filehandler
node_svc_busfleet -->|"indexes"| node_model_bus
node_svc_busfleet -->|"maps"| node_model_route
node_svc_bookingmanager -->|"creates"| node_model_booking
node_svc_bookingmanager -->|"updates"| node_model_passenger
node_svc_bookingmanager -->|"allocates"| node_model_bus
node_svc_bookingmanager -->|"sets"| node_enum_bookingstatus
node_svc_bookingmanager -->|"sets"| node_enum_busstatus
node_svc_bookingmanager -->|"applies"| node_enum_seattype
node_model_bus -->|"extends"| node_model_vehicle
node_model_bus -->|"implements"| node_model_bookable
node_model_bus -->|"uses"| node_enum_busstatus
node_model_bus -->|"uses"| node_enum_seattype
node_model_booking -->|"references"| node_model_passenger
node_model_booking -->|"references"| node_model_bus
node_model_booking -->|"uses"| node_enum_bookingstatus
node_ui_busrow -->|"displays"| node_model_bus
node_ui_busrow -->|"displays"| node_model_route
node_ui_busrow -->|"shows"| node_enum_busstatus
node_ui_bookingrow -->|"displays"| node_model_booking
node_ui_bookingrow -->|"displays"| node_model_passenger
node_ui_bookingrow -->|"shows"| node_enum_bookingstatus
node_persistence_filehandler -->|"serializes"| node_model_booking
node_persistence_filehandler -->|"serializes"| node_model_bus
node_persistence_filehandler -->|"serializes"| node_model_route
node_persistence_filehandler -->|"serializes"| node_model_passenger

click node_ui_mainapp "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/ui/MainApp.java"
click node_ui_busrow "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/ui/BusRow.java"
click node_ui_bookingrow "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/ui/BookingRow.java"
click node_svc_bookingmanager "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/service/BookingManager.java"
click node_svc_busfleet "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/service/BusFleet.java"
click node_thr_booking "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/threads/BookingThread.java"
click node_thr_cancellation "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/threads/CancellationThread.java"
click node_thr_waitlist "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/threads/WaitlistNotifier.java"
click node_thr_filewriter "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/threads/FileWriterThread.java"
click node_persistence_filehandler "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/fileio/FileHandler.java"
click node_model_bus "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Bus.java"
click node_model_vehicle "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Vehicle.java"
click node_model_bookable "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Bookable.java"
click node_model_route "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Route.java"
click node_model_passenger "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Passenger.java"
click node_model_booking "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Booking.java"
click node_enum_seattype "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/enums/SeatType.java"
click node_enum_bookingstatus "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/enums/BookingStatus.java"
click node_enum_busstatus "https://github.com/aj976/bus_ticket_booking_system/blob/main/src/enums/BusStatus.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui_mainapp,node_ui_busrow,node_ui_bookingrow toneBlue
class node_svc_bookingmanager,node_svc_busfleet toneAmber
class node_model_bus,node_model_vehicle,node_model_bookable,node_model_route,node_model_passenger,node_model_booking,node_enum_seattype,node_enum_bookingstatus,node_enum_busstatus toneMint
class node_thr_booking,node_thr_cancellation,node_thr_waitlist,node_thr_filewriter toneRose
class node_persistence_filehandler toneIndigo
```

## Components

### JavaFX UI

Entry point and table-row presentation adapters.

- [MainApp](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/ui/MainApp.java): JavaFX entry · Application shell and primary UI coordinator. · `src/ui/MainApp.java`
- [BusRow](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/ui/BusRow.java): row adapter · Table-row presentation for buses. · `src/ui/BusRow.java`
- [BookingRow](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/ui/BookingRow.java): row adapter · Table-row presentation for bookings. · `src/ui/BookingRow.java`

### Services

Fleet registry and booking orchestration.

- [BookingManager](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/service/BookingManager.java): booking service · Transactional booking and cancellation orchestration. · `src/service/BookingManager.java`
- [BusFleet](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/service/BusFleet.java): fleet registry · In-memory catalog and route lookup index. · `src/service/BusFleet.java`

### Domain model

Core business entities and enums.

- [Bus](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Bus.java): vehicle entity · Bookable fleet asset and availability holder. · `src/model/Bus.java`
- [Vehicle](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Vehicle.java): abstract base · Shared vehicle superclass for fleet entities. · `src/model/Vehicle.java`
- [Bookable](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Bookable.java): contract · Booking capability contract implemented by buses. · `src/model/Bookable.java`
- [Route](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Route.java): route entity · Route definition used for lookup and display. · `src/model/Route.java`
- [Passenger](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Passenger.java): person entity · Customer identity participating in bookings. · `src/model/Passenger.java`
- [Booking](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/model/Booking.java): reservation entity · Booking record and lifecycle state container. · `src/model/Booking.java`
- [SeatType](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/enums/SeatType.java): enum · Seat classification used by booking rules. · `src/enums/SeatType.java`
- [BookingStatus](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/enums/BookingStatus.java): enum · Lifecycle state for booking records. · `src/enums/BookingStatus.java`
- [BusStatus](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/enums/BusStatus.java): enum · Availability state for buses. · `src/enums/BusStatus.java`

### Background threads

Async wrappers for booking, cancellation, and autosave.

- [BookingThread](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/threads/BookingThread.java): async booking · Background booking execution wrapper. · `src/threads/BookingThread.java`
- [CancellationThread](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/threads/CancellationThread.java): async cancel · Background cancellation execution wrapper. · `src/threads/CancellationThread.java`
- [WaitlistNotifier](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/threads/WaitlistNotifier.java): coordination · Monitor-based waitlist promotion coordination. · `src/threads/WaitlistNotifier.java`
- [FileWriterThread](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/threads/FileWriterThread.java): autosave thread · Background file write and export worker. · `src/threads/FileWriterThread.java`

### File persistence

Serialization and export boundary.

- [FileHandler](https://github.com/aj976/bus_ticket_booking_system/blob/main/src/fileio/FileHandler.java): file I/O · Persistence and report generation boundary. · `src/fileio/FileHandler.java`

## Connections

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