How vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc works
Project type and purpose
• This is a desktop client–server application written in Kotlin.
• It demonstrates Jetpack Compose Desktop on the client side and Ktor/Kotlinx-RPC on the server side for a multiplayer Tic-Tac-Toe game.
• There are three Gradle modules: api (shared RPC interfaces), server (game logic & RPC server), and client (Compose UI & RPC client).
File structure
Top-level modules:
• api/ – defines GameService.kt (RPC interface and data models).
• server/ – implements Ktor RPC server in Server.kt and GameServiceImpl.kt; uses kotlinx-serialization.
• client/ – Compose Desktop app (ClientApp.kt), GameScreen, ViewModel, service client, and UI widgets.
• buildSrc/ – shared Gradle config (not drawn as a runtime component).
README for additional insights
• Confirms Kotlin 11+, Gradle 7+, Jetpack Compose Desktop, Ktor server & client, Kotlinx-RPC, Coroutines & StateFlow.
• Usage: run server with :server:run and client with :client:run.
• No external database; game state lives in server memory.
Main components and their interactions
a. API module (shared RPC definitions)
b. Server
– “Ktor RPC Server” (Server.kt)
– “GameServiceImpl” implementing GameService
– Embedded HTTP engine
c. Client
– “Compose Desktop UI” (ClientApp & GameScreen)
– “GameViewModel” (StateFlow)
– “GameServiceClient” (RPC client over Ktor)
d. Data flow
1. User taps UI → Compose event → GameViewModel
2. ViewModel calls GameServiceClient.remoteCall()
3. RPC client sends HTTP request to Server
4. Server dispatches to GameServiceImpl → updates game state → returns result
5. Response flows back to GameServiceClient → ViewModel → UI updates
Architectural patterns & design principles
• Client-server architecture with clear API boundaries.
• RPC over HTTP (Ktor + Kotlinx-RPC) for type-safe communication.
• MVVM pattern on client (Compose UI + ViewModel + ServiceClient).
• Single responsibility modules: api, client, server.