How youkaba/cards-game works
Project Type and Purpose
• This project is a Java-based REST API application built with Spring Boot and Maven. Its purpose is to simulate a basic deck of playing cards game, where multiple players interact with a “game deck” formed by one or more standard 52-card decks.
• The README explicitly lists operations such as game creation/deletion, deck manipulation, card dealing, and querying players’ hands and remaining cards per suit. It also requires an in-memory datastore with custom concurrency handling and event logging for changes.
File Structure
• The overall structure follows a layered, hexagonal (or ports and adapters) architecture, splitting the application into clearly defined components:
• The adapter layer is split into two directories:
• "adapters/primary" holds the entry points (REST controllers) and configuration classes. For example, CardsGameApplication.java is the main Spring Boot application, and the controllers (e.g., DeckController, GameController, PlayerController) expose the REST API.
• "adapters/secondary" holds the gateway implementations (e.g., InMemoryDeckRepository, InMemoryGameRepository) that fulfill repository interfaces.
• The "businesslogic" folder encapsulates:
• Domain models (e.g., Card, Deck, Game, Player, Suit).
• Use case implementations (e.g., CreateGame, AddPlayer, DealCard, etc.) which detail the core behaviors.
• Exception handling for domain-specific errors.
• Configuration files (RepositoriesConfiguration.java, UseCaseConfiguration.java) indicate dependency injection and wiring of these components.
• Other elements such as application.properties and test suites in the "src/test" folder further confirm the structured, testable design.
a. Main components:
• Presentation Layer (Primary Adapter):
• REST Controllers that expose endpoints for game operations (DeckController, GameController, PlayerController).
• The main application entry point (CardsGameApplication.java) and configuration classes.
• Business Logic Layer:
• Use Cases representing operations (CreateGame, DealCard, AddPlayer, etc.)
• Domain models representing Card, Deck, Game, and Player.
• Exception modules handling error cases.
• Persistence/Infrastructure Layer (Secondary Adapter):
• Repository interfaces defined in the businesslogic layer (DeckRepository, GameRepository).
• Implementations of these interfaces (InMemoryDeckRepository, InMemoryGameRepository) that provide in-memory datastore support with built-in concurrency handling.
• Event Handling Component:
• Although not isolated in its own module, the design includes triggering events when actions occur to record history changes; indicate this as a separate “Event Logging” component that interacts with each layer as required.
b. Relationships and Interactions:
• Client requests entering the system via the REST controllers.
• That use cases depend on repository interfaces (ports) and that the implementations (adapters/secondary) fulfill those contracts.
• Optionally, show configuration classes wiring these dependencies.
c. Architectural Patterns and Design Principles:
• Hexagonal/ports-and-adapters architecture: The “primary” adapters expose the API, while “secondary” adapters abstract underlying storage.
• Separation of concerns between presentation (controllers), business rules (use cases, domain models), and infrastructure (in-memory repositories).
• That dependency injection (via Spring Boot configuration classes) is used to manage component wiring.
• Patterns such as Repository Pattern (using interfaces and in-memory implementations) and use of RESTful API principles.
d. Relevant Technologies and Frameworks:
• Java 17 and Spring Boot 3.x as the base technology.
• Maven (pom.xml, mvnw, mvnw.cmd) for build configuration.
• In-memory data handling with custom concurrency support.
• The event triggering and logging requirement.
• Testing frameworks used in unit tests (as observed in the “src/test” folder).