How acocinas/s501advancedspringframeworkwithwebflux works
Project Type and Purpose
• This is a reactive, full-stack backend service (a single microservice/monolith) built with Spring Boot WebFlux. Its purpose is to expose a REST API to play Blackjack, managing game state in MongoDB and player data in MySQL, all packaged and deployed via Docker Compose with Swagger documentation.
File Structure Analysis
• Top-level “blackjack-api” directory contains:
• Configuration files: Dockerfile, docker-compose.yml, Maven wrapper, .gitignore, .dockerignore
• src/main/java/com/blackjack/blackjack_api:
– config: MongoConfig, R2dbcConfig, SwaggerConfig, WebFluxConfig
– controller: GameController, PlayerController
– dto: request/response mappings and mappers
– enums: domain constants (GameStatus, Rank, Suit)
– exception: custom exceptions + GlobalExceptionHandler
– interfaces: layered abstractions for repositories (mongo, mysql) and services
– model: domain entities (Game, Player, Deck, Card, Hand)
– service: business logic implementations
• src/main/resources: application.yml, init.sql
• src/test: unit and controller tests
• Key architectural patterns:
• Layered architecture (Controller → Service → Repository)
• Reactive streams (WebFlux, Spring Data R2DBC for MySQL, Reactive Mongo driver)
• Docker-based deployment for service + MongoDB + MySQL
• Client(s): Web or mobile app, Postman, Swagger UI
• API Layer (Spring WebFlux):
• HTTP Server / Router
• Controllers (GameController, PlayerController)
• GlobalExceptionHandler
• Service Layer:
• GameServiceImplement
• PlayerService
• Data Access Layer:
• Reactive MongoDB Repository (GameRepository)
• R2DBC MySQL Repository (PlayerRepository)
• Databases:
• MongoDB (container)
• MySQL (container)
• Infrastructure:
• Docker Compose orchestration
• Swagger/OpenAPI documentation
1. Client → HTTP Server (REST calls)
2. HTTP Server → Controller → Service
3. Service → appropriate Repository
– Game state reads/writes → MongoDB
– Player CRUD/ranking → MySQL
4. Repository → Database (reactive driver) → back up chain to Client
5. API exposes OpenAPI spec → Swagger UI (external browser)
c. Architectural Patterns & Principles:
• Reactive non-blocking I/O end-to-end
• Separation of concerns per layer
• Abstraction of data stores via repository interfaces
• Centralized error handling (GlobalExceptionHandler)
• DTO mapping to shield controllers from domain entities
d. Key Technologies:
• Spring Boot WebFlux, Spring Data R2DBC, Spring Data Reactive MongoDB
• Swagger / springdoc-openapi
• Docker, Docker Compose
• Maven, JUnit, Mockito
Essential Elements
• Component labels: “GameController”, “PlayerRepository (R2DBC)”, etc.
• Docker Compose overlay showing container-to-container networking.