Skip to content

esnelubov/jack-black

Repository files navigation

JackBlack

A little REST blackjack game

Requirements

This code was tested with the configuration:

  • Ubuntu 22.04
  • Go 1.17
  • PostgreSQL 14

Installation

On local machine

Set your PostgreSQL DSN in .env file
$ make -f Makefile build install-migrate apply-migrations
$ ./cmd/backend

Using docker

$ docker compose up
$ docker exec BACKEND_CONTAINER_NAME make -f Makefile apply-migrations

Usage

You can access the game backend using Postman or using the provided command-line client:

$ ./cmd/client

If you access it using Postman than use the provided OpenAPI file:

/api/openapi/http_api.yml

Architecture

Endpoints

Name Description
/api/player Gets the player data
/player/create Creates a player with the given credentials
/player/stats Displayes the player's gaming history
/game/state Describes the current state of the game and next possible actions
/game/action Perform the next action

Basically the game works in an endless cycle in which a player performs an action and then requests description of the new game state.

Layers

  1. Requests are received by the autogenerated HTTP server layer: internal/ports/http_api/
  2. The extracted data is sent to the application layer: internal/app/
  3. In the application layer domain objects (internal/domain/) are created from database repositories (internal/adapters/gorm/)
  4. All the game logic is managed by domain objects:
    • internal/domain/entry - performs authentication
    • internal/domain/player - stores player's balance and stats
    • internal/domain/game/session - stores all the game data
    • internal/domain/game/actions - is the state machine that describes the Blackjack gameplay
    • internal/domain/game/deck - describes the card deck

About

A little REST blackjack game

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages