Skip to main content
Logo

Back-end for tuicub - online multiplayer board game in your terminal.

API Documentation · Events Documentation

Features

  • Fully typed code (PEP-484),
  • Testable, clean layered architecture,
  • 100% tests coverage,
  • All public interfaces documented with Google style docstrings,
  • Detailed API documentation using the OpenAPI 3.1.0 specification.

Overview

Components diagram of the system

  1. The Client connects to the Events Server to receive real-time notifications about events that occur in the user's game or gameroom,
  2. The Client queries and issues commands to the API Server via REST API,
  3. The API Server notifies the Messaging about the Client's actions, such as ending a turn,
  4. The Messaging then notifies the Events Server that an event has occured and it needs to be sent to affected Clients ,
  5. The Events Server sends the event that occurred to all affected Clients .

Installation

Using pip

Tuicubserver is available as tuicubserver on PyPI:

pip install tuicubserver

Manually

Start by cloning the repository:

git clone https://github.com/tom-bartk/tuicub-server.git
cd tuicub-server

Then, install the project's dependencies:

python -m pip install -e .

You can now launch the server using the following commands:

$ python -m src.tuicubserver

Usage: python -m src.tuicubserver [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  api     Start the API server.
  events  Start the events and messages server.

Configuration

Prerequisites

A PostgreSQL database is needed for persistence. Some of tuicub's models utilize the ARRAY data type, hence the need for the PostgreSQL backend.

config.toml

Configuration is done via a toml file with a following structure and default values:

[db]
# Connection string to the database.
url ="postgresql+psycopg2://postgres:postgres@localhost:5432/tuicub"

[logging]
# Path to a file to write logs to.
logfile = "/tmp/tuicubserver.log"

[messages]
# Host of the messages server to connect to.
host = "api.tuicub.com"

# Port of the messages server.
port = 23433

# Secret to use when sending messages.
secret = "changeme"

[events]
# Secret to use when authorizing disconnect callbacks from the events server.
secret = "changeme"

To use a custom configuration, set the TUICUBSERV_CONF environment variable to the path of your config file.

For example:

TUICUBSERV_CONF=~/mytuicub/myconfig.toml tuicubserver api

If the TUICUBSERV_CONF environment variable is not set or the file does not exist, the app will try to read a config.toml file from the current working directory.

Launching

API Server

The tuicubserver api command

Use the api command to start the API server, for example:

TUICUBSERV_CONF=./config.toml tuicubserver api --host 0.0.0.0 --port 8080

This will run the underlying Flask application on all available interfaces and port 8080 using the Werkzeug's development server.

Using a WSGI HTTP server

Since the API server is a WSGI application (PEP-3333), you can use any WSGI HTTP server of your choice. The application factory named create_app is defined in the src.tuicubserver.tuicubserver module.

To start the api server using gunicorn on all interfaces and port 8080 run:

TUICUBSERV_CONF=./config.toml gunicorn \
  --bind 0.0.0.0:8080 \
  "src.tuicubserver.tuicubserver:create_app()"

Events Server

Both the Messaging and the Events Server run in the same process. To start it, use the tuicubserver events command:

Usage: tuicubserver events [OPTIONS]

  Start the events and messages server.

Options:
  --events-port PORT    Port to bind events server to.  [default: 23432]
  --events-host HOST    Host to bind events server to.  [default: 0.0.0.0]
  --messages-port PORT  Port to bind messages server to.  [default: 23433]
  --messages-host HOST  Host to bind messages server to.  [default: 0.0.0.0]
  --api-url URL         Base URL of the API for disconnect callbacks.
                        [default: https://api.tuicub.com]
  --help                Show this message and exit.

Following example uses the default host and ports, and a custom API Server:

TUICUBSERV_CONF=./config.toml tuicubserver events --api-url http://localhost:8080

Documentation

API Docs

Visit the API Documentation for a detailed description of all API endpoints.

Screenshot

Screenshot of the API documentation

Events Docs

tuicub gameplay is driven by asynchronous events delivered over TCP sockets.

Every event is fully documented in the Events Documentation.

Screenshot

Screenshot of the events documentation

License

AGPLv3

Copyright (C) 2023 tombartk 

This program is free software: you can redistribute it and/or modify it under the terms
of the GNU Affero General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program.
If not, see https://www.gnu.org/licenses/.

Release files for tuicubserver 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tuicubserver 0.1.0
File Size Uploaded
tuicubserver-0.1.0.tar.gz 764.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tuicubserver 0.1.0
File Interpreter ABI Platform
tuicubserver-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 839.8 kB

Release files / tuicubserver-0.1.0.tar.gz

Download URL tuicubserver-0.1.0.tar.gz
Size 764.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4c14c909f62c2917c87f8abfe6af6593e8eea23b0c06502be4d1b6c162d2b170
BLAKE2b-256 checksum
How to use checksums
cb00e732502c1485231ea69c9eb559b71903bc0c1e12b665a55aea79911a6044
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.1

Release files / tuicubserver-0.1.0-py3-none-any.whl

Download URL tuicubserver-0.1.0-py3-none-any.whl
Size 75.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75818763fb458246345331974ff7bc272fd7102df61de69e13c9a83279793e3c
BLAKE2b-256 checksum
How to use checksums
3cd31075a2bd78d18f26b48bbb7a1d8a43df801ed96904558ad13296d6b71e94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.1

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page