Skip to content

soulcrancerdev/solana-casino-game-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎰 Solana Casino Game Platform

A Modern Multi-Chain Crypto Gaming Platform with Real-Time Multiplayer Games

Node.js React MongoDB Docker License

Scissors • Crash • Mines • Turtle Race • Plinko • Dice • Slot Game

FeaturesQuick StartArchitectureDocumentationContributing


📋 Table of Contents


🎯 Overview

A comprehensive, production-ready crypto gaming platform built with modern technologies. This platform supports multiple blockchain networks, provides real-time multiplayer gaming experiences, and includes a complete admin dashboard for platform management.

Key Highlights

  • 🎮 7 Different Games - Crash, Dice, Mines, Scissors, Slot, Plinko, Turtle Race
  • 🔗 Multi-Chain Support - Ethereum, BSC, Tron, Bitcoin
  • 💰 Multiple Cryptocurrencies - BTC, ETH, BNB, TRX, USDT, and more
  • Real-Time Gaming - Socket.IO powered live gameplay
  • 🔐 Secure Authentication - JWT, 2FA, Web3 wallet integration
  • 📊 Admin Dashboard - Complete platform management
  • 🐳 Docker Ready - One-command deployment
  • 📈 Scalable Architecture - Microservices design

✨ Features

Gaming Features

  • ✅ Real-time multiplayer gameplay with Socket.IO
  • ✅ Provably fair gaming with seed-based randomness
  • ✅ Instant game results and payouts
  • ✅ Game history and statistics
  • ✅ Tournament system
  • ✅ Free spins and rewards

Wallet Features

  • ✅ Multi-currency wallet support
  • ✅ Deposit and withdrawal functionality
  • ✅ Real-time balance updates
  • ✅ Transaction history
  • ✅ Multi-chain token support
  • ✅ Automatic transaction monitoring

User Features

  • ✅ Multiple authentication methods (Email, Google OAuth, Web3 wallet)
  • ✅ User profile management
  • ✅ Game settings and preferences
  • ✅ Betting history and statistics
  • ✅ Affiliate program support
  • ✅ Real-time chat system

Admin Features

  • ✅ Comprehensive admin dashboard
  • ✅ User management and moderation
  • ✅ Game configuration
  • ✅ Transaction monitoring
  • ✅ Analytics and reporting
  • ✅ Campaign management
  • ✅ System health monitoring

Platform Features

  • Centralized Logging - Structured logging with file and console output
  • Health Checks - Built-in health endpoints for all services
  • Rate Limiting - Protection against abuse and DDoS
  • Error Handling - Comprehensive error handling middleware
  • Docker Support - Complete containerization setup
  • Environment Variables - Secure configuration management
  • API Documentation - Complete API reference

🎮 Games

Game Description Features
🎯 Crash Bet before the graph crashes! Multiplier mechanics, auto-cashout, live betting
🎲 Dice Traditional luck-based dice game Customizable odds, instant results
💣 Mines Find safe spots, avoid bombs! Progressive difficulty, strategic gameplay
✂️ Scissors Classic multiplayer hand game Real-time betting, instant payouts
🎰 Slot Spin the reels, win rewards! Multiple themes, bonus rounds
🎪 Plinko Drop the ball, win prizes! Physics-based gameplay, multiple levels
🐢 Turtle Race Race to win! Multiple participants, dynamic odds

🏗️ Architecture

System Architecture

┌─────────────────────────────────────────────────────────────┐
│                        Frontend (React)                      │
│                      Port: 8800                              │
└──────────────────────┬──────────────────────────────────────┘
                       │
┌──────────────────────┴──────────────────────────────────────┐
│                    API Gateway / Load Balancer               │
└──────────────────────┬──────────────────────────────────────┘
                       │
        ┌──────────────┼──────────────┐
        │              │              │
┌───────▼──────┐ ┌─────▼─────┐ ┌─────▼──────┐
│ Main Server  │ │ Management │ │   Admin   │
│   Port: 5000 │ │ Port: 4000 │ │ Port: 6100│
└───────┬──────┘ └─────┬─────┘ └─────┬──────┘
        │              │              │
        └──────────────┼──────────────┘
                       │
        ┌──────────────┼──────────────┐
        │              │              │
┌───────▼──────┐ ┌─────▼─────┐ ┌─────▼──────┐
│ Game Services│ │ Chat      │ │  MongoDB   │
│ Ports: 5100+ │ │ Port:4900 │ │  Database  │
└──────────────┘ └───────────┘ └────────────┘

