How rioacosta/s5-01-blackjack-with-webflux works
Project Type and Purpose
• This is a reactive backend service (microservice/API) built with Spring Boot + WebFlux.
• Purpose: expose a Blackjack game API with endpoints to create/play games, manage players, and fetch rankings.
• Deployed via Docker Compose alongside two datastore containers (MySQL and MongoDB).
File Structure
Top-level:
• pom.xml, maven wrapper: standard Java/Spring Boot build
• Dockerfile, docker-compose.yml: containerization and orchestration
• init.sql: schema/seed file for MySQL
src/main/java/cat/itacademy/.../controllers:
• HTTP entry points (GameController, PlayerController, RankingController)
src/main/.../services:
• Business logic layer (GameService, PlayerService, RankingService)
src/main/.../repository:
• Reactive data access layer (GameRepository, PlayerRepository)
src/main/.../model & dto:
• Domain objects and transport DTOs
src/main/resources/application.properties:
• Service configuration (ports, DB connections, Swagger/Actuator)
README for Technical Stack & Runtime
• Java 21, Spring Boot, Spring WebFlux (reactive)
• MongoDB (NoSQL) for game persistence
• MySQL (via init.sql) – likely for relational data or compatibility
• Docker & Docker Compose orchestrate three containers:
– Blackjack API (port 8080)
– MongoDB (port 27017)
– MySQL (port 3307)
• Swagger/OpenAPI, Actuator health checks
Main Components
a. Clients:
– HTTP clients (Postman, frontend, curl)
– Swagger UI / OpenAPI Docs
b. Blackjack API Service:
– Controllers (HTTP Router)
– Service Layer (reactive business logic)
– Repository Layer (reactive data access)
– GlobalExceptionHandler (error handling)
c. Datastores:
– MongoDB container (Reactive driver)
– MySQL container (JDBC, init.sql)
d. Support & Infrastructure:
– Docker Compose network
– Spring Actuator endpoints
Relationships & Data Flows
• Client → HTTP request → Controller
• Controller → calls Service (Mono/Flux)
• Service → reads/writes via Repository
• Repository → connects to MongoDB or MySQL
• Service → returns reactive stream → Controller → HTTP response
• Swagger UI ↔ Blackjack API (served as static resources)
• Actuator → Blackjack API internals
Architectural Patterns & Design Principles
• Layered architecture:
– Presentation (Controllers)
– Business (Services)
– Data (Repositories)
• Reactive, non-blocking I/O via Spring WebFlux (Flux/Mono pipelines)
• Domain-driven design: clear separation of model, DTO, exception types
• Containerized deployment: each component in its own Docker container
• External configurability: application.properties, Docker Compose