# rioacosta/s5-01-blackjack-with-webflux architecture

> Architecture diagram of the GitHub repository rioacosta/s5-01-blackjack-with-webflux, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rioacosta/s5-01-blackjack-with-webflux
- Repository: https://github.com/rioacosta/s5-01-blackjack-with-webflux

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Clients["HTTP Clients (Postman, curl, frontend)"]:::external
    Swagger["Swagger UI / OpenAPI"]:::external
    Actuator["Spring Actuator"]:::external

    %% Docker Compose Network
    subgraph "docker-compose"
        direction TB
        subgraph "blackjack-api (port 8080)"
            direction TB
            App["S501BlackjackWithWebFluxApplication"]:::entry
            subgraph "Controllers"
                direction TB
                GC["GameController"]:::controller
                PC["PlayerController"]:::controller
                RC["RankingController"]:::controller
            end
            subgraph "Services"
                direction TB
                GS["GameService"]:::service
                PS["PlayerService"]:::service
                RS["RankingService"]:::service
            end
            subgraph "Repositories"
                direction TB
                GR["GameRepository"]:::repository
                PR["PlayerRepository"]:::repository
            end
            subgraph "Domain Models & DTOs"
                direction TB
                ModelGame["Game"]:::model
                ModelPlayer["Player"]:::model
                ModelCards["Cards"]:::model
                ModelSuit["CardSuitEnum"]:::model
                ModelValue["CardValueEnum"]:::model
                DTOCreateGame["CreateGameRequestDTO"]:::dto
                DTOPlay["PlayRequestDTO"]:::dto
                DTOCreatePlayer["CreatePlayerRequestDTO"]:::dto
                DTORanking["RankingResponseDTO"]:::dto
            end
            subgraph "Exceptions & Handling"
                direction TB
                ExHandler["GlobalExceptionHandler"]:::exception
                ExNotFound["GameNotFoundException"]:::exception
                ExFinished["GameAlreadyFinishedException"]:::exception
                ExPlayerNotFound["PlayerNotFoundException"]:::exception
                ExDuplicate["DuplicatePlayerException"]:::exception
            end
            Config["application.properties"]:::config
        end
        Mongo["MongoDB (27017)"]:::datastore
        MySQL["MySQL (3307)"]:::datastore
        SQLInit["init.sql (volume)"]:::dockerfile
    end

    %% Connections
    Clients -->|HTTP| GC
    Clients -->|HTTP| PC
    Clients -->|HTTP| RC
    Swagger -->|Served via API| App
    Actuator -->|Metrics/Health| App

    GC -->|"calls"| GS
    PC -->|"calls"| PS
    RC -->|"calls"| RS

    GS -->|"uses"| GR
    PS -->|"uses"| PR
    RS -->|"uses"| GR
    RS -->|"uses"| PR

    GR -->|Reactive driver| Mongo
    PR -->|JDBC| MySQL
    SQLInit -.->|Initial schema| MySQL

    App --> GC
    App --> PC
    App --> RC
    App --> Config
    App --> ExHandler

    %% Click Events
    click App "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/S501BlackjackWithWebFluxApplication.java"
    click GC "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/controllers/GameController.java"
    click PC "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/controllers/PlayerController.java"
    click RC "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/controllers/RankingController.java"
    click GS "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/services/GameService.java"
    click PS "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/services/PlayerService.java"
    click RS "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/services/RankingService.java"
    click GR "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/repository/GameRepository.java"
    click PR "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/repository/PlayerRepository.java"
    click ModelGame "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/model/Game.java"
    click ModelPlayer "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/model/Player.java"
    click ModelCards "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/model/Cards.java"
    click ModelSuit "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/model/CardSuitEnum.java"
    click ModelValue "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/model/CardValueEnum.java"
    click DTOCreateGame "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/dto/CreateGameRequestDTO.java"
    click DTOPlay "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/dto/PlayRequestDTO.java"
    click DTOCreatePlayer "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/dto/CreatePlayerRequestDTO.java"
    click DTORanking "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/dto/RankingResponseDTO.java"
    click ExHandler "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/exceptions/GlobalExceptionHandler.java"
    click ExNotFound "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/exceptions/GameNotFoundException.java"
    click ExFinished "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/exceptions/GameAlreadyFinishedException.java"
    click ExPlayerNotFound "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/exceptions/PlayerNotFoundException.java"
    click ExDuplicate "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/exceptions/DuplicatePlayerException.java"
    click Config "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/main/resources/application.properties"
    click SQLInit "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/init.sql"
    click MySQL "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/docker-compose.yml"
    click Mongo "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/docker-compose.yml"
    click AppDockerfile "https://github.com/rioacosta/s5-01-blackjack-with-webflux/tree/master/Dockerfile"
    click AppDockerfile "https://github.com/rioacosta/s5-01-blackjack-with-webflux/tree/master/Dockerfile"
    click Tests "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/test/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/S501BlackjackWithWebFluxApplicationTests.java"
    click Tests "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/test/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/controllers/GameControllerTest.java"
    click Tests "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/src/test/java/cat/itacademy/S5_01_Blackjack_With_WebFlux/services/PlayerServiceTest.java"
    click Pom "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/pom.xml"
    click MavenWrapper "https://github.com/rioacosta/s5-01-blackjack-with-webflux/tree/master/mvnw"
    click MavenWrapperCmd "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/mvnw.cmd"
    click MavenProps "https://github.com/rioacosta/s5-01-blackjack-with-webflux/blob/master/.mvn/wrapper/maven-wrapper.properties"

    %% Styles
    classDef external fill:#E8F0FE,stroke:#0B5394,color:#0B5394
    classDef entry fill:#FFF2CC,stroke:#BF9000,color:#BF9000
    classDef controller fill:#D9EAD3,stroke:#38761D,color:#38761D
    classDef service fill:#FCE5CD,stroke:#E69138,color:#E69138
    classDef repository fill:#D0E0E3,stroke:#134F5C,color:#134F5C
    classDef model fill:#F4CCCC,stroke:#990000,color:#990000
    classDef dto fill:#C9DAF8,stroke:#1155CC,color:#1155CC
    classDef exception fill:#EAD1DC,stroke:#912F5E,color:#912F5E
    classDef config fill:#E2EFDA,stroke:#6AA84F,color:#6AA84F
    classDef datastore fill:#F9CB9C,stroke:#B45F06,color:#B45F06
    classDef docker fill:#D9D2E9,stroke:#674EA7,color:#674EA7
    classDef dockerfile fill:#FFE599,stroke:#BF9000,color:#BF9000
```