Microservices Architecture

The platform uses a microservices architecture where each game and major functionality runs as an independent service:

  • Main Server (5000) - Core API, authentication, payments
  • Admin Service (6100) - Admin panel backend
  • Management Service (4000) - Platform management, analytics
  • Chat Service (4900) - Real-time chat system
  • Game Services (5100-5700) - Individual game servers with Socket.IO

Each service:

  • Operates independently
  • Has its own health check endpoint
  • Can be scaled horizontally
  • Connects to shared MongoDB database
  • Uses centralized logging

🛠️ Tech Stack

Backend

  • Runtime: Node.js 18+
  • Framework: Express.js
  • Database: MongoDB 7.0 with Mongoose ODM
  • Real-Time: Socket.IO 4.5+
  • Authentication: JWT (JSON Web Tokens)
  • Blockchain: Web3.js, Ethers.js, TronWeb
  • Payments: Tatum API for crypto transactions
  • Email: SendGrid for transactional emails
  • Task Scheduling: node-cron
  • Logging: Custom centralized logger
  • Rate Limiting: express-rate-limit

Frontend

  • Framework: React 18.2.0
  • State Management: Redux with Redux Thunk
  • UI Library: Material-UI (MUI) 5.0
  • Routing: React Router DOM 6.0
  • Web3 Integration: @web3-react/core, Ethers.js
  • Real-Time: Socket.IO client
  • HTTP Client: Axios
  • Build Tool: react-app-rewired with custom webpack config

Infrastructure

  • Containerization: Docker & Docker Compose
  • Web Server: Nginx (for production frontend)
  • Process Management: PM2 (optional)
  • Version Control: Git

🚀 Quick Start

Prerequisites

  • Node.js v18 or higher
  • MongoDB 7.0+ (local or MongoDB Atlas)
  • npm or yarn package manager
  • Docker and Docker Compose (for Docker deployment)
  • Git for version control

Docker Deployment (Recommended)

The easiest way to get started is using Docker Compose:

# Clone the repository
git clone <repository-url>
cd solana-casino-game-master

# Copy environment files (if needed)
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.env
cp admin/.env.example admin/.env

# Edit .env files with your configuration
# Then start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down

Services will be available at:

Manual Installation

1. Clone Repository

git clone <repository-url>
cd solana-casino-game-master

2. Backend Setup

cd backend

# Install dependencies
npm install --legacy-peer-deps

# Create .env file (copy from .env.example)
cp .env.example .env

# Edit .env with your configuration
# Then start the main server
npm run dev

# In separate terminals, start other services:
npm run admin          # Admin service (port 6100)
npm run manage         # Management service (port 4000)
npm run chatroom       # Chat service (port 4900)
npm run crash          # Crash game (port 5700)
npm run dice           # Dice game (port 5400)
npm run mines          # Mines game (port 5300)
npm run scissors       # Scissors game (port 5200)
npm run slot           # Slot game (port 5500)
npm run plinko         # Plinko game (port 5600)
npm run turtle         # Turtle race (port 5100)

3. Frontend Setup

cd frontend

# Install dependencies
npm install --legacy-peer-deps

# Create .env file (optional)
cp .env.example .env

# Start development server
npm start

Frontend will be available at http://localhost:8800

4. Admin Panel Setup

cd admin

# Install dependencies
npm install

# Create .env file (optional)
cp .env.example .env

# Start admin panel
npm start

Admin panel will be available at http://localhost:9000


⚙️ Configuration

Environment Variables

Backend (.env)

Create a .env file in the backend directory:

# Server Configuration
SERVER_PORT=5000
NODE_ENV=development

# Database
MONGODB_URI=mongodb://localhost:27017/PlayZelo
# Or for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://user:[email protected]/PlayZelo

# JWT Authentication
JWT_SECRET=your_strong_random_secret_key_min_32_chars
JWT_EXPIRE=1h

# Tatum API (Crypto Payments)
TATUM_API_KEY_TESTNET=your_testnet_api_key
TATUM_API_KEY_MAINNET=your_mainnet_api_key

# Infura (Ethereum Provider)
INFURA_API_KEY=your_infura_api_key
INFURA_URL_TESTNET=https://sepolia.infura.io/v3/YOUR_KEY
INFURA_URL_MAINNET=https://mainnet.infura.io/v3/YOUR_KEY

# Network Configuration
NETWORK=testnet
DEV_MODE=true

