Overview
Welcome to the Blackjack API project! This guide will help you understand the development workflow, coding standards, and best practices for contributing to this project.Prerequisites
Before you begin, ensure you have the following installed:- Java 21 or higher
- Maven 3.8+ (or use the included
./mvnwwrapper) - Docker & Docker Compose (for local database setup)
- Git for version control
- IDE (IntelliJ IDEA recommended)
Development Setup
1. Clone the Repository
2. Start Local Databases
The project requires MongoDB and MySQL. Use Docker Compose to start both:- MongoDB on
localhost:27017 - MySQL on
localhost:3306
3. Run the Application
Start the Spring Boot application:http://localhost:8080
4. Verify Setup
Access the Swagger UI to verify the setup:Project Structure
The project follows Hexagonal Architecture (Ports & Adapters) with clear separation of concerns:Architecture Principles
Domain Layer
- Pure business logic
- No framework dependencies
- Defines ports (interfaces)
- Contains aggregates and value objects
Application Layer
- Orchestrates use cases
- Coordinates domain objects
- Transaction boundaries
- Uses domain ports
Infrastructure Layer
- Implements domain ports
- Handles HTTP, database, external services
- Framework-specific code
- Configuration
Reactive Programming
- Uses Spring WebFlux
- Reactive MongoDB and R2DBC
- Non-blocking operations
- Returns Mono/Flux types
Coding Standards
Java Style
- Java 21 language features are encouraged
- Use Lombok for reducing boilerplate (
@Data,@Builder, etc.) - Follow standard Java naming conventions
- Keep methods small and focused (Single Responsibility)
- Prefer immutability where possible
Domain-Driven Design
Aggregates
Aggregates
GameandPlayerare the main aggregates- Aggregates enforce business invariants
- Use aggregate roots for external access
Value Objects
Value Objects
PlayerId,GameId,PlayerName,Card,Hand, etc.- Immutable and validated on creation
- Represent domain concepts
Repository Ports
Repository Ports
- Defined in
domain/port/ - Implemented in
infrastructure/persistence/ - Return reactive types (
Mono,Flux)
Use Cases
Use Cases
- One class per use case
- Clear
execute()method - Orchestrate domain logic
Reactive Patterns
All asynchronous operations use Project Reactor:Exception Handling
- Domain exceptions (
GameNotFoundException,InvalidMoveException, etc.) indomain/exception/ - Global exception handler in
infrastructure/web/error/GlobalExceptionHandler - Map domain exceptions to appropriate HTTP status codes
Development Workflow
Branch Strategy
Follow a feature branch workflow:- main - Production-ready code
- feature/ - New features (
feature/add-multiplayer) - fix/ - Bug fixes (
fix/dealer-bust-calculation) - refactor/ - Code refactoring (
refactor/simplify-game-logic) - test/ - Test improvements (
test/add-ranking-tests) - docs/ - Documentation updates (
docs/update-api-specs)
Creating a Feature
- Create a new branch from
main:
- Make your changes following the coding standards
- Write tests for your changes (see Testing Guide)
- Run tests locally:
- Commit your changes using conventional commits
Commit Conventions
Follow Conventional Commits specification:Commit Format
Commit Types
| Type | Description | Example |
|---|---|---|
feat | New feature | feat: add multiplayer support |
fix | Bug fix | fix: correct dealer bust detection |
refactor | Code refactoring | refactor: simplify Hand calculation |
test | Add or update tests | test: add integration tests for ranking |
docs | Documentation changes | docs: update API documentation |
style | Code style changes | style: format code with prettier |
perf | Performance improvements | perf: optimize card shuffling algorithm |
chore | Maintenance tasks | chore: update dependencies |
Commit Examples
Commit Best Practices
- Keep commits small and focused on a single change
- Write clear and descriptive commit messages
- Use present tense (“add” not “added”)
- Reference issue numbers if applicable:
fix: correct scoring (#42) - Do not commit:
- Secrets or credentials
- Compiled files (
.class,target/) - IDE-specific files (use
.gitignore) - Large binary files
Testing Requirements
All contributions must include appropriate tests:- ✅ Domain changes require domain unit tests
- ✅ Use case changes require application tests with mocked repositories
- ✅ Controller changes require WebTestClient integration tests
- ✅ All tests must pass before submitting a pull request
Pull Request Process
1. Prepare Your Branch
Ensure your branch is up to date:2. Create Pull Request
- Push your branch to GitHub
- Create a pull request against
main - Use a descriptive PR title (following conventional commit format)
- Provide a clear description of changes
PR Template
3. Code Review
- Address reviewer feedback
- Keep the PR focused and small when possible
- Use
git commit --fixupfor review changes if appropriate
4. Merge
Once approved:- Ensure all tests pass
- Squash commits if needed
- Merge to
main
Database Migrations
MySQL schema changes use Flyway:- Create a new migration file in
src/main/resources/db/migration/ - Follow naming convention:
V{version}__{description}.sql- Example:
V2__add_player_statistics.sql
- Example:
- Test migration locally:
API Documentation
- Keep Swagger/OpenAPI annotations up to date
- Document all REST endpoints with
@Operation,@ApiResponse - Test documentation at
http://localhost:8080/swagger-ui.html
Code Review Guidelines
When reviewing code:Check for adherence to hexagonal architecture
Verify domain logic is in the domain layer
Ensure tests cover the changes
Look for proper error handling
Verify reactive patterns are used correctly
Check commit messages follow conventions
Getting Help
If you need help:- Review existing code for patterns and examples
- Check the Architecture Overview
- Consult the API Reference
- Open a discussion on GitHub
Additional Resources
Testing Guide
Comprehensive testing strategy and examples
Architecture
Understand the hexagonal architecture
API Reference
Complete API documentation
GitHub Repository
View source code and issues