Back to .md Directory

Claude Code Guide for Oxeye

Documents a Rust Discord bot and Minecraft mod project with build commands, architecture, API endpoints, and database schema.

May 2, 2026
0 downloads
0 views
ai rag claude
View source

What this file does

Documents a Rust Discord bot and Minecraft mod project with build commands, architecture, API endpoints, and database schema.

When to use it

  • Onboarding new developers to the Oxeye codebase
  • Setting up a development environment for the project
  • Understanding the layered architecture and error handling patterns
  • Adding new HTTP endpoints or Discord commands

Assumes this stack

RustAxumTokioPoiseSQLiteMinecraft Fabric

Claude Code Guide for Oxeye

Project Overview

Oxeye is a Discord bot + Minecraft Mod + backend service that tracks who's online on Minecraft servers and displays that information in Discord. It consists of:

  • Rust Backend: HTTP API server + Discord bot (single binary)
  • Minecraft Fabric Mod: Java mod that reports player join/leave events
  • SQLite Database: Persistent storage for server links and player status

Enabled Tools

  • ast-grep: Available for structural code search and refactoring using AST patterns. Use for finding/modifying Rust and Java code structures.

Quick Reference

Build Commands

# Build the project
cargo build --release

# Run tests
cargo test

# Run with Discord token
DISCORD_TOKEN=<token> cargo run

# Check without building
cargo check

Project Structure

oxeye/
├── oxeye-backend/        # Main Rust HTTP server + Discord bot
│   ├── src/
│   │   ├── main.rs       # Entry point, runtime setup
│   │   ├── lib.rs        # Router creation, middleware setup
│   │   ├── config.rs     # Environment configuration
│   │   ├── routes.rs     # HTTP endpoint handlers
│   │   ├── error.rs      # Error types and HTTP mapping
│   │   ├── helpers.rs    # Utility functions
│   │   ├── validation.rs # Input validation
│   │   └── discord_commands.rs  # Discord slash commands
│   └── tests/            # Integration tests
├── oxeye-db/             # Database abstraction crate
│   └── src/
│       ├── lib.rs        # Database operations (~60 methods)
│       ├── models.rs     # Data types
│       └── error.rs      # Database errors
├── oxeye-mod/            # Minecraft Fabric Mod (Java/Gradle)
├── docs/                 # Architecture documentation
├── Cargo.toml            # Workspace root
└── DESIGN.md             # API specification

Technology Stack

ComponentTechnologyNotes
Web FrameworkAxum 0.8HTTP server with middleware
Async RuntimeTokioFull features enabled
Discord BotPoise 0.6Command framework on Serenity
Databasetokio-rusqliteAsync SQLite with WAL mode
SerializationSerde + serde_jsonJSON encoding/decoding
Error HandlingthiserrorErgonomic error types
LoggingtracingStructured logging
Rate Limitingtower-governorIP-based rate limiting

Rust Edition: 2024

Architecture Patterns

Layered Design

HTTP Request → Validation (validation.rs) → Routes (routes.rs) → Database (oxeye-db)
Discord Command → discord_commands.rs → Database (oxeye-db)

Error Handling

  • All errors flow through AppError enum in error.rs
  • Database errors wrapped and mapped to HTTP status codes
  • Internal errors logged server-side, user-friendly messages returned
  • Never expose SQL, stack traces, or library names to clients

Authentication

  • API keys generated as oxeye-sk-{32 alphanumeric}
  • Keys stored as SHA-256 hashes (never plaintext)
  • Bearer token authentication on protected endpoints
  • Connection codes format: oxeye-{6 alphanumeric} (10-minute TTL)

Concurrency

  • SQLite with WAL mode for concurrent reads
  • Tokio async/await throughout
  • Rate limiting prevents abuse

API Endpoints

MethodPathAuthPurpose
POST/connectNoneRedeem connection code
POST/joinBearerReport player joining
POST/leaveBearerReport player leaving
POST/syncBearerReplace entire player list
GET/statusBearerCheck server connection
POST/disconnectBearerUnlink server

Discord Commands

  • /oxeye connect <name> - Admin-only, generates linking code
  • /oxeye list - Shows all servers in guild
  • /oxeye status <name> - Shows online players with join times

Database Schema

Three main tables:

  • pending_links - Connection codes with TTL
  • servers - Linked Minecraft servers (api_key_hash, name, guild_id)
  • online_players - Players currently online with join timestamps

Testing

# Run all tests
cargo test

# Run specific test
cargo test test_name

# Run with output
cargo test -- --nocapture

Tests use in-memory SQLite for speed. Coverage includes:

  • All HTTP endpoints (success and error cases)
  • Database operations
  • Input validation
  • Rate limiting behavior
  • Error response formats

Environment Variables

VariableDefaultRequiredDescription
DISCORD_TOKEN-YesDiscord bot token
PORT3000NoHTTP server port
DATABASE_PATHoxeye.dbNoSQLite database file
REQUEST_BODY_LIMIT1048576NoMax request size (bytes)
REQUEST_TIMEOUT_SECS30NoRequest timeout

Rate limit variables also available (see config.rs).

Code Style

  • Use #[debug_handler] on Axum handlers for better error messages
  • Validation happens before any database operations
  • Helper functions in helpers.rs for common operations
  • Comprehensive error messages that help users fix issues
  • Tests alongside implementation in oxeye-db, separate test files in oxeye-backend

Common Tasks

Adding a new HTTP endpoint

  1. Add route in lib.rs under appropriate rate-limit tier
  2. Add handler in routes.rs
  3. Add validation if needed in validation.rs
  4. Add database methods if needed in oxeye-db/src/lib.rs
  5. Add integration tests in tests/integration_tests.rs

Adding a new Discord command

  1. Add command function in discord_commands.rs
  2. Register in the commands vector in main.rs
  3. Database access via ctx.data().db

Adding a new database operation

  1. Add method in oxeye-db/src/lib.rs
  2. Add types if needed in models.rs
  3. Add tests in the #[cfg(test)] module

Key Files to Understand

  • oxeye-backend/src/lib.rs:1-119 - Router setup, middleware, rate limiting tiers
  • oxeye-backend/src/routes.rs:1-143 - All HTTP handlers
  • oxeye-db/src/lib.rs:1-400 - Database schema and core operations
  • DESIGN.md - Complete API specification
  • docs/architecture-decisions.md - Performance decisions and caching strategy

Docker

Multi-architecture builds available:

  • Dockerfile.amd64 - x86-64
  • Dockerfile.arm64 - ARM64 (Raspberry Pi, Apple Silicon)

Final images are minimal scratch-based containers.

What's inside

15 sections covering overview, tools, build commands, project structure, stack, architecture, API, Discord commands, database, testing, env vars, code style, tasks, key files, and Docker.

Change this for your project

  • Replace adhi-thirumala/oxeye with your own repository name
  • Replace DISCORD_TOKEN with your own environment variable name if different
  • Replace oxeye-sk-{32 alphanumeric} with your own API key format
  • Replace oxeye-{6 alphanumeric} with your own connection code format

Where it goes

Save as CLAUDE.md in your repository root. Claude Code reads it automatically at the start of every session.

Worth borrowing

  • Layered architecture separating validation, routes, and database operations
  • Centralized error handling via an AppError enum that maps to HTTP status codes
  • In-memory SQLite for fast integration tests

Related Documents