This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Shengji is an online implementation of the Chinese trick-taking card game 升级 ("Tractor" or "Finding Friends"). It features a Rust backend with WebSocket support and a React TypeScript frontend with WebAssembly integration.
# Run frontend in development mode with hot reloading
cd frontend && yarn watch
# Run backend in development mode
cd backend && cargo run --features dynamic
# Full development setup (run in separate terminals)
cd frontend && yarn watch
cd backend && cargo run --features dynamic# Build production frontend
cd frontend && yarn build
# Build release backend
cargo build --release
# Full production build
cd frontend && yarn build && cd ../backend && cargo run# Run all Rust tests
cargo test --all
# Run specific Rust test
cargo test test_name
# Run frontend tests
cd frontend && yarn test
# Run frontend tests in watch mode
cd frontend && yarn test --watch# Lint TypeScript
cd frontend && yarn lint
# Fix TypeScript lint issues
cd frontend && yarn lint --fix
# Lint Rust
cargo clippy
# Format TypeScript
cd frontend && yarn prettier --write
# Check TypeScript formatting
cd frontend && yarn prettier --check
# Format Rust
cargo fmt --all
# Check Rust formatting
cargo fmt --all -- --check# Generate TypeScript types from Rust schemas (run from frontend directory)
cd frontend && yarn types && yarn prettier --write && yarn lint --fix- backend/: Axum web server handling WebSocket connections and game API
- core/: Game state management, message types, and serialization
- mechanics/: Core game logic including bidding, tricks, and scoring
- storage/: Storage abstraction layer supporting in-memory and Redis backends
- frontend/shengji-wasm/: WebAssembly bindings for client-side game mechanics
- frontend/src/: React components and application logic
- frontend/src/state/: WebSocket connection and state management
- frontend/src/ChatMessage.tsx: In-game chat implementation
- frontend/src/Draw.tsx: Card rendering and game board visualization
- frontend/src/Play.tsx: Main gameplay component
- frontend/json-schema-bin/: Utility for generating TypeScript types from Rust
The project maintains type safety between Rust and TypeScript by:
- Defining types in Rust using serde serialization
- Generating JSON schemas from Rust types
- Converting schemas to TypeScript definitions via json-schema-bin
- Sharing game logic through WebAssembly for client-side validation
- All game state updates flow through WebSocket connections
- Messages are typed and validated on both client and server
- State synchronization happens automatically via the WebSocketProvider
- Update logic in
mechanics/src/ - If changing message types, update
core/src/message.rs - Regenerate TypeScript types with
yarn types - Update frontend components to handle new mechanics
- Implement server-side logic in appropriate Rust module
- Add message types if needed in
core/ - Generate TypeScript types
- Implement UI in React components
- Ensure WebSocket message handling is updated
- Unit test game mechanics in Rust (
mechanics/src/) - Integration test API endpoints in
backend/ - Component testing for React UI elements
- Manual testing for WebSocket interactions and gameplay flow
Always run lints and formatting before committing:
Rust:
cargo fmt --all && cargo clippyFrontend (.tsx/.ts):
cd frontend && yarn lint --fix && yarn prettier --write