Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,8 @@ DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc


# nodejs
node_modules

138 changes: 138 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Deckster is a multi-platform card game framework built with .NET 9. It provides a WebSocket-based server architecture for hosting multiplayer card games with clients available in C# (.NET), Swift (iOS), and Kotlin (Android).

## Commands

### Building
```bash
# Build the entire solution
build.bat
# Or manually:
cd src/Deckster.Server
dotnet restore
dotnet build
```

### Running the Server
```bash
# Run the server
server.bat
# Or manually:
cd src/Deckster.Server
dotnet run
```

### Running Tests
```bash
# Run all tests
dotnet test src/Deckster.UnitTests/Deckster.UnitTests.csproj

# Run tests with detailed output
dotnet test src/Deckster.UnitTests/Deckster.UnitTests.csproj --logger "console;verbosity=detailed"
```

### Running Sample Clients
Sample clients for different games can be run using the provided shell scripts or directly:
```bash
# Using convenience scripts (bash):
./crazyeights.sh
./chatroom.sh
./idiot.sh
./bullshit.sh

# Or manually:
cd src/Deckster.[GameName].SampleClient
dotnet run
```

### Code Generation
The project uses OpenAPI/Swagger for code generation:
```bash
# Server generates OpenAPI spec at runtime
# Check decksterapi.yml and generated/ directory for OpenAPI outputs

# Run code generator
cd src/Deckster.CodeGenerator
dotnet run
```

## Architecture

### Multi-Layered Solution Structure

The solution is organized into logical folders:
- **10. Server**: `Deckster.Server` - ASP.NET Core WebSocket server
- **15. Sample clients**: Multiple `Deckster.[GameName].SampleClient` projects demonstrating client implementation
- **20. Libs**: Core libraries (`Deckster.Core`, `Deckster.Client`, `Deckster.Games`)
- **30. Code generation**: `Deckster.CodeGenerator` and generated client code
- **90. Tests**: `Deckster.UnitTests` with NUnit

### Core Components

**Deckster.Core**: Shared data models, protocol definitions, serialization, and authentication models. Used by both server and clients.

**Deckster.Server**: ASP.NET Core server hosting multiple card games. Contains:
- WebSocket communication layer (`Communication/IServerChannel`, `Communication/WebSocketServerChannel`)
- Game implementations in `Games/` directory
- Controllers for REST API endpoints
- Authentication middleware
- Swagger/OpenAPI integration

**Deckster.Client**: .NET client library for connecting to Deckster servers. Provides:
- `DecksterClient` - Main client class with authentication
- `GameClient<TState>` - Base class for game-specific clients
- Generated game clients (`.g.cs` files) in `Games/` subdirectories

**Deckster.Games**: Game logic and state management, shared between server and clients. Each game (CrazyEights, Uno, ChatRoom, Gabong, Idiot, Yaniv, TexasHoldEm, Bullshit) has its own subdirectory.

### Communication Protocol

The server uses a dual WebSocket architecture:
1. **Action Socket**: Request/response pattern for client actions
2. **Notification Socket**: Asynchronous push notifications from server

Connection handshake:
1. Client initiates join (establishes action socket)
2. Client sends finish join (establishes notification socket)

Disconnect procedures differ based on who initiates:
- **Client disconnect**: Client closes action socket with "Client disconnected" message
- **Server disconnect**: Server closes notification socket with "Server disconnected" message

See README.md diagrams for detailed connection/disconnection flows.

### Multi-Platform Support

- **.NET**: `Deckster.Client` NuGet package
- **iOS**: Swift package defined in `Package.swift`, source in `ios/Sources/`
- **Android**: Kotlin library in `android/decksterlib/`, built with Gradle

Code generation from OpenAPI spec creates platform-specific clients.

### Code Generation

- `Deckster.CodeGenerator` generates client code from the server's API
- Generated code appears in `generated/` directory
- The `Deckster.Generated.Client` project contains generated .NET clients
- Mobile platforms have their own generation scripts (`android/generate-code-from-openapi.sh`)

## Dependencies

- **.NET 9.0**
- **NUnit** (testing)
- **Marten** (document database for server)
- **Swashbuckle.AspNetCore** (OpenAPI/Swagger)
- **System.Text.Json** (serialization)

## Project References

The server references all sample clients for demonstration purposes. When adding new games:
1. Create game logic in `Deckster.Games`
2. Add server-side implementation in `Deckster.Server/Games`
3. Generate client code using `Deckster.CodeGenerator`
4. Create sample client project following naming pattern `Deckster.[GameName].SampleClient`
Loading