How cinsara/itacademy_sprint5.01_blackjack works
Project type and purpose
• This is a backend API for a Blackjack game built on Spring Boot with a reactive WebFlux stack.
• It is not a full UI-driven front-end project; it’s a microservice-style RESTful API that handles gameplay, player management, rankings, and session persistence.
• It provides endpoints for creating games, playing moves, deleting games, retrieving rankings, updating player info, and is designed to be containerized via Docker.
File structure
Top-level artifacts:
• Dockerfile, .dockerignore, docker-compose.yml → containerization/deployment
• build.gradle, gradlew scripts → build system (Gradle)
• src/main/java/com/example/demo/
• controllers → API layer (GameController, PlayerController)
• dto → request/response objects (BetRequest, GameRequest, etc.)
• services → business logic (GameService, PlayerService, GameAction)
• repositories → data access (Reactive Mongo and R2DBC/MySQL)
• model → domain objects (Game, Player, Card, Deck)
• exceptions & utils → global error handling and helper functions
• src/main/resources → properties (application.properties, Docker profile), schema.sql for MySQL
• src/test → unit and integration tests, Testcontainers for MySQL/Mongo spin-up
README for additional insights
• Reactive Stack: uses Spring WebFlux → non-blocking I/O
• Dual Databases:
• MongoDB for session data (hands, games)
• MySQL for persistent player data and rankings
• Swagger integration for API docs
• GlobalExceptionHandler to centralize error responses
• Docker Support: image build + docker-compose orchestration
a. Main components:
• API Layer (WebFlux)
• GameController
• PlayerController
• Service Layer
• GameService & GameAction (gameplay rules)
• PlayerService (player CRUD & ranking)
• Data Access Layer
• GameRepository (MongoDB reactive driver)
• PlayerRepository (R2DBC/MySQL)
• Databases
• MongoDB (game sessions)
• MySQL (player data, rankings)
• Infrastructure & Tools
• Swagger/OpenAPI
• Docker & Docker-Compose
• Gradle build & CI/CD pipelines (if present)
b. Relationships and interactions:
• Client → HTTP over port 8080 → WebFlux controllers
• Controllers invoke Services → Services call Repositories
• Repositories talk to either MongoDB or MySQL
• Errors propagate up to GlobalExceptionHandler
• Swagger UI sits alongside controllers for exploration
• Docker Compose wires up app container + Mongo + MySQL
c. Architectural patterns & principles:
• Layered Architecture (Controller → Service → Repository)
• Reactive Programming (Flux/Mono pipelines)
• Exception Handling (Centralized advice controller)
• DTO mapping to decouple API contract from domain model
d. Key technologies:
• Java 21, Spring Boot 3+, Spring WebFlux
• Reactive MongoDB driver, R2DBC for MySQL
• Swagger / Springdoc OpenAPI, JUnit 5, Testcontainers