# Email Service (SendGrid)
SENDGRID_API_KEY=your_sendgrid_api_key

# CORS
CORS_ORIGIN=http://localhost:8800,http://localhost:9000

# Logging
LOG_LEVEL=info
LOG_FILE_PATH=./logs

Frontend (.env)

REACT_APP_API_URL=http://localhost:5000/api
REACT_APP_SOCKET_URL=http://localhost:4000
REACT_APP_CHAT_SOCKET_URL=http://localhost:4900
REACT_APP_GOOGLE_CLIENT_ID=your_google_client_id

Admin (.env)

REACT_APP_API_URL=http://localhost:6100/api
ADMIN_USERNAME=admin
ADMIN_PASSWORD=change_this_password

⚠️ Security Note: Never commit .env files. Always use .env.example as a template.


📁 Project Structure

solana-casino-game-master/
├── backend/                    # Backend services
│   ├── server.js              # Main server entry point
│   ├── config.js              # Configuration (uses env vars)
│   ├── controllers/           # Request handlers
│   ├── models/                # Database models
│   ├── routes/                # API routes
│   ├── middleware/            # Express middleware
│   ├── utils/                 # Shared utilities
│   │   ├── logger.js         # Centralized logging
│   │   ├── appFactory.js     # App factory (reduces duplication)
│   │   ├── rateLimiter.js    # Rate limiting
│   │   └── errorHandler.js   # Error handling
│   ├── helper/                # Helper functions
│   ├── crash/                 # Crash game service
│   ├── dice/                  # Dice game service
│   ├── mines/                 # Mines game service
│   ├── scissors/              # Scissors game service
│   ├── slot/                  # Slot game service
│   ├── plinko/                # Plinko game service
│   ├── turtlerace/            # Turtle race service
│   ├── userchat/              # Chat service
│   ├── management/            # Management service
│   └── admin/                 # Admin service
│
├── frontend/                   # React frontend
│   ├── src/
│   │   ├── App.js            # Main app component
│   │   ├── config/           # Configuration files
│   │   ├── redux/            # Redux store and reducers
│   │   ├── routes/           # Route definitions
│   │   ├── views/            # Page components
│   │   ├── layout/           # Layout components
│   │   └── assets/           # Static assets
│   └── public/               # Public assets
│
├── admin/                      # Admin panel
│   └── src/                   # Admin React app
│
├── docker-compose.yml         # Docker Compose configuration
├── Dockerfile                 # Backend Dockerfile
├── .dockerignore             # Docker ignore file
├── .gitignore                 # Git ignore file
├── README.md                  # This file
└── API.md                     # API documentation

📚 API Documentation

Complete API documentation is available in API.md.

Quick API Reference

Base URL: http://localhost:5000/api

Authentication:

Authorization: Bearer <jwt_token>

Health Check:

GET /health

Key Endpoints:

  • POST /api/v0/auth/register - Register user
  • POST /api/v0/auth/login - Login
  • GET /api/v0/user/profile - Get user profile
  • GET /api/v0/wallet/balance - Get wallet balance
  • POST /api/v0/wallet/deposit - Deposit funds
  • POST /api/v0/wallet/withdraw - Withdraw funds
  • POST /api/v0/games/bet - Place bet

See API.md for complete documentation.


🔒 Security

Security Features

  • JWT Authentication - Secure token-based authentication
  • Password Hashing - Bcrypt with salt rounds
  • Rate Limiting - Protection against abuse and DDoS
  • CORS Protection - Configurable Cross-Origin Resource Sharing
  • Input Validation - Server-side validation for all inputs
  • Environment Variables - Sensitive data in env vars, not code
  • Error Handling - No sensitive data in error messages
  • Session Security - Secure session configuration
  • 2FA Support - Optional two-factor authentication
  • Web3 Signature Verification - Secure wallet authentication

Security Best Practices

  1. Never commit .env files - Use .env.example as template
  2. Use strong JWT secrets - Minimum 32 characters, random
  3. Enable HTTPS in production - Use SSL/TLS certificates
  4. Regular dependency updates - Keep packages up to date
  5. Database security - Use strong MongoDB credentials
  6. API key protection - Rotate API keys regularly
  7. Rate limiting - Configure appropriate limits
  8. CORS configuration - Restrict to known origins

💻 Development

Running All Services

Use a process manager like PM2 or run each service in separate terminals:

# Using PM2 (recommended for production)
npm install -g pm2
pm2 start ecosystem.config.js

