Skip to content

AshwinJharia/explodingKittens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Exploding Kittens - Single Player Game

A modern single-player implementation of the popular Exploding Kittens card game with user authentication and leaderboards.

๐Ÿš€ Features

  • Single Player Game - Draw cards and avoid exploding kittens
  • User Authentication - JWT-based registration and login
  • Score Tracking - Personal scores and global leaderboard
  • Flexible Storage - Redis or in-memory storage via configuration
  • Responsive Design - Works on all screen sizes (100vh/100vw)
  • Real-time Feedback - Toast notifications for all actions

๐Ÿ— Tech Stack

Backend: Go + Gin + Redis/Memory Storage
Frontend: React + Vite + Redux + Framer Motion
Database: Redis (production) / In-Memory (free tier)
Deployment: Render + Vercel

๐Ÿ—„๏ธ Storage Architecture

Configurable Storage System:

  • Interface-based design - Single codebase supports multiple storage types
  • Environment-driven - Switch storage via USE_MEMORY_STORE variable
  • Production ready - Redis for persistence, Memory for free deployment

Storage Options:

Environment Storage Type Persistence Cost
Development Redis (local) โœ… Persistent Free
Production (Free) In-Memory โŒ Resets on restart Free
Production (Paid) Redis Cloud โœ… Persistent $7+/month

๐Ÿš€ Quick Start

Prerequisites

  • Go 1.21+
  • Node.js 18+
  • Redis (for local development)

Local Development

  1. Clone and setup
git clone https://github.com/yourusername/exploding-kittens.git cd exploding-kittens
  1. Test with Redis (Recommended)
# Start Redis docker-compose up -d redis # Backend with Redis cd backend cp .env.example .env # Edit .env: USE_MEMORY_STORE=false go mod tidy # Set environment and run $env:USE_MEMORY_STORE="false"; go run main.go # Frontend cd ../frontend cp .env.example .env npm install npm run dev
  1. Test with Memory Storage
# Backend with Memory cd backend # Set environment and run $env:USE_MEMORY_STORE="true"; go run main.go # Frontend (same as above) cd ../frontend npm run dev

Visit: http://localhost:5173

๐ŸŒ Deployment

Environment Configuration

Backend Environment Variables:

# Required ENVIRONMENT=production|development PORT=8080 JWT_SECRET=your-secret-key # Storage Selection USE_MEMORY_STORE=true|false # Redis (if USE_MEMORY_STORE=false) REDIS_URL=redis://user:pass@host:port REDIS_ADDR=localhost:6379 # for development # CORS ALLOWED_ORIGINS=https://your-frontend-domain.com

Frontend Environment Variables:

VITE_ENVIRONMENT=production|development VITE_API_URL=https://your-backend-domain.com

Backend (Render)

  1. Connect GitHub repo to Render
  2. Render auto-detects render.yaml
  3. Free Tier: Uses in-memory storage (USE_MEMORY_STORE=true)
  4. Paid Tier: Add Redis service and set USE_MEMORY_STORE=false

Frontend (Vercel)

  1. Connect GitHub repo to Vercel
  2. Set root directory to frontend
  3. Environment variables set automatically via vercel.json

๐ŸŽฎ How to Play

  1. Register/Login to save your scores
  2. Start Game - Click to begin drawing cards
  3. Card Types:
    • ๐Ÿ˜ธ Cat Cards - Safe, go to inventory
    • ๐Ÿ›ก๏ธ Defuse Cards - Protect against bombs
    • โญ๏ธ Skip Cards - Safe, just removed
    • ๐Ÿ”„ Shuffle Cards - Reshuffle the deck
    • ๐Ÿ’ฅ Bomb Cards - Game over unless you have defuse
  4. Win Condition - Draw all cards without exploding
  5. Scoring - Each win increases your score

๐Ÿ“Š Project Structure

โ”œโ”€โ”€ render.yaml # Render deployment config โ”œโ”€โ”€ docker-compose.yml # Redis for local development โ”œโ”€โ”€ LICENSE # MIT License โ”œโ”€โ”€ backend/ # Go API server โ”‚ โ”œโ”€โ”€ config/ # Environment configuration โ”‚ โ”œโ”€โ”€ handlers/ # HTTP request handlers โ”‚ โ”œโ”€โ”€ middleware/ # Auth, CORS, rate limiting โ”‚ โ”œโ”€โ”€ services/ # Business logic & storage โ”‚ โ”‚ โ”œโ”€โ”€ storageService.go # Storage abstraction โ”‚ โ”‚ โ”œโ”€โ”€ redisStorage.go # Redis implementation โ”‚ โ”‚ โ”œโ”€โ”€ memoryStorage.go # Memory implementation โ”‚ โ”‚ โ””โ”€โ”€ authService.go # Authentication logic โ”‚ โ”œโ”€โ”€ models/ # Data models โ”‚ โ”œโ”€โ”€ main.go # Application entry point โ”‚ โ”œโ”€โ”€ go.mod # Go dependencies โ”‚ โ””โ”€โ”€ .env.example # Environment template โ”œโ”€โ”€ frontend/ # React application โ”‚ โ”œโ”€โ”€ src/ โ”‚ โ”‚ โ”œโ”€โ”€ components/ # React components โ”‚ โ”‚ โ”œโ”€โ”€ config/ # Environment config โ”‚ โ”‚ โ””โ”€โ”€ state/ # Redux store โ”‚ โ”œโ”€โ”€ vercel.json # Vercel deployment โ”‚ โ”œโ”€โ”€ package.json # Node dependencies โ”‚ โ””โ”€โ”€ .env.example # Environment template 

๐Ÿ—„๏ธ Database Schema

Redis Hash Tables:

  • users - Complete user profiles (ID, username, email, password hash, scores)
  • usernames - Username to user ID mapping for fast lookup
  • scores - Username to score mapping for leaderboard

Memory Storage:

  • Same structure as Redis but stored in application memory
  • Data resets when server restarts (every ~15 minutes of inactivity on free tier)

๐Ÿ”ง API Endpoints

  • POST /api/auth/register - User registration
  • POST /api/auth/login - User login
  • GET /api/auth/profile - Get user profile (requires auth)
  • POST /api/game/user - Update user score
  • GET /api/game/user/:username - Get user score
  • GET /api/game/leaderboard - Get game leaderboard

๐Ÿงช Testing Storage Types

Test Redis Storage:

cd backend docker-compose up -d redis $env:USE_MEMORY_STORE="false"; go run main.go # Check logs: "Using Redis storage"

Test Memory Storage:

cd backend $env:USE_MEMORY_STORE="true"; go run main.go # Check logs: "Using in-memory storage"

๐Ÿ”’ Security Features

  • JWT Authentication - Secure token-based auth
  • Password Hashing - bcrypt with salt rounds
  • CORS Protection - Configured for specific domains
  • Rate Limiting - Prevents API abuse
  • Environment Secrets - No hardcoded credentials

๐Ÿš€ Performance

  • Redis: Sub-millisecond data access, persistent storage
  • Memory: Nanosecond access, no network overhead
  • Frontend: Optimized bundle, lazy loading, responsive design
  • Backend: Efficient Go runtime, minimal dependencies

๐Ÿ“„ License

MIT License - see LICENSE file for details

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

About

๐ŸŽฎ Single-player Exploding Kittens card game with JWT authentication, configurable Redis/Memory storage, and responsive design. Built with Go + Gin backend and React + Redux frontend.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors