Skip to content

CodingMiner/cinema-book

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 CinemaBook

A full-featured cinema ticket reservation system built with Java 21, Spring Boot, and vanilla JavaScript. Browse screenings, pick your seats on an interactive seat map, and reserve β€” all with real-time availability, dynamic pricing, and concurrency protection.

Java Spring Boot H2 Tests


✨ Features

🎟️ Reservation Flow

  • Interactive seat map β€” CSS Grid layout with color-coded seat types (Accessible, Standard, Premium)
  • 15-minute seat locking β€” selected seats are held while you complete your booking
  • Lazy lock expiry β€” no background jobs; expired locks are detected on read
  • Full lifecycle β€” PENDING β†’ CONFIRMED β†’ CANCELLED or EXPIRED

πŸ’° Dynamic Pricing

Occupancy Tier Multiplier
< 50% 🟒 BASE Γ—1.00
50–79% 🟑 MID Γ—1.25
β‰₯ 80% πŸ”΄ HIGH Γ—1.50

Prices are locked at reservation time β€” no surprises on confirmation.

πŸ”’ Concurrency Protection

  • Pessimistic locking on seat selection prevents double-booking
  • Pessimistic locking on user row prevents active reservation count races
  • Adjacent seat and same-row enforcement for group bookings

πŸ“‹ Business Rules

  • Max 10 seats per reservation
  • Max 3 active reservations per customer
  • All seats must be adjacent in the same row
  • Booking closes 30 minutes before screening starts
  • Payment modeled as status: PENDING β†’ PAID β†’ REFUNDED

πŸš€ Quick Start

Prerequisites

  • Java 21+
  • Maven 3.8+

That's it β€” no Docker, no external database, no npm.

Run

mvn spring-boot:run

Open

Endpoint URL
🎬 App http://localhost:8080
πŸ“– Swagger UI http://localhost:8080/swagger-ui.html
πŸ—„οΈ H2 Console http://localhost:8080/h2-console

Pre-seeded Data

The app seeds reference data on startup:

Type Details
πŸ‘€ Admin User ID 1
πŸ‘₯ Customers User IDs 2, 3, 4
πŸŽ₯ Movies Inception, The Dark Knight, Interstellar
πŸ›οΈ Hall Hall A (10 rows Γ— 12 seats)
πŸ“… Screenings 3 screenings with different times

πŸ§ͺ Testing

Run All Tests

mvn clean test

Test Suite Breakdown

Suite Count Description
Unit tests 44 Service logic with Mockito
Integration tests 44 MockMvc end-to-end with @SpringBootTest
πŸ₯’ BDD scenarios 58 Cucumber feature files covering 12 user stories + 1 full-lifecycle scenario
Total 146 All passing βœ…

Run a Single Test Class

mvn test -Dtest=ReservationServiceTest

BDD Feature Files

Cucumber scenarios live under src/test/resources/features/:

Feature User Story Scenarios
us003-seat-map.feature View seat map 5
us004-initiate-reservation.feature Initiate reservation 9
us005-confirm-reservation.feature Confirm reservation 4
us006-auto-lock-expiry.feature Automatic lock expiry 5
us007-cancel-reservation.feature Cancel reservation 5
us008-view-reservations.feature View my reservations 4
us009-user-identification.feature User identification 4
us013-concurrent-booking.feature Concurrent booking 2
us017-booking-cutoff.feature Booking cutoff 4
us018-adjacent-seat-enforcement.feature Adjacent seats 5
us019-dynamic-pricing.feature Dynamic pricing 5
us020-active-reservation-limit.feature Reservation limit 4
full-lifecycle.feature End-to-end lifecycle 2

After running tests, check target/cucumber-reports.html for a formatted BDD report.


πŸ—οΈ Architecture

Tech Stack

Layer Technology
Language Java 21
Framework Spring Boot 3.3.11
ORM Spring Data JPA / Hibernate
Database H2 (file-based, persists across restarts)
API Docs Springdoc OpenAPI 2.5.0
Frontend Vanilla JS + HTML5 + CSS3 (single file)
Testing JUnit 5, Mockito, MockMvc, Cucumber 7.18
Code Gen Lombok

Project Structure

com.cinemabooking
β”œβ”€β”€ 🎬 movie/           # Movie entity + repository
β”œβ”€β”€ πŸ›οΈ hall/            # Hall, Seat entities + repositories
β”œβ”€β”€ πŸ“… screening/       # Screening, ShowSeat, controller, service, DTOs
β”œβ”€β”€ 🎟️ reservation/    # Reservation, ReservationSeat, controller, service, DTOs
β”œβ”€β”€ πŸ‘€ user/            # User entity + repository, UserRole enum
└── πŸ”§ shared/          # Enums, ErrorResponse, GlobalExceptionHandler, DataSeeder, PricingCalculator

Entity Relationships

Movie ──1:N── Screening ──1:N── ShowSeat ──N:1── Seat ──N:1── Hall
                  β”‚
                  └──1:N── Reservation ──1:N── ReservationSeat ──N:1── ShowSeat
                               β”‚
                               └──N:1── User

Key Design Decisions

  • πŸ—„οΈ No external infrastructure β€” H2 file DB, no Redis, no message queues
  • ⏰ Lazy expiry β€” no scheduled jobs; ShowSeat.getEffectiveStatus() checks lockedUntil
  • πŸ” Pessimistic locking β€” @Lock(PESSIMISTIC_WRITE) on seat and user queries
  • πŸ’΅ Price snapshots β€” prices calculated at initiation, stored in ReservationSeat
  • πŸ“‹ Spec-first API β€” contract defined in openapi.yaml, no annotations on Java code
  • 🧹 No auth framework β€” identity via X-User-Id header (training project focus is business logic)

πŸ“‘ API Endpoints

Method Endpoint Description
GET /api/screenings/{id}/seats πŸ—ΊοΈ Seat map with pricing & availability
POST /api/reservations 🎟️ Initiate reservation (lock seats)
POST /api/reservations/{code}/confirm βœ… Confirm reservation
POST /api/reservations/{code}/cancel ❌ Cancel reservation
GET /api/reservations πŸ“‹ List user's reservations

All mutation endpoints require the X-User-Id header.


πŸ–₯️ Frontend

Single-file app at src/main/resources/static/index.html:

  • πŸŒ™ Dark cinema theme with CSS custom properties
  • πŸͺ‘ Interactive seat grid β€” click to select, color-coded by type and status
  • πŸ’΅ Live pricing β€” pricing tier badge + per-type price table
  • ⏱️ Countdown timer β€” shows remaining lock time on pending reservations
  • πŸ“± Responsive β€” breakpoints at 700px and 480px
  • πŸ“‹ My Reservations tab β€” filter by status, cancel confirmed bookings

πŸ“„ Documentation

File Description
prd.md Product requirements & user stories
tech-stack.md Technology choices & constraints
decisions.md Architectural decision log
CLAUDE.md AI assistant instructions
testing-rules.md Test conventions & patterns

πŸ“œ License

This is a training/demo project. No license specified.

About

Full-stack cinema reservation system - interactive seat maps, real-time availability, dynamic pricing and concurrency-safe booking. Built with Java 21, Spring Boot & vanilla JS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors