A cinema ticket booking system built with ASP.NET Core and MongoDB, featuring optimistic locking for concurrent booking management.
- User authentication with JWT
- Movie and hall management
- Showtime scheduling
- Seat booking with concurrency control
- MongoDB replica set with transactions
- RESTful API with Swagger documentation
- .NET 9.0
- ASP.NET Core Web API
- MongoDB 7.0
- Docker & Docker Compose
- MongoDB.Driver
- JWT Bearer Authentication
- xUnit for testing
TicketBookingSystem/
├── TicketBookingSystem.Domain/
│ ├── Entities/
│ └── Enums/
├── TicketBookingSystem.Infrastructure/
│ ├── Data/
│ ├── Repositories/
│ └── Services/
├── TicketBookingSystem.Api/
│ ├── Controllers/
│ └── DTOs/
└── TicketBookingSystem.Tests/
- API depends on Infrastructure and Domain
- Infrastructure depends on Domain
- Tests depend on all layers
- .NET 9.0 SDK
- Docker Desktop
Clone the repository:
git clone <repository-url>
cd TicketBookingSystemStart MongoDB with Docker Compose:
docker compose up -dRun the application:
cd TicketBookingSystem.Api
dotnet runThe API will be available at http://localhost:5220
Access Swagger UI at http://localhost:5220 when the application is running.
POST /api/auth/register- Register new userPOST /api/auth/login- User login
GET /api/movies- List all moviesGET /api/movies/{id}- Get movie by IDGET /api/movies/title/{title}- Get movie by titleGET /api/movies/genre/{genre}- Get movies by genrePOST /api/movies- Create movie
GET /api/halls- List all hallsGET /api/halls/{id}- Get hall by IDPOST /api/halls- Create hall
GET /api/showtimes- List all showtimesGET /api/showtimes/{id}- Get showtime by IDGET /api/showtimes/{id}/available-seats- Get available seatsPOST /api/showtimes- Create showtime
GET /api/bookings/my- Get user bookingsGET /api/bookings/{id}- Get booking by IDPOST /api/bookings- Create bookingDELETE /api/bookings/{id}- Cancel booking
MongoDB runs in a Docker container on port 27017. Database name is TicketBookingDb.
users- User accountsmovies- Movie cataloghalls- Cinema hallsshowtimes- Movie showtimesbookings- Ticket bookings
Access Mongo Express at http://localhost:8081 for database management.
Configuration is in appsettings.json:
{
"MongoDbSettings": {
"ConnectionString": "mongodb://admin:admin123@localhost:27017/?authSource=admin&replicaSet=rs0",
"DatabaseName": "TicketBookingDb"
},
"JwtSettings": {
"SecretKey": "YourSuperSecretKeyForJwtTokenGeneration123456789",
"Issuer": "TicketBookingSystem",
"Audience": "TicketBookingUsers",
"ExpiryMinutes": 60
}
}Note: The credentials above are for local development only. For production, use environment variables or secure configuration management.
Run unit tests:
dotnet testBuild the solution:
dotnet buildClean build artifacts:
dotnet cleanThe system uses optimistic locking with version fields to handle concurrent booking requests. MongoDB transactions ensure data consistency across operations.
- Each showtime has a version field
- Booking updates check the version
- Failed updates trigger retry (up to 3 attempts)
- Transactions guarantee atomicity
Start services:
docker compose up -dStop services:
docker compose downView logs:
docker compose logs -f mongodbRemove all data:
docker compose down -vMIT