Virtual cryptocurrency simulator based on Rugplay
|
|
||
|---|---|---|
| website | ||
| .dockerignore | ||
| .gitattributes | ||
| .gitignore | ||
| build.sh | ||
| docker-compose.yml | ||
| Dockerfile | ||
| drop.sql | ||
| LICENSE | ||
| README.md | ||
Rugplay
A realistic cryptocurrency trading simulation platform built with SvelteKit and Svelte 5, focusing on decentralized exchange mechanics and the inherent risks of "rug pulls."
Features
- Coin Creation: Create simulated cryptocurrencies with customizable parameters
- Liquidity Pools: AMM-based trading with realistic price mechanics and slippage
- Trading: Buy/sell coins against base currency (*BUSS) with supply/demand pricing
- Rug Pull Simulation: Experience realistic market crashes when large holders sell
- Portfolio Tracking: Monitor holdings and transaction history
- Real-time Updates: WebSocket-powered live price feeds and trade notifications
- Prediction Markets: "Hopium" betting system for market predictions
- Gambling: Coinflip and slots games
- Leaderboards: Track top performers
Tech Stack
- Frontend: SvelteKit + Svelte 5 with runes
- Backend: Node.js API routes
- WebSocket: Bun-based real-time server
- Database: PostgreSQL with Drizzle ORM
- Cache: Redis for real-time messaging
- Storage: AWS S3/Backblaze B2 compatible
- Auth: Better Auth with Google OAuth
- UI: ShadCN UI components + Tailwind CSS
Pre-Deployment Checklist
Before running on your Linux machine, ensure:
- Docker & Docker Compose installed:
docker --version && docker compose version - Ports available: 3002, 8081, 5432, 6379 are not in use
- Git access: Repository is cloned with all files
- Environment configured:
website/.envfile created fromwebsite/.env.example - Permissions set:
chmod +x build.shexecuted - Minimum system requirements: 2GB RAM, 10GB disk space
Essential Environment Variables
The following must be configured in website/.env:
# Required for database connection
DATABASE_URL=postgresql://rugplay_user:your_secure_password@postgres:5432/rugplay
POSTGRES_USER=rugplay_user
POSTGRES_PASSWORD=your_secure_password
POSTGRES_DB=rugplay
# Required for real-time features
REDIS_URL=redis://redis:6379
# Required for authentication (generate a 32+ character random string)
PRIVATE_BETTER_AUTH_SECRET=your_super_secret_auth_key_minimum_32_characters
PUBLIC_BETTER_AUTH_URL=http://localhost:3002
Quick Start
Prerequisites
- Docker & Docker Compose
- Git
Installation
-
Clone the repository:
git clone <repository-url> cd rugplay -
Configure environment:
cp website/.env.example website/.env # Edit website/.env with your actual values (see Configuration section) -
Deploy:
chmod +x build.sh ./build.sh
The application will be available at:
- Main App: http://localhost:3002
- WebSocket: http://localhost:8081
- Database: localhost:5432
- Redis: localhost:6379
Configuration
Required Environment Variables
Copy website/.env.example to website/.env and configure:
# Database Configuration
DATABASE_URL=postgresql://rugplay_user:your_secure_password@postgres:5432/rugplay
POSTGRES_USER=rugplay_user
POSTGRES_PASSWORD=your_secure_password
POSTGRES_DB=rugplay
# Redis Configuration
REDIS_URL=redis://redis:6379
# Authentication
PRIVATE_BETTER_AUTH_SECRET=your_super_secret_auth_key_minimum_32_chars
PUBLIC_BETTER_AUTH_URL=http://localhost:3002
Optional Environment Variables
# Google OAuth (for social login)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
# AWS S3/Backblaze B2 Storage (for file uploads)
PRIVATE_B2_KEY_ID=your_b2_key_id
PRIVATE_B2_APP_KEY=your_b2_app_key
PUBLIC_B2_BUCKET=your_bucket_name
PUBLIC_B2_ENDPOINT=https://s3.us-west-002.backblazeb2.com
PUBLIC_B2_REGION=us-west-002
# OpenAI (for AI features)
OPENAI_API_KEY=your_openai_api_key
# Application Settings
NODE_ENV=production
PORT=3000
Architecture
Services
- app: Main SvelteKit application (port 3002)
- websocket: Bun-based WebSocket server for real-time features (port 8081)
- postgres: PostgreSQL database with pgvector extension
- redis: Redis for caching and pub/sub messaging
Key Components
- AMM Trading: Automated Market Maker with constant product formula (x*y=k)
- Real-time Price Updates: WebSocket broadcasting for live price feeds
- Comment System: Real-time coin discussions
- Prediction Markets: AI-resolved betting on future events
- Portfolio Management: Track holdings across multiple coins
- Admin Panel: Manage promo codes and system settings
Development
Local Development
# Start only database and redis
docker compose up -d postgres redis
# Install dependencies and run main app
cd website
npm install
npm run dev
# Run websocket server (in separate terminal)
cd website/websocket
bun install
bun run src/main.ts
Database Management
# Run migrations
docker compose exec app npm run db:migrate
# Open Drizzle Studio
docker compose exec app npm run db:studio
# Push schema changes
docker compose exec app npm run db:push
Deployment Commands
Manual Deployment
# Build and start all services
docker compose build --no-cache
docker compose up -d
# Check service status
docker compose ps
# View logs
docker compose logs -f
# View specific service logs
docker compose logs -f app
docker compose logs -f websocket
Maintenance
# Restart all services
docker compose restart
# Stop services
docker compose down
# Clean rebuild (removes volumes - WARNING: deletes data)
docker compose down --volumes --remove-orphans
docker compose build --no-cache
docker compose up -d
# Update and redeploy
git pull
./build.sh
Troubleshooting
Common Issues
- Port conflicts: Ensure ports 3002, 8081, 5432, 6379 are available
- Database connection: Check DATABASE_URL format and postgres service status
- WebSocket issues: Verify REDIS_URL and redis service connectivity
- File uploads: Confirm S3/B2 credentials and bucket permissions
Health Checks
# Check all container status
docker compose ps
# Test main app
curl http://localhost:3002
# Test websocket health
curl http://localhost:8081/health
# Check database connectivity
docker compose exec postgres pg_isready -U rugplay_user
# Check redis connectivity
docker compose exec redis redis-cli ping
Log Analysis
# Follow all logs
docker compose logs -f
# Application errors
docker compose logs app | grep -i error
# WebSocket logs
docker compose logs websocket
# Database logs
docker compose logs postgres
Production Considerations
Security
- Change all default passwords and secrets
- Use strong PRIVATE_BETTER_AUTH_SECRET (minimum 32 characters)
- Configure firewall rules for exposed ports
- Use HTTPS in production (reverse proxy recommended)
- Rotate API keys and database credentials regularly
Performance
- Configure PostgreSQL for your hardware
- Set up Redis persistence if needed
- Monitor container resource usage
- Configure log rotation
- Set up database connection pooling
Monitoring
- Set up health check endpoints
- Configure log aggregation
- Monitor database performance
- Track WebSocket connection metrics
- Set up alerts for service failures
Backup Strategy
- Database backups:
pg_dumpscheduled backups - Redis persistence: Configure RDB snapshots
- File storage: S3/B2 versioning and backup
- Configuration: Version control for .env files (encrypted)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test with Docker locally
- Submit a pull request
License
[Add your license here]
Support
For issues and questions:
- Open GitHub issues for bugs
- Check logs first:
docker compose logs -f - Verify environment configuration
- Test with clean rebuild if needed