Implement&Test
Implement&Test
Executive Summary 4
3 Database Design 20
3.1 Entity Relationship Diagram (ERD) . . . . . . . . . . . . . . . . . . . . 20
3.2 Data Schema Specification . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5 Implementation Progress 45
5.1 Completed Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.2 Planned & In-Progress Features . . . . . . . . . . . . . . . . . . . . . . . 46
6 Testing Progress 48
6.1 Test Cases & Coverage Status . . . . . . . . . . . . . . . . . . . . . . . . 48
6.1.1 Backend Tests (Spring Boot) . . . . . . . . . . . . . . . . . . . . . 48
6.1.2 Frontend Tests (ReactJS) . . . . . . . . . . . . . . . . . . . . . . 49
6.2 Testing Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
6.2.1 Current Testing Strategy . . . . . . . . . . . . . . . . . . . . . . . 50
6.2.2 Recommended Testing Strategy . . . . . . . . . . . . . . . . . . . 50
6.2.3 Tools Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
6.3 Issues Found & Current Resolution Status . . . . . . . . . . . . . . . . . . 51
6.3.1 Known Issues (Resolved) . . . . . . . . . . . . . . . . . . . . . . . . 51
2
6.3.2 Potential Issues (To Be Tested) . . . . . . . . . . . . . . . . . . . . 51
6.3.3 Testing Gaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
6.4 Testing Roadmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7 Conclusion 53
List of Figures
1.1 Member Use Case Diagram of the Online Cinema Booking System . . . . 6
1.2 Admin Use Case Diagram of the Online Cinema Booking System . . . . . 8
2.1 Hight - level Architecture Design of the Online Cinema Booking System . 10
2.2 Component Diagram of the Online Cinema Booking System . . . . . . . 15
3
Executive Summary
4
System Design, Implementation and Testing Progress List of Figures
mented to run every five minutes, automatically releasing seats associated with bookings
that remain pending for more than 15 minutes. Additionally, a complex dynamic pricing
engine was engineered using native SQL queries, allowing the system to calculate ticket
prices accurately based on variable factors such as seat class (VIP/Classic) and day type
(Weekends/Holidays).
Finally, to ensure the reliability and stability of the software, a comprehensive testing
strategy has been adopted. The team is utilizing JUnit 5 for backend logic verification
and React Testing Library for frontend component validation. While the project is
currently moving from feature development to an intensive testing phase, the foundational
work regarding architecture and core functionality is complete. The HDQ Cinema system
stands as a technically feasible, secure, and scalable solution ready for advanced feature
expansion and eventual production deployment.
5
Chapter 1
Figure 1.1: Member Use Case Diagram of the Online Cinema Booking System
The Use Case Diagram presented in the figure defines the functional scope and
primary interactions within the Customer module of the Movie Ticket Booking System.
The system interacts with two distinct user actor categories: Guest and Registered
Guest. Both actors inherit from a generalized Customer actor, accurately reflecting
a generalization relationship where basic functionalities are shared. While the Guest
is primarily associated with Create Account and initial exploration, the Registered
6
System Design, Implementation and Testing Progress Chapter 1. Use Case Analysis
7
System Design, Implementation and Testing Progress Chapter 1. Use Case Analysis
Figure 1.2: Admin Use Case Diagram of the Online Cinema Booking System
The Use Case Diagram presented in the figure defines the administrative functional
scope and operational privileges within the Admin module of the Movie Ticket Booking
System. The system interacts with a single primary actor, the Admin, who is responsible
for maintaining the system’s core data and business configurations.
8
System Design, Implementation and Testing Progress Chapter 1. Use Case Analysis
9
Chapter 2
Figure 2.1: Hight - level Architecture Design of the Online Cinema Booking System
System overview
10
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
The Frontend Layer is built using [Link], a modern JavaScript library for building
user interfaces. React Router manages client-side routing, enabling navigation
between different pages such as HomePage (/), MovieDetail (/movie-detail/:id),
SeatSelection (/seat-selection), ConfirmPayment (/confirm-payment), and Login
(/login). Ant Design provides a comprehensive set of UI components including
Layout, Tabs, Buttons, Forms, and Modals, ensuring a consistent and professional
user interface. The API Service Layer acts as a centralized communication hub be-
tween the Frontend and Backend. It provides abstraction functions like getMovies(),
getShowtimes(), createBooking(), createPayment(), and login() that handle HTTP
requests, error handling, and response parsing. When a user interacts with the UI,
React components trigger these API functions, which send HTTP requests to the
Backend endpoints. The responses are then processed and used to update the React
component state, triggering re-renders to display the updated information to the
user.
The Controller Layer serves as the entry point for all incoming HTTP re-
quests from the Frontend. Controllers such as MovieController, BookingCon-
troller, PaymentController, AuthenticationController, CinemaController,
and ShowTimeController are responsible for handling specific REST endpoints.
Each controller receives HTTP requests, validates the incoming data, extracts re-
quest parameters and body content, and delegates business logic processing to the
appropriate Service layer components. Controllers do not contain business logic;
instead, they act as coordinators that transform HTTP requests into service method
calls and convert service responses into HTTP responses. They handle HTTP
status codes, error responses, and ensure proper data serialization to JSON
format. The controllers also interact with the exception handling mechanism to
provide meaningful error messages to clients.
The Service Layer contains the core business logic of the application. BookingSer-
vice manages the entire booking lifecycle: it creates bookings with seat reservations,
sets seats to HELD status to prevent other users from booking them, calculates
total prices using dynamic pricing logic, and handles payment approval to change
booking status from PENDING to CONFIRM. The service also manages the
automatic cleanup of expired bookings through the deleteExpiredBookings() method.
11
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
The Repository Layer provides an abstraction for data access operations us-
ing JPA (Java Persistence API) and Hibernate ORM. Repositories such as
BookingRepository, MovieRepository, TicketPriceRepository, BookingDe-
tailRepository, and ShowTimeRepository extend JpaRepository, providing
standard CRUD operations and custom query methods. BookingDetailRepository
implements a unique constraint on the combination of seat_id and showtime_id,
preventing the same seat from being booked twice for the same showtime. This
constraint is enforced at the database level, providing a robust solution to race
conditions that could occur when multiple users attempt to book the same seat
simultaneously. TicketPriceRepository contains a complex native SQL query in
the toPrice() method that joins multiple tables (ticket_price, show_time, cin-
ema, and day_type) to calculate dynamic pricing. The query uses COALESCE
functions to handle cases where day types might not match exactly, falling back
to day-of-week calculations. Repositories interact directly with the PostgreSQL
database through JPA, which handles SQL generation, connection management,
and result set mapping. The repositories also support custom queries using @Query
annotations for complex operations that cannot be expressed through standard JPA
12
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
Spring Security is configured to protect all endpoints except public ones using JWT
authentication. The Security Filter Chain intercepts every incoming HTTP
request, extracts the JWT token from the Authorization header, validates the
token’s signature and expiration, extracts user information and roles from the token
claims, and allows the request to proceed to the Controller if validation succeeds.
Public endpoints that do not require authentication include /accounts (POST) for
user registration, /auth/token (POST) for login, /auth/introspect (POST) for
token validation, /auth/logout (POST) for logout, and /auth/refresh (POST)
for token refresh. All other endpoints require a valid JWT token in the request
header. CSRF (Cross-Site Request Forgery) protection is disabled because the
system uses stateless JWT authentication with tokens sent in HTTP headers
rather than cookies. This is appropriate for REST APIs and eliminates the
need for CSRF tokens while maintaining security through JWT validation.
CORS (Cross-Origin Resource Sharing) is configured to allow requests from
the Frontend origin ([Link] enabling the React application
to make API calls to the Backend running on a different port. The CORS
configuration allows all HTTP methods and headers, providing flexibility for
API communication.
PostgreSQL serves as the persistent storage for all system data, including movies,
showtimes, seats, bookings, cinemas, rooms, members, and ticket prices. JPA/Hiber-
nate manages the Object-Relational Mapping (ORM) between Java entity
13
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
classes and database tables, automatically generating SQL queries and handling
result set mapping. Transactions are crucial for maintaining data consistency,
especially in booking operations where multiple related records must be created
atomically. The @Transactional annotation ensures that all database operations
within a method either complete successfully or are rolled back together, preventing
partial updates that could lead to data inconsistency. Unique constraints at the
database level provide an additional layer of protection against race conditions. The
unique constraint on booking_detail(seat_id, showtime_id) ensures that even
if two requests attempt to book the same seat simultaneously, only one will succeed,
with the other receiving a database constraint violation error.
Deployment Infrastructure
The entire system is containerized using Docker, with separate containers for
Frontend, Backend, and Database. The Frontend container runs the React
application on port 3000, the Backend container runs the Spring Boot
application on port 8080, and the Database container runs PostgreSQL on
port 5433 (mapped from internal port 5432). Docker Compose orchestrates
these containers, managing their lifecycle, networking between containers, and
volume persistence for database data. The compose file defines environment
variables for database credentials, JWT signing keys, and other configuration
parameters. This containerized approach ensures consistent deployment across
different environments and simplifies scaling and maintenance operations.
14
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
Booking Flow: When a user selects seats and initiates a booking, the Frontend
sends a POST request to /bookings with booking details. The Booking-
Controller receives the request and calls [Link](). The
service validates the member and showtime, calculates prices for each seat using
[Link](), creates Booking and BookingDetail enti-
ties with HELD status, and saves them to the database. The unique constraint
on booking_detail(seat_id, showtime_id) prevents double booking at the
database level. The response returns the booking ID to the Frontend, which then
redirects to the payment page. Payment Flow: The Frontend calls PaymentSer-
[Link]() with the booking ID. The service retrieves booking details,
constructs VNPAY payment parameters, generates a signed payment URL, and
returns it to the Frontend. The user is redirected to VNPAY for payment. After
payment, VNPAY sends a callback to the backend, which processes the result and
updates the booking status accordingly. Authentication Flow: When a user logs
in, the Frontend sends credentials to /auth/token. The AuthenticationService
finds the user in the database, verifies the password using BCrypt, generates a JWT
token with user information and roles, and returns the token. The Frontend stores
the token in localStorage and includes it in subsequent API requests. Spring
Security validates the token for each protected endpoint request.
The Frontend package contains six main components that handle user interactions
and API communication. The HomePage component displays the main landing page
with movie listings, allowing users to browse available and upcoming movies. The
15
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
The Backend Controllers package contains six REST controllers that serve as
entry points for different functional areas of the application. The MovieController
handles movie-related endpoints, processing requests to retrieve movie lists, filter
movies by status (showing/upcoming), and get detailed movie information. The
BookingController manages booking operations, receiving booking creation requests,
handling payment approval, and providing booking status information. The Cinema-
Controller processes requests related to cinema information, allowing clients to
retrieve cinema lists and details. The PaymentController handles payment-related
operations, creating payment URLs and processing payment callbacks from external
gateways. The ShowTimeController manages showtime creation and retrieval
operations. The AuthenticationController handles all authentication-related
endpoints including login, token refresh, logout, and token introspection. Each con-
troller receives HTTP requests from the APIService, validates the incoming
data, and delegates business logic processing to corresponding Service components.
Controllers are responsible for transforming HTTP requests into service method
calls and converting service responses into properly formatted HTTP responses with
appropriate status codes.
The Backend Services package contains the core business logic components
that orchestrate complex operations and coordinate between multiple repositories.
The MovieService handles movie-related business logic, including filtering movies
by release dates and cinema locations. The BookingService is one of the most
critical services, managing the entire booking lifecycle: it creates bookings with
16
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
seat reservations, calculates total prices, manages booking status transitions from
PENDING to CONFIRM, and coordinates with the BookingDeleteScheduler
for automatic cleanup of expired bookings. The CinemaService manages cinema-
related operations, while the PaymentService integrates with external payment
gateways, generating secure payment URLs, processing payment callbacks, and
updating booking statuses based on payment results. The ShowTimeService
handles showtime management operations. The AuthenticationService manages
user authentication, password verification, JWT token generation and validation, and
token refresh mechanisms. The TicketPriceService implements complex dynamic
pricing calculations that consider multiple factors including seat type, day type,
and cinema location. The BookingDeleteScheduler is a specialized component
that runs periodically to clean up expired bookings, ensuring seat availability is
maintained. Services coordinate with multiple repositories to retrieve and persist
data, use mappers to convert between entities and DTOs, and manage transactions
to ensure data consistency.
The Backend Repositories package contains data access components that provide
abstraction over database operations. The MovieRepository handles all database
operations related to movies, including queries to find movies by various criteria.
The BookingRepository manages booking data persistence and retrieval, including
queries to find bookings by status and creation time for cleanup operations. The
BookingDetailRepository is particularly important as it manages the relation-
ship between bookings, seats, and showtimes, and enforces the unique constraint
that prevents double booking. The CinemaRepository, ShowTimeRepository,
and SeatRepository handle data access for their respective entities. The Tick-
etPriceRepository contains complex native SQL queries for dynamic price cal-
culation, joining multiple tables to determine the correct price based on various
conditions. The MemberRepository manages user data access, including authen-
tication queries. All repositories extend JpaRepository, providing standard CRUD
operations, and implement custom query methods when needed. Repositories interact
directly with the PostgreSQL database, executing SQL queries and mapping results
to entity objects.
Security Components
17
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
18
System Design, Implementation and Testing Progress
Chapter 2. System Architecture Design
Scheduled Operations
19
Chapter 3
Database Design
Figure 3.1: Entity Relationship Diagram of the Online Cinema Booking System
Cinema Entity represents physical cinema locations in the system. Each cinema has
a unique identifier (cinema_id), along with location information including name,
city, district, and full address. This entity serves as the top-level organizational
unit, with each cinema containing multiple rooms and having its own pricing
structure. Room Entity represents individual screening auditoriums within a
20
System Design, Implementation and Testing Progress Chapter 3. Database Design
cinema. Each room has a unique identifier (room_id) and a name for identification.
The room belongs to a specific cinema through the cinema_id foreign key,
establishing a one-to-many relationship where one cinema can have multiple
rooms. Each room contains multiple seats and hosts multiple showtimes. Seat
Entity represents individual seats within a room. Each seat has a unique identifier
(seat_id), a seat number, a seat row (typically a character like ’A’, ’B’, ’C’),
and a seat type (VIP or CLASSIC). The seat belongs to a specific room through
the room_id foreign key. Seats can be reserved through booking details, creating
a many-to-many relationship with showtimes through the booking_detail
junction entity. Movie Entity stores information about films available for
screening. It contains a unique identifier (movie_id), title, poster URL, duration in
minutes, release dates (day_start and day_end), director name, genre, description,
trailer URL, and age limitation. Each movie can have multiple showtimes scheduled
at different times and in different rooms. ShowTime Entity represents a scheduled
screening of a movie at a specific time in a specific room. It has a unique identifier
(showtime_id), a start time (timestamp), and foreign keys to both the movie
and room. A unique constraint on the combination of start_time and room_id
ensures that the same room cannot have overlapping showtimes, preventing scheduling
conflicts.
Member Entity represents registered users of the cinema system. Each member has
a unique identifier (member_id), a unique username for login, an encrypted
password (stored using BCrypt), email address, phone number, and date of birth.
Members can create multiple bookings, establishing a one-to-many relationship
with the booking entity. Booking Entity represents a booking transaction made by a
member. It contains a unique identifier (booking_id), total price (calculated from
individual seat prices), creation timestamp, and booking status (PENDING or
CONFIRM). The booking belongs to a specific member through the member_id
foreign key. A booking can contain multiple booking details, each representing a
reserved seat. BookingDetail Entity is a junction entity that connects bookings,
seats, and showtimes. It contains a unique identifier (id), individual seat price,
seat status (AVAILABLE, HELD, or BOOKED), and foreign keys to booking,
seat, and showtime. The critical unique constraint on the combination of
seat_id and showtime_id prevents the same seat from being booked twice for the
same showtime, solving the race condition problem in concurrent booking scenarios.
21
System Design, Implementation and Testing Progress Chapter 3. Database Design
DayType Entity defines special day categories such as holidays and weekends that
affect ticket pricing. It has a unique identifier (id), a unique day type name,
and date ranges (day_start and day_end) that define when this day type is
active. This allows the system to apply different pricing rules during holidays or
weekends. TicketPrice Entity stores pricing rules that determine ticket costs
based on multiple factors. It contains a unique identifier (id), the price value,
seat type (VIP or CLASSIC), and foreign keys to both day type and cinema.
This design enables dynamic pricing where the same seat type can have different
prices depending on the day type (holiday/weekend) and the cinema location. The
pricing calculation uses complex SQL queries that join these entities to determine
the correct price for a booking.
Supporting Entities
PaymentURL Entity stores VNPAY payment gateway URLs generated for book-
ings. It contains a unique identifier (id), the payment URL string, and foreign
keys to both booking and member. This entity maintains a one-to-one re-
lationship with booking (a booking can have at most one payment URL) and a
22
System Design, Implementation and Testing Progress Chapter 3. Database Design
The database design includes several critical constraints that ensure data integrity.
The unique constraint on booking_detail(seat_id, showtime_id) prevents
double booking at the database level, providing a robust solution to race condi-
tions. The unique constraint on show_time(start_time, room_id) prevents
scheduling conflicts where the same room would have overlapping showtimes. The
unique constraint on day_type(day_type) ensures that day type names are
unique across the system. Foreign key constraints maintain referential integrity
throughout the system, ensuring that bookings reference valid members, booking
details reference valid bookings, seats, and showtimes, and all relationships remain
consistent. Cascade delete operations are configured where appropriate, such as
when a booking is deleted, its associated booking details are automatically removed.
The ERD follows several database design best practices. The use of UUIDs as
primary keys provides globally unique identifiers that are suitable for distributed systems.
Junction entities like booking_detail and role_permission properly implement
many-to-many relationships. The separation of concerns is evident with distinct entities for
business logic (booking, movie) and supporting functionality (employee accounts, tokens).
23
System Design, Implementation and Testing Progress Chapter 3. Database Design
Table: cinema
24
System Design, Implementation and Testing Progress Chapter 3. Database Design
Table: room
Table: seat
Table: movie
25
System Design, Implementation and Testing Progress Chapter 3. Database Design
Table: show_time
Table: member
Table: booking
26
System Design, Implementation and Testing Progress Chapter 3. Database Design
Table: booking_detail
Table: day_type
27
System Design, Implementation and Testing Progress Chapter 3. Database Design
Table: ticket_price
Table: employee
Table: employee_account
28
System Design, Implementation and Testing Progress Chapter 3. Database Design
Table: role
Table: permission
Table: role_permission
29
System Design, Implementation and Testing Progress Chapter 3. Database Design
Table: payment_url
Table: invalidated_token
30
Chapter 4
31
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
The authentication flow begins when a user interacts with the Login Page
component on the Frontend. The user enters their username and password
credentials into the login form. When the user clicks the Login button, the
Login Page component captures these credentials and initiates the authentication
process by calling the login() function in the API Service layer.
The API Service component receives the login request with username and pass-
word parameters. This component acts as a centralized communication layer that
handles all HTTP requests to the Backend. It constructs a POST request to
the /cinemas/auth/token endpoint, including the credentials in the request body
as JSON. The API Service sends this HTTP request to the Authentication-
Controller on the Backend, establishing the connection between Frontend and
Backend layers.
32
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
object. The controller’s role is limited to request handling and response formatting,
keeping business logic separate in the service layer.
The PostgreSQL database processes the query and returns the member entity
if found, or indicates that no member exists with that username. The Member-
Repository receives the database response and returns the member entity (or null)
to the AuthenticationService. This database interaction is critical as it retrieves
the stored password hash for comparison.
The Login Page component receives the successful authentication response and
stores the JWT token in the browser’s localStorage for use in subsequent API
requests. The user information is also stored in localStorage to maintain user
context throughout the session. After storing the authentication data, the Login
Page redirects the user to the HomePage, completing the successful login flow.
33
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
If the database query returns no member with the provided username, the Member-
Repository indicates that the user was not found. The AuthenticationService
throws an AppException with a "User not found" message. The Authentica-
tionController handles this exception and returns an HTTP 404 Not Found
response. The API Service forwards this error to the Login Page, which displays
an appropriate error message to inform the user that the account does not exist.
Security Considerations
Component Responsibilities
Each component in the sequence has clear responsibilities. The Login Page handles
user interface and local storage management. The API Service manages HTTP
communication and response parsing. The AuthenticationController handles
HTTP request/response formatting. The AuthenticationService contains the
core authentication business logic. The MemberRepository provides data access
abstraction. The SecurityConfig component manages JWT token generation and
security configuration. The PostgreSQL Database provides persistent storage for
member credentials.
34
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
Flow Characteristics
Figure 4.2: Booking Creation Sequence Sequences of the Online Cinema Booking System
35
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
seats to the final confirmation that seats are held. This sequence demonstrates the
interaction between the frontend, backend controllers, services, and database,
showing how the system validates requests, calculates prices, and creates bookings
while preventing race conditions through database-level constraints.
The booking process begins when a member interacts with the Frontend appli-
cation, specifically the SeatSelection page. The member visually selects their
preferred seats from the seat map displayed for a particular showtime. The Fron-
tend component tracks these selections, maintaining the state of selected seats
including their seat IDs, row numbers, and seat types. This user interaction
represents the first step in the booking journey, where the member makes their seat
choices before proceeding to create the booking.
After selecting seats, the member initiates the booking creation by clicking a confir-
mation button or proceeding to payment. The Frontend component collects all
necessary information including the selected seat IDs, showtime ID, member
ID (from the authenticated session), and cinema ID. The Frontend constructs
a booking request object containing this information and prepares to send it to the
Backend for processing.
The Frontend sends a POST request to the /bookings endpoint, including the
booking request in the request body as JSON. This HTTP request travels from the
Frontend to the BookingController on the Backend, establishing communication
between the client and server. The request includes all necessary data for booking
creation: member identification, showtime selection, seat selections, and cinema
[Link] where each step waits for the previous step to complete before
proceeding. The flow includes alternative paths (alt blocks) for different scenarios:
successful authentication, invalid password, and user not found. Error handling is
integrated throughout the flow, ensuring that exceptions are properly caught and
converted to appropriate HTTP responses. The sequence maintains separation
of concerns, with each layer handling its specific responsibilities without mixing
concerns.
36
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
The BookingController receives the HTTP POST request and extracts the
booking request data from the request body. The controller validates the request
structure and delegates the business logic processing to the BookingService by
calling the createBooking() method with the request object. The controller’s
responsibility is limited to request handling and response formatting, maintaining
separation of concerns with the service layer.
One of the most complex operations in the booking creation process is the dynamic
price calculation. The BookingService calls the TicketPriceRepository’s
toPrice() method for each selected seat. This method executes a sophisticated
native SQL query that joins multiple tables including ticket_price, show_time,
cinema, and day_type. The query considers the seat type (VIP or CLASSIC),
the day type (determined by checking if the showtime date falls within a holiday
period or is a weekend), and the cinema location to calculate the appropriate
price for each seat. The price calculation logic handles various scenarios: if the
showtime date matches a defined day type (like a holiday), it uses that day type’s
pricing; otherwise, it falls back to calculating the day of the week. The query uses
COALESCE functions to handle null values and ensures that a price is always
returned. This dynamic pricing allows the system to charge different rates for VIP
37
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
seats versus classic seats, for holidays versus regular days, and potentially different
rates at different cinema locations.
After calculating prices for all selected seats, the BookingService creates the
booking entity with the total price (sum of all individual seat prices), creation
timestamp, and initial status set to PENDING. The service then creates Book-
ingDetail entities for each selected seat, setting the seat status to HELD to
indicate that these seats are temporarily reserved. Each BookingDetail record
links a specific seat to a specific showtime and booking, with the calculated price
for that seat. The service attempts to save these entities to the database within
a transaction. The database enforces a unique constraint on the combination
of seat_id and showtime_id in the booking_detail table. This constraint is
critical for preventing race conditions: if two users simultaneously attempt to
book the same seat for the same showtime, only one will succeed. The database will
reject the second attempt with a constraint violation error, which the service
catches and converts into a user-friendly error message.
The entire booking creation process occurs within a database transaction managed
by the @Transactional annotation. This ensures atomicity: either all operations
succeed (member validation, showtime validation, price calculation, booking creation,
and all booking detail creations) or all operations are rolled back. This prevents
partial bookings where some seats might be reserved while others fail, which would
lead to data inconsistency. The transaction also provides isolation, ensuring that
concurrent booking attempts are properly serialized. When the transaction is active,
database locks prevent other transactions from modifying the same records, further
protecting against race conditions. The unique constraint at the database level
provides an additional safety net, ensuring data integrity even if application-level
checks fail.
38
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
After successful booking creation, the selected seats have their status set to HELD
in the booking_detail records. This status indicates that the seats are temporarily
reserved for this booking but not yet confirmed. The seats will remain in HELD
status until payment is completed and the booking is approved, at which point the
status changes to BOOKED. If payment is not completed within 15 minutes,
the scheduled cleanup task will delete the booking and release the seats back to
AVAILABLE status.
The sequence diagram shows the successful path, but the actual implementation
handles various error scenarios. If member validation fails, the service throws
an exception indicating the member does not exist. If showtime validation
fails, an exception indicates the showtime is invalid. If the unique constraint is
violated (double booking attempt), the service catches the DataIntegrityVio-
lationException and converts it to a user-friendly error message indicating that
one or more seats are no longer available.
The most critical aspect of this sequence is the prevention of race conditions
through the unique constraint. When multiple users simultaneously attempt
to book the same seat, the database ensures that only one booking succeeds. The first
transaction to commit will create the booking_detail record, and subsequent
attempts will fail at the database level due to the unique constraint violation.
This database-level enforcement is more reliable than application-level locking
mechanisms and provides a robust solution to the concurrent booking problem.
Performance Considerations
39
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
Figure 4.3: Payment Process Sequence Sequences of the Online Cinema Booking System
40
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
Payment Initiation
The payment process begins when a member, after creating a booking and selecting
seats, decides to proceed with payment. The member interacts with the Frontend
application, typically on the ConfirmPayment page, where they review their
booking details including selected seats, showtime information, and total price.
When the member clicks the payment button or confirms their intention to pay, the
Frontend initiates the payment creation process.
41
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
The member is now on the VNPAY payment gateway website, where they
enter their payment information such as bank account details, card information, or
other payment methods supported by VNPAY. The VNPAY gateway processes the
payment securely, handling all sensitive financial information without exposing it to
the HDQ Cinema system. This external processing ensures PCI DSS compliance
and reduces the security burden on the cinema application.
When the response code is "00" (indicating successful payment), the PaymentSer-
vice verifies the payment callback’s authenticity by validating the secure hash. After
42
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
verification, the service calls the BookingService to approve the payment. The
BookingService updates the booking status from PENDING to CONFIRM in
the database and updates all associated BookingDetail records, changing the seat
status from HELD to BOOKED, permanently reserving the seats. The service
also deletes the PaymentURL record and returns a BookingResponse.
When the response code is "24" (indicating payment cancellation by the user), the
PaymentService handles the cancellation. The service deletes the PaymentURL
record and calls the BookingService to delete the entire booking and all associ-
ated BookingDetail records from the database. This releases the seats back to
AVAILABLE status, making them available for other members to book.
When the response code indicates payment failure (any code other than "00" or
"24"), the PaymentService throws an AppException with an appropriate error
code. This exception is caught by the PaymentController, which converts it into
an error response. The booking remains in PENDING status, and seats remain
in HELD status, allowing the member to potentially retry payment or allowing
the system’s scheduled cleanup task to eventually remove expired bookings.
Response to Frontend
43
System Design, Implementation and Testing Progress Chapter 4. Detail Process Design
Transaction Integrity
The sequence handles various edge cases including payment timeouts (handled by
the 15-minute expiration), payment failures, and network issues during callback
processing. The system’s scheduled cleanup task provides a safety net by removing
bookings that remain in PENDING status for more than 15 minutes, ensuring
that seats are eventually released even if payment processing encounters issues.
44
Chapter 5
Implementation Progress
– The system supports secure user registration (Member creation) and login
using JWT (JSON Web Token).
– Movies: Users can view movie lists and details, and filter movies by status
(showing/upcoming) or cinema. Admins possess the capability to create new
movie entries.
– Cinemas & Rooms: The system manages cinema lists, allows for the creation
of rooms, and supports detailed seat configuration for specific rooms.
45
System Design, Implementation and Testing Progress
Chapter 5. Implementation Progress
– Booking Logic:
∗ The system implements automatic seat holding (HELD status) during user
interaction.
∗ Race condition prevention is enforced via unique database constraints
to ensure no two users can book the same seat simultaneously.
∗ Dynamic total price calculation is performed based on selected seat types.
∗ Booking status is tracked through PENDING and CONFIRM states.
• Payment Integration:
– Successful integration with the VNPAY payment gateway has been achieved.
– The system calculates ticket prices flexibly based on Seat Type (VIP/Classic),
Day Type (Holiday/Weekend), and specific Cinema policies.
– A responsive design has been finalized for key pages, including the Homepage
(Movie Listing), Movie Details, Seat Selection, Payment Confirmation, and
Login pages.
46
System Design, Implementation and Testing Progress
Chapter 5. Implementation Progress
• Engagement & Promotions: Movie rating and reviews, Loyalty programs, and
Promotional codes/discounts.
47
Chapter 6
Testing Progress
1. Unit Tests:
• BookingService:
• PaymentService:
48
System Design, Implementation and Testing Progress Chapter 6. Testing Progress
• AuthenticationService:
• TicketPriceRepository:
• Repository Layer:
2. Integration Tests:
• Component Tests: Verify rendering and state for SeatSelection, SeatMap (status
display), Ticket (price display), and MovieItem.
49
System Design, Implementation and Testing Progress Chapter 6. Testing Progress
• Integration Tests:
• Frontend: Focus on Component Testing and Integration Testing for user flows
using mocked API responses.
50
System Design, Implementation and Testing Progress Chapter 6. Testing Progress
• Status: RESOLVED
• Status: RESOLVED
• Status: RESOLVED
• Status: RESOLVED
51
System Design, Implementation and Testing Progress Chapter 6. Testing Progress
Phase 3 (Medium-term): Implement E2E tests, Load testing, and Security testing.
52
Chapter 7
Conclusion
As of this reporting period, the HDQ Cinema - Online Movie Ticket Booking System
has successfully completed its core development phase, establishing a stable operational
platform built on a clear layered architecture of Spring Boot, ReactJS, and PostgreSQL.
The system now supports the complete end-user workflow, enabling seamless registration,
movie browsing, real-time seat selection, and secure payment processing via the VNPAY
gateway. Beyond standard functionality, the development team has effectively addressed
complex technical challenges, notably implementing specific database constraints to prevent
race conditions during concurrent bookings and deploying scheduled tasks to automatically
release expired seat holds, thereby ensuring data integrity and resource optimization.
Furthermore, the system demonstrates sophisticated business logic through its Dynamic
Pricing engine, which accurately handles complex price variations based on seat types,
weekends, and holidays. Security has also been prioritized with a robust JWT-based
authentication and authorization mechanism to protect user transactions. However, despite
these functional successes, the project currently faces a significant limitation regarding
quality assurance. The test coverage for both backend and frontend components remains
minimal at approximately 5
To address these gaps and finalize the ecosystem, the future development roadmap
is structured into three strategic phases. The immediate focus will be on consolidation,
prioritizing the implementation of unit and integration tests to achieve target coverage
rates of 80
References
53
Bibliography
[1] I. Sommerville, Software Engineering, 10th ed. Pearson Education Limited, 2016.
[3] IEEE Std 830-1998, IEEE Recommended Practice for Software Requirements Specifi-
cations, IEEE, 1998.
[4] ISO/IEC/IEEE 29148:2018, Systems and software engineering — Life cycle processes
— Requirements engineering, 2018.
[6] Visual Paradigm Online, “Use Case Diagram for Online Cinema Ticket Booking
System,” Available: [Link]
[9] [Link], “ERD and Use Case Diagrams for Online Ticket Booking System,” 2023.
Available: [Link]
54