Go Game with AT Protocol Integration#
A SvelteKit application that implements the game of Go using the Wgo library, with AT Protocol OAuth authentication and custom lexicons to record game state and moves on the decentralized network.
🚀 Now deployed on Cloudflare Pages! This application runs on Cloudflare's global edge network with D1 database and KV storage.
Features#
- AT Protocol OAuth: Login with your Bluesky account
- Custom Lexicons: Game state stored as AT Protocol records
boo.sky.go.game- Game recordsboo.sky.go.move- Move recordsboo.sky.go.pass- Pass records
- Wgo.js Integration: Professional Go board rendering and game logic
- Real-time Updates: Firehose subscription for network-wide game updates
- Multiple Board Sizes: Support for 9x9, 13x13, and 19x19 boards
- Edge Deployment: Runs on Cloudflare's global edge network
- D1 Database: Cloudflare's serverless SQL database for game storage
- KV Storage: Session and state management with Cloudflare KV
Implementation Status#
This is a demonstration project showing the architecture for integrating a Go game with AT Protocol. The core implementation includes:
✅ Completed:
- SvelteKit application structure
- Custom AT Protocol lexicon definitions for games, moves, and passes
- SQLite database schema with Kysely
- Wgo.js board component integration
- Game creation and joining UI
- Move recording logic
- Pass functionality
- Game state management
⚠️ Partially Implemented:
- OAuth authentication (structure in place, needs full AT Protocol OAuth client setup)
- AT Protocol record creation (URIs generated, but not actually written to network)
- Firehose subscription (placeholder implementation provided)
📝 Notes:
- The application demonstrates the data structures and flow for AT Protocol integration
- OAuth and record creation are simplified for demo purposes
- To fully implement, you'll need to properly configure NodeOAuthClient and AtpAgent
- The Node version (v17.9.0) is below the recommended 18+, which may cause some warnings
Deployment#
Cloudflare Pages (Recommended)#
This application is optimized for deployment on Cloudflare Pages. See CLOUDFLARE_DEPLOYMENT.md for complete deployment instructions.
Quick steps:
- Create D1 database and KV namespaces
- Set environment secrets
- Deploy via GitHub integration or Wrangler CLI
Migration Notes#
This application has been migrated from Node.js to Cloudflare Workers. See MIGRATION_SUMMARY.md for details on the changes made.
Getting Started#
Prerequisites#
- Node.js 20+ (required for Cloudflare tooling)
- npm or pnpm
- Cloudflare account (for deployment)
Installation#
-
Clone the repository
-
Install dependencies:
npm install -
Copy the environment file:
cp .env.example .env -
Edit
.envand update theSESSION_SECRETto a random string:DATABASE_PATH=./data/app.db SESSION_SECRET=your-random-secret-here PUBLIC_BASE_URL=http://localhost:5173
Running the Development Server#
npm run dev
The application will be available at http://localhost:5173
Building for Production#
npm run build
npm run preview
How to Play#
- Login: Click login and enter your Bluesky handle (e.g.,
yourname.bsky.social) - Create Game: Choose a board size and create a new game
- Wait or Join: Either wait for another player to join your game, or join an existing waiting game
- Play: Take turns placing stones on the board
- Pass: Click the Pass button if you want to pass your turn
- Game End: The game ends when both players pass consecutively
Project Structure#
/src
/routes
+page.svelte # Home page with game list
+page.server.ts # Server-side data loading
+layout.svelte # Layout wrapper
/auth
/login/+server.ts # OAuth login initiation
/callback/+server.ts # OAuth callback handler
/logout/+server.ts # Logout handler
/game/[id]
+page.svelte # Game board view
+page.server.ts # Game data loading
/api
/games
+server.ts # Create game API
/[id]
/join/+server.ts # Join game API
/move/+server.ts # Record move API
/pass/+server.ts # Record pass API
/lib
/server
auth.ts # OAuth client setup
db.ts # Database configuration
firehose.ts # Firehose subscription
/components
Board.svelte # Wgo board component
hooks.server.ts # Server hooks
/lexicons # Custom lexicon definitions
boo.sky.go.game.json
boo.sky.go.move.json
boo.sky.go.pass.json
/static
oauth-client-metadata.json # OAuth client metadata
Architecture#
Technology Stack#
- Frontend: SvelteKit 5 with TypeScript
- Go Engine: Wgo.js (v3.0.0-alpha.10)
- Authentication: AT Protocol OAuth (
@atcute/oauth-node-client) - Data Storage: AT Protocol records with custom lexicons
- Database: Cloudflare D1 (serverless SQLite) with Kysely query builder
- Session Storage: Cloudflare KV
- Image Generation: @cf-wasm/resvg (WebAssembly-based)
- Deployment: Cloudflare Pages with Workers runtime
- Real-time: AT Protocol Firehose integration
Custom Lexicons#
The application defines three custom AT Protocol lexicons:
- boo.sky.go.game: Represents a game between two players
- boo.sky.go.move: Represents a stone placement move
- boo.sky.go.pass: Represents a pass action
All game data is stored as AT Protocol records, making it decentralized and portable.
Known Limitations#
- The firehose implementation is a placeholder - full implementation would require WebSocket connection to AT Protocol relay
- No automatic scoring - game ends on two consecutive passes but doesn't calculate winner
- OAuth session management is simplified for development (should use proper encryption in production)
- No time controls or undo functionality
- Real-time updates require page refresh
Future Enhancements#
- Automatic territory scoring
- Game chat/comments using AT Protocol
- Game history and replay functionality
- Time controls (byo-yomi, Fischer)
- Player ranking system
- SGF (Smart Game Format) export
- Game analysis tools
- Spectator mode
Contributing#
This is a demonstration project showing AT Protocol integration with a game application. Feel free to fork and extend!
License#
MIT