# Or manually in separate terminals
cd backend
npm run dev        # Main server
npm run admin      # Admin service
npm run manage     # Management service
# ... etc

Development Scripts

Backend:

npm run dev        # Start main server with nodemon
npm run admin      # Start admin service
npm run manage     # Start management service
npm run crash      # Start crash game
# ... etc

Frontend:

npm start          # Start dev server (port 8800)
npm run build      # Build for production

Admin:

npm start          # Start admin panel (port 9000)
npm run build      # Build for production

Code Quality

  • Use the centralized logger instead of console.log
  • Follow existing code style and conventions
  • Write clear, commented code
  • Use the error handler utilities
  • Implement proper error handling

Logging

The platform uses a centralized logging system:

const logger = require('./utils/logger');

logger.info('Information message');
logger.warn('Warning message');
logger.error('Error message', { errorData });
logger.debug('Debug message');

Logs are written to:

  • Console (with colors)
  • File: ./logs/app-YYYY-MM-DD.log

🚢 Deployment

Docker Deployment

# Build and start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

# Rebuild after changes
docker-compose up -d --build

Production Checklist

  • Set NODE_ENV=production
  • Use strong JWT secrets
  • Configure MongoDB connection string
  • Set up SSL/TLS certificates
  • Configure CORS for production domains
  • Set up monitoring and logging
  • Configure backup strategy
  • Set up rate limiting
  • Enable HTTPS
  • Configure firewall rules
  • Set up health check monitoring

Environment-Specific Configuration

Development:

  • NODE_ENV=development
  • DEV_MODE=true
  • NETWORK=testnet
  • Detailed error messages

Production:

  • NODE_ENV=production
  • DEV_MODE=false
  • NETWORK=mainnet
  • Generic error messages
  • HTTPS enabled
  • Proper CORS configuration

🐛 Troubleshooting

Common Issues

Port Already in Use:

# Find process using port
lsof -i :5000  # macOS/Linux
netstat -ano | findstr :5000  # Windows

# Kill process or change port in config

MongoDB Connection Error:

  • Verify MongoDB is running
  • Check connection string in .env
  • Verify network connectivity
  • Check MongoDB credentials

Module Not Found:

# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install --legacy-peer-deps

Socket.IO Connection Issues:

  • Verify Socket.IO server is running
  • Check URL in frontend config
  • Check CORS configuration
  • Verify firewall rules

Docker Issues:

# Rebuild containers
docker-compose down
docker-compose build --no-cache
docker-compose up -d

Environment Variables Not Loading:

  • Verify .env file exists
  • Check file location (should be in service root)
  • Restart the service after changes

🤝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Make your changes
    • Follow existing code style
    • Add comments for complex logic
    • Update documentation if needed
  4. Test your changes
    • Ensure all services start without errors
    • Test the new functionality
  5. Commit your changes
    git commit -m "Add amazing feature"
  6. Push to your branch
    git push origin feature/amazing-feature
  7. Open a Pull Request

Code Standards

  • Use centralized logger instead of console.log
  • Follow existing naming conventions
  • Write clear commit messages
  • Add error handling for new features
  • Update documentation for significant changes
  • Test thoroughly before submitting

📝 License

This project is licensed under the ISC License.

You are free to use, modify, and distribute this software. However, please use it responsibly and in compliance with applicable laws and regulations in your jurisdiction.

⚠️ Important: This is a gaming platform that involves cryptocurrency transactions. Always ensure compliance with local regulations regarding online gaming and cryptocurrency usage. Use responsibly and at your own risk.


📞 Support & Contact

For questions, support, or collaboration opportunities:

  • Issues: Open an issue on GitHub
  • Documentation: See API.md for API documentation

🙏 Acknowledgments

This platform utilizes various open-source libraries and frameworks. Special thanks to:

  • React and the React community
  • Express.js team
  • MongoDB and Mongoose
  • Socket.IO
  • Material-UI
  • All contributors and maintainers of the projects that make this platform possible

🎯 Roadmap

Planned Improvements

  • Add more game types
  • Implement WebSocket clustering for better scalability
  • Add comprehensive test suite
  • Implement CI/CD pipeline
  • Add monitoring and alerting (Prometheus, Grafana)
  • Implement caching layer (Redis)
  • Add API versioning
  • Implement GraphQL API option
  • Add mobile app support
  • Implement advanced analytics

Built with ❤️ for the crypto gaming community

⭐ Star this repo if you find it helpful!

Releases

No releases published

Packages

No packages published

Languages