A production-grade, full-stack Bitcoin mining clicker game inspired by Universal Paperclips, built with modern web technologies.
- Next.js 15 (App Router) with TypeScript
- React 19
- TailwindCSS
- shadcn/ui components
- Framer Motion for animations
- Zustand for state management
- Recharts for data visualization
- NestJS with TypeScript
- PostgreSQL with Prisma ORM
- Redis + BullMQ for background jobs
- Socket.io for real-time updates
- NextAuth v5 for authentication
├── backend/ # NestJS backend application
├── frontend/ # Next.js frontend application
├── docker-compose.yml
└── README.md
- Node.js 20+
- PostgreSQL 14+
- Redis 7+
- Docker (optional, for containerized setup)
-
Install dependencies:
npm install
-
Set up environment variables:
Create
.envfiles in bothbackend/andfrontend/directories. See.env.examplefiles for required variables. -
Set up the database:
cd backend npx prisma migrate dev npx prisma generate npm run seed -
Start Redis:
redis-server
Or use Docker:
docker run -d -p 6379:6379 redis:7-alpine
-
Start the development servers:
npm run dev
This will start:
- Backend on
http://localhost:3001 - Frontend on
http://localhost:3000
- Backend on
Run migrations:
cd backend
npx prisma migrate devGenerate Prisma client:
npx prisma generateSeed the database with initial game data:
cd backend
npm run seedThe game engine runs server-side using BullMQ background jobs:
- Tick System: Runs every second, updating player resources (satoshis from hashrate)
- Market Simulation: Updates BTC price and network difficulty periodically
- World Events: Generates random market events that affect gameplay
- Difficulty Recalculation: Adjusts mining difficulty based on network hashrate
The tick system is the core of the game engine. It:
- Processes all active players
- Calculates satoshi generation based on hashrate
- Updates energy costs
- Persists state changes
- Emits real-time updates via WebSocket
Ticks run every second via BullMQ scheduled jobs. The system is designed to handle thousands of concurrent players efficiently.
The game includes several AI modules that can be enhanced with GPT-style AI:
-
Miner Manager AI (
backend/src/game/ai/miner-manager.ai.ts)- Currently uses greedy ROI optimization
- Replace
decideHardwarePurchase()with GPT calls
-
Energy Optimizer AI (
backend/src/game/ai/energy-optimizer.ai.ts)- Currently uses cost-benefit analysis
- Replace
optimizeEnergyUsage()with GPT calls
-
Market Trader AI (
backend/src/game/ai/market-trader.ai.ts)- Currently uses simple trend following
- Replace
decideTrade()with GPT calls
-
Empire AI (
backend/src/game/ai/empire.ai.ts)- Coordinates all AI modules
- Replace
makeStrategicDecision()with GPT calls
All AI modules are marked with // AI_INTEGRATION_POINT comments where GPT API calls should be added.
Run tests:
npm run testRun backend tests:
cd backend
npm run testRun frontend tests:
cd frontend
npm run test-
Build Docker image:
cd backend docker build -t bitcoin-mining-backend .
-
Deploy using Fly.io:
flyctl deploy
- Connect your repository to Vercel
- Configure environment variables
- Deploy automatically on push
DATABASE_URL- PostgreSQL connection stringREDIS_URL- Redis connection stringJWT_SECRET- JWT signing secretNEXT_AUTH_SECRET- NextAuth secretNEXT_AUTH_URL- Frontend URL for NextAuth
NEXT_PUBLIC_API_URL- Backend API URLNEXT_PUBLIC_WS_URL- WebSocket URLNEXTAUTH_SECRET- NextAuth secretNEXTAUTH_URL- Frontend URL
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
MIT