# acocinas/s501advancedspringframeworkwithwebflux architecture

> Architecture diagram of the GitHub repository acocinas/s501advancedspringframeworkwithwebflux, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/acocinas/s501advancedspringframeworkwithwebflux
- Repository: https://github.com/acocinas/s501advancedspringframeworkwithwebflux

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        A1["Web/Mobile App"]:::client
        A2["Swagger UI"]:::client
        A3["Postman/HTTP Client"]:::client
    end

    subgraph "API Layer"
        subgraph "Configuration"
            CFG1["WebFluxConfig"]:::api
            CFG2["SwaggerConfig"]:::api
            CFG3["MongoConfig"]:::api
            CFG4["R2dbcConfig"]:::api
        end
        WFX["HTTP Server/Router"]:::api
        SWG["Swagger/OpenAPI"]:::api
        C1["GameController"]:::api
        C2["PlayerController"]:::api
        EXC["GlobalExceptionHandler"]:::api
    end

    subgraph "Service Layer"
        S1["GameServiceImplement"]:::service
        S2["PlayerService"]:::service
    end

    subgraph "Data Access Layer"
        R1["GameRepository (Reactive MongoDB)"]:::repo
        R2["PlayerRepository (R2DBC MySQL)"]:::repo
    end

    subgraph "Databases"
        DB1["MongoDB"]:::db
        DB2["MySQL"]:::db
    end

    subgraph "Infrastructure"
        DC["Docker Compose"]:::infra
    end

    A1 -->|HTTP REST| WFX
    A3 -->|HTTP REST| WFX
    A2 -->|"UI for OpenAPI spec"| SWG

    CFG1 --> WFX
    CFG2 --> SWG
    CFG3 --> R1
    CFG4 --> R2

    WFX -->|"dispatch"| C1
    WFX -->|"dispatch"| C2
    C1 -.-> EXC
    C2 -.-> EXC

    C1 -->|"Flux<Game>/Mono<Game"| S1
    C2 -->|"Mono<Player>/Flux<Player"| S2

    S1 -->|"reactive CRUD"| R1
    S2 -->|"reactive CRUD"| R2

    R1 -->|"BSON"| DB1
    R2 -->|"R2DBC"| DB2

    SWG -->|serves spec| WFX

    DC -->|"orchestrates"| WFX
    DC -->|"orchestrates"| DB1
    DC -->|"orchestrates"| DB2

    classDef client fill:#f4cccc,stroke:#333
    classDef api fill:#cfe2f3,stroke:#333
    classDef service fill:#d9ead3,stroke:#333
    classDef repo fill:#fce5cd,stroke:#333
    classDef db fill:#ffe599,stroke:#333
    classDef infra fill:#d9d2e9,stroke:#333

    click CFG1 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/config/WebFluxConfig.java"
    click CFG2 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/config/SwaggerConfig.java"
    click CFG3 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/config/MongoConfig.java"
    click CFG4 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/config/R2dbcConfig.java"
    click C1 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/controller/GameController.java"
    click C2 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/controller/PlayerController.java"
    click EXC "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/exception/handler/GlobalExceptionHandler.java"
    click S1 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/service/GameServiceImplement.java"
    click S2 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/service/PlayerService.java"
    click R1 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/interfaces/repository/mongo/GameRepository.java"
    click R2 "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/src/main/java/com/blackjack/blackjack_api/interfaces/repository/mysql/PlayerRepository.java"
    click DC "https://github.com/acocinas/s501advancedspringframeworkwithwebflux/blob/main/blackjack-api/docker-compose.yml"
```
