# raphaeltarita/skullgame-server architecture

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

- Interactive diagram: https://gitdiagram.com/raphaeltarita/skullgame-server
- Repository: https://github.com/raphaeltarita/skullgame-server

## Overview

##### Main Components

a) External Interface Layer:
- HTTP/HTTPS Endpoints (represented as an API Gateway)
- WebSocket Connection Handler (planned future feature)
- Static Site Server (optional feature)

b) Authentication System:
- JWK Authentication Service
- Auth Store
- User Management

c) Game Core:
- Games Manager
- Game Controller
- State Management System
- Move Handlers

d) Configuration System:
- Config Provider
- Environment Config
- Features Config
- Auth Config

##### Component Relationships

**[Client] ←→ [API Gateway] → [Auth System] → [Game Core]**
- ↑               ↑               ↑
- [Configuration System]──┘

##### Specific Implementation Details

- Blue: External interfaces (HTTP endpoints, WebSocket)
- Green: Authentication components
- Red: Game core components
- Yellow: Configuration components
- Gray: External storage/files

##### Detailed Component Breakdown

a) API Gateway (Endpoints):
- Connection to auth middleware
- WebSocket upgrade path

b) Authentication System:
- JWK validation flow
- To AuthStore
- Link to user configuration

c) Game Core:
- GamesManager as central coordinator
- Individual Game instances
- State Management system
- Move Handlers hierarchy

d) Configuration:
- Config file relationships
- Environment variable integration
- Feature toggles

##### Additional Elements

Supporting components:
- Server-config directory with certificates
- Logging system (Logback)
- Thread pool for game management

##### Data Flow Indicators

- Authentication flow
- Game state updates
- Configuration loading
- Move processing pipeline

##### Specific Architectural Notes

- Separation between auth and game logic
- State management system's central role
- Modular move handler system
- Configuration injection points

##### Technical Stack Indicators

- Ktor framework
- Kotlin/JVM runtime
- JWK authentication
- Logback logging

##### Scale and Performance

Indicate:
- Thread pool limitations
- Concurrent game handling
- State management boundaries

Remember to include version or environment indicators if the system behavior varies between development and production configurations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client Application]
    end

    subgraph "External Interface Layer"
        API["API Gateway"]:::api
        WS["WebSocket Handler"]:::ws
        RH["Request Handler"]:::handler
    end

    subgraph "Authentication System"
        AS["Auth Store"]:::auth
        AU["Auth Utils"]:::auth
        JWT["JWT Implementation"]:::auth
    end

    subgraph "Game Core"
        GM["Games Manager"]:::game
        GC["Game Controller"]:::game
        SM["State Management"]:::game
        SSB["State Signal Broker"]:::game
        subgraph "Move Handlers"
            MH["Move Handler System"]:::game
        end
    end

    subgraph "Configuration System"
        CP["Config Provider"]:::config
        EC["Environment Config"]:::config
        FC["Features Config"]:::config
        AC["Auth Config"]:::config
        UC["User Config"]:::config
    end

    subgraph "Supporting Components"
        LC["Logging Config"]:::support
        AEP["Application Entry"]:::support
        SC["Server Constants"]:::support
    end

    %% Relationships
    CL --> API
    CL --> WS
    API --> RH
    RH --> AS
    AS --> GM
    WS --> GM
    GM --> GC
    GC --> SM
    SM --> SSB
    GC --> MH
    CP --> API
    CP --> AS
    CP --> GM
    EC --> CP
    FC --> CP
    AC --> CP
    UC --> CP
    AS --> AU
    AS --> JWT

    %% Click Events
    click API "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/endpoints/routing.kt"
    click WS "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/endpoints/websockets.kt"
    click RH "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/endpoints/handling/requests.kt"
    click AS "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/auth/AuthStore.kt"
    click AU "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/auth/authutils.kt"
    click JWT "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/endpoints/jwt.kt"
    click GM "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/core/game/GamesManager.kt"
    click GC "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/core/game/GameController.kt"
    click SM "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/core/state/GlobalState.kt"
    click MH "https://github.com/RaphaelTarita/skullgame-server/tree/main/src/main/kotlin/com/rtarita/skull/server/core/game/handler"
    click SSB "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/core/state/StateSignalBroker.kt"
    click CP "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/config/ConfigProvider.kt"
    click EC "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/config/EnvironmentConfig.kt"
    click FC "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/config/FeaturesConfig.kt"
    click AC "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/config/AuthConfig.kt"
    click UC "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/config/User.kt"
    click LC "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/resources/logback.xml"
    click AEP "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/Application.kt"
    click SC "https://github.com/RaphaelTarita/skullgame-server/blob/main/src/main/kotlin/com/rtarita/skull/server/ServerConstants.kt"

    %% Styling
    classDef default fill:#fff,stroke:#333,stroke-width:2px
    classDef api fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef ws fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef handler fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef auth fill:#90EE90,stroke:#333,stroke-width:2px
    classDef game fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef config fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef support fill:#D3D3D3,stroke:#333,stroke-width:2px
```
