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 interfaceK— 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 interfaceSame operations as Storage but with suspend functions
Suitable for coroutine-based applications
Prevents blocking UI during I/O operations
FileStorage— Synchronous file-based storage implementationStores each game in a separate
.txtfileUses provided Serializer for domain object conversion
Creates directories and files as needed
AsyncFileStorage— Asynchronous file-based storage implementationNon-blocking version using Kotlin coroutines
Same functionality as FileStorage with async I/O
Preferred for interactive applications
MongoDBStorage— Synchronous MongoDB storage implementationStores games in MongoDB collections
Provides scalability for server deployments
AsyncMongoDBStorage— Asynchronous MongoDB storage implementationNon-blocking MongoDB operations with coroutines
Suitable for high-concurrency scenarios
MongoDBConnection— MongoDB connection managementHandles connection pooling and configuration
Serializer<T, U>— Interface for domain-to-storage conversionserialize(obj: T): U— Convert domain object to storage formatdeserialize(obj: U): T— Convert storage format back to domainMust preserve round-trip identity
Responsibilities
Reading and writing game snapshots to local text files or MongoDB
Providing
Serializerinterface for domain type conversionManaging 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-coreundercore.storage.serializersand are composed by storage implementations through theStoragecontract.Default folder used by the project is
saves(seeEnvironment.ktin core).File format is intentionally simple and human-readable for debugging.
Types
AsyncStorage implementation via file + text strings.
AsyncStorage implementation via file + text strings.
Asynchronous storage contract for persisting and retrieving domain entities.
Represents connection configuration for a MongoDB server. Handles credential encoding and connection string generation.
Storage implementation via MongoDB + text strings.
Contract for converting domain entities to/from a data storage format.