# vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc architecture

> Architecture diagram of the GitHub repository vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc
- Repository: https://github.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Section
    subgraph "Client"
        direction TB
        subgraph "UI Layer"
            direction TB
            ClientApp["ClientApp.kt\n(Compose Desktop)"]:::client
            GameScreen["GameScreen.kt\n(UI Widgets)"]:::client
        end
        GameViewModel["GameViewModel.kt\n(StateFlow)"]:::client
        GameServiceClient["GameServiceClient.kt\n(Ktor RPC)"]:::client
    end

    %% API Module Section
    subgraph "API Module"
        direction TB
        APIModule["GameService.kt\n(Kotlinx-RPC)"]:::api
    end

    %% Server Section
    subgraph "Server"
        direction TB
        KtorServer["Server.kt\n(Embedded HTTP)"]:::server
        GameServiceImpl["GameServiceImpl.kt\n(Game Logic)"]:::server
    end

    %% Connections
    ClientApp -->|"launches UI"| GameScreen
    GameScreen -->|"user event"| GameViewModel
    GameViewModel -->|"invoke RPC"| GameServiceClient
    GameServiceClient -->|"RPC request"| APIModule
    APIModule -->|"dispatch"| KtorServer
    KtorServer -->|"calls RPC impl"| GameServiceImpl
    GameServiceImpl -->|"RPC response"| KtorServer
    KtorServer -->|"RPC response"| APIModule
    APIModule -->|"RPC response"| GameServiceClient
    GameServiceClient -->|"result"| GameViewModel
    GameViewModel -->|"update UI"| GameScreen

    %% Click Events
    click APIModule "https://github.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc/blob/main/api/src/main/kotlin/demo/tictactoe/api/GameService.kt"
    click KtorServer "https://github.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc/blob/main/server/src/main/kotlin/demo/tictactoe/server/Server.kt"
    click GameServiceImpl "https://github.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc/blob/main/server/src/main/kotlin/demo/tictactoe/server/GameServiceImpl.kt"
    click ClientApp "https://github.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc/blob/main/client/src/main/kotlin/demo/tictactoe/client/ClientApp.kt"
    click GameScreen "https://github.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc/blob/main/client/src/main/kotlin/demo/tictactoe/client/screen/GameScreen.kt"
    click GameViewModel "https://github.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc/blob/main/client/src/main/kotlin/demo/tictactoe/client/view/GameViewModel.kt"
    click GameServiceClient "https://github.com/vladk1m0/tictactoe_demo_kotlin_compose_desktop_ktor_rpc/blob/main/client/src/main/kotlin/demo/tictactoe/client/data/GameServiceClient.kt"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef api fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef server fill:#90EE90,stroke:#000,stroke-width:1px;
```
