Package-level declarations

Overview

Implements persistence using plain text files placed in a saves folder by default, with optional MongoDB support for scalable storage. The storage code is intentionally simple: domain objects are converted to a textual representation via Serializer implementations and written to files. This approach favors human-readable saves that are easy to debug and test.

Key Components

  • Storage<K, T, U> — Generic synchronous storage interface

    • K — Key type (typically String for game names)

    • T — Domain type (e.g., GameState)

    • U — Storage format (typically String)

    • Operations: new, load, save, delete, lastModified, loadAllIds, close

  • AsyncStorage<K, T, U> — Generic asynchronous storage interface

    • Same operations as Storage but with suspend functions

    • Suitable for coroutine-based applications

    • Prevents blocking UI during I/O operations

  • FileStorage — Synchronous file-based storage implementation

    • Stores each game in a separate .txt file

    • Uses provided Serializer for domain object conversion

    • Creates directories and files as needed

  • AsyncFileStorage — Asynchronous file-based storage implementation

    • Non-blocking version using Kotlin coroutines

    • Same functionality as FileStorage with async I/O

    • Preferred for interactive applications

  • MongoDBStorage — Synchronous MongoDB storage implementation

    • Stores games in MongoDB collections

    • Provides scalability for server deployments

  • AsyncMongoDBStorage — Asynchronous MongoDB storage implementation

    • Non-blocking MongoDB operations with coroutines

    • Suitable for high-concurrency scenarios

  • MongoDBConnection — MongoDB connection management

    • Handles connection pooling and configuration

  • Serializer<T, U> — Interface for domain-to-storage conversion

    • serialize(obj: T): U — Convert domain object to storage format

    • deserialize(obj: U): T — Convert storage format back to domain

    • Must preserve round-trip identity

Responsibilities

  • Reading and writing game snapshots to local text files or MongoDB

  • Providing Serializer interface for domain type conversion

  • Managing file/database lifecycle (creation, deletion, updates)

  • Validating file structure and reporting errors when data is malformed

  • Supporting both synchronous and asynchronous I/O patterns

Storage Backends

File Storage (default):

  • Human-readable text files

  • Easy to inspect and debug

  • Suitable for single-user applications

MongoDB Storage (optional):

  • Document-based storage

  • Scalable for multiple users

  • Requires MongoDB server

Notes

  • The concrete serializers for core types live in reversi-core under core.storage.serializers and are composed by storage implementations through the Storage contract.

  • Default folder used by the project is saves (see Environment.kt in core).

  • File format is intentionally simple and human-readable for debugging.

Types

Link copied to clipboard
data class AsyncFileStorage<T>(val folder: String, val serializer: Serializer<T, String>) : AsyncStorage<String, T, String>

AsyncStorage implementation via file + text strings.

Link copied to clipboard
data class AsyncMongoDBStorage<T>(val mongoDBConnection: MongoDBConnection, val databaseName: String, val collectionName: String, val serializer: Serializer<T, String>) : AsyncStorage<String, T, String>

AsyncStorage implementation via file + text strings.

Link copied to clipboard
interface AsyncStorage<K, T, U>

Asynchronous storage contract for persisting and retrieving domain entities.

Link copied to clipboard
data class FileStorage<T>(val folder: String, val serializer: Serializer<T, String>) : Storage<String, T, String>

Storage implementation via file + text strings.

Link copied to clipboard
data class MongoDBConnection(val user: String, val password: String, val host: String, val port: Int)

Represents connection configuration for a MongoDB server. Handles credential encoding and connection string generation.

Link copied to clipboard
data class MongoDBStorage<T>(val mongoDBConnection: MongoDBConnection, val databaseName: String, val collectionName: String, val serializer: Serializer<T, String>) : Storage<String, T, String>

Storage implementation via MongoDB + text strings.

Link copied to clipboard
interface Serializer<T, U>

Contract for converting domain entities to/from a data storage format.

Link copied to clipboard
interface Storage<K, T, U>

Synchronous storage contract for persisting and retrieving domain entities.