A modern, full-stack game recharge platform built with TypeScript, featuring multi-merchant support, internationalization, and integrated payment processing.
Game Recharge Platform is a comprehensive, production-ready solution for managing in-game currency purchases and virtual goods. The platform provides a seamless experience for end users, merchants, and administrators with robust support for multiple payment providers, multi-language interfaces, and role-based access control.
Built with modern web technologies and best practices, this platform demonstrates enterprise-grade architecture with clean code separation, type safety, and scalable design patterns.
- Overview
- Features
- Architecture
- Tech Stack
- Project Structure
- Quick Start
- Getting Started
- Environment Configuration
- API Documentation
- Database Schema
- Security Features
- Development
- Internationalization
- Deployment
- FAQ
- Roadmap
- License
- Contributing
- Game Management: Browse and search games with detailed information
- SKU Management: Product catalog with pricing, discounts, and bonuses
- Order Processing: Complete order lifecycle management (Pending β Paid/Failed/Canceled)
- Multi-Merchant Support: Multiple merchants can manage their games independently
- Merchant Application System: Users can apply to become merchants with admin approval workflow
- Stripe: Full integration with Stripe payment processing
- PayPal: Complete PayPal checkout flow support
- Webhook Support: Secure payment status updates via webhooks
- Internationalization: Support for Chinese (δΈζ), Japanese (ζ₯ζ¬θͺ), and English
- Responsive Design: Modern UI built with Tailwind CSS
- Authentication: Auth0 SSO integration with OAuth 2.0 / OpenID Connect
- Role-Based Access: USER, MERCHANT, and ADMIN roles with appropriate permissions
- Demo Mode: Development-friendly demo authentication system
- Admin Dashboard: Comprehensive statistics, merchant management, and order oversight
- Merchant Portal: Game and SKU management for merchants
- Order Analytics: Revenue trends, order statistics, and performance metrics
The platform follows a frontend-backend separation architecture:
βββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React + Vite) β
β React 18 + TypeScript + Tailwind CSS β
ββββββββββββββββββββ¬βββββββββββββββββββββββ
β HTTP/REST API
β (CORS Enabled)
ββββββββββββββββββββΌβββββββββββββββββββββββ
β Backend (Node.js + Express) β
β Express + TypeScript + Prisma ORM β
ββββββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β β β
βββββΌβββββββ βββββΌβββββββ βββββΌβββββββ
βPostgreSQLβ β Redis β β Auth0 β
β β β (Cache) β β SSO β
ββββββββββββ ββββββββββββ ββββββββββββ
- React 18.2.0 - UI library
- TypeScript 5.2.2 - Type safety
- Vite 5.1.0 - Build tool and dev server
- Tailwind CSS 3.4.1 - Utility-first CSS framework
- React Router DOM 6.22.0 - Client-side routing
- Zustand 4.5.0 - State management
- i18next 23.8.0 - Internationalization
- @auth0/auth0-react 2.11.0 - Authentication
- @stripe/react-stripe-js - Stripe integration
- @paypal/react-paypal-js - PayPal integration
- Node.js - Runtime environment
- Express 4.18.2 - Web framework
- TypeScript 5.2.2 - Type safety
- Prisma 5.8.1 - Modern ORM
- PostgreSQL 16 - Primary database
- Redis 7 - Caching layer
- express-oauth2-jwt-bearer 1.6.0 - Auth0 JWT validation
- Stripe 14.15.0 - Payment processing
- @paypal/checkout-server-sdk - PayPal server SDK
- Pino 9.0.0 - High-performance logging
- Helmet 7.1.0 - Security headers
- Zod 3.22.4 - Runtime validation
game-recharge-platform/
βββ frontend/ # Frontend application
β βββ src/
β β βββ components/ # React components
β β βββ pages/ # Page components
β β βββ services/ # API services
β β βββ store/ # Zustand state management
β β βββ types/ # TypeScript types
β β βββ auth/ # Authentication logic
β β βββ i18n/ # Internationalization
β β β βββ locales/ # Translation files (zh, ja, en)
β β βββ App.tsx # Root component
β β βββ main.tsx # Entry point
β βββ package.json
β βββ vite.config.ts
β βββ tailwind.config.js
β
βββ backend/ # Backend application
β βββ src/
β β βββ routes/ # API routes
β β β βββ health.ts
β β β βββ games.ts
β β β βββ skus.ts
β β β βββ orders.ts
β β β βββ merchant.ts
β β β βββ merchantApply.ts
β β β βββ adminMerchants.ts
β β β βββ paymentsStripe.ts
β β β βββ paymentsPaypal.ts
β β βββ middleware/ # Express middleware
β β β βββ auth.ts # Authentication
β β β βββ demoAuth.ts # Demo mode auth
β β β βββ error.ts # Error handling
β β βββ payments/ # Payment services
β β β βββ stripe.ts
β β β βββ paypal.ts
β β βββ app.ts # Express app config
β β βββ index.ts # Entry point
β β βββ config.ts # Configuration
β β βββ db.ts # Database connection
β β βββ logger.ts # Logging setup
β βββ prisma/
β β βββ schema.prisma # Database schema
β β βββ migrations/ # Database migrations
β β βββ seed.ts # Seed data
β βββ package.json
β
βββ database/ # Database configuration
β βββ docker-compose.yml # Docker Compose setup
β
βββ docs/ # Documentation
βββ TECHNICAL_ARCHITECTURE.md
βββ AUTH0_SSO_SETUP.md
For a quick overview, here's the minimal setup to get the platform running:
# 1. Start databases
cd database && docker-compose up -d
# 2. Setup backend
cd ../backend
npm install
cp env.example .env # Configure your .env file
npm run prisma:generate
npm run prisma:migrate
npm run dev
# 3. Setup frontend (in a new terminal)
cd ../frontend
npm install
cp env.example .env # Configure your .env file
npm run devVisit http://localhost:5173 to see the application.
Note: Make sure to configure Auth0, Stripe, and PayPal credentials in the
.envfiles before running.
- Node.js >= 18.x
- npm or yarn
- Docker and Docker Compose (for database)
- Auth0 Account (for authentication)
- Stripe Account (for payments)
- PayPal Developer Account (for payments)
-
Clone the repository
git clone <repository-url> cd gamepay/game-recharge-platform
Note: Replace
<repository-url>with your actual repository URL. -
Set up the database
cd database docker-compose up -dThis will start PostgreSQL and Redis containers.
-
Set up the backend
cd backend npm install # Copy environment variables cp env.example .env # Edit .env with your configuration # Generate Prisma Client npm run prisma:generate # Run database migrations npm run prisma:migrate # (Optional) Seed the database npm run prisma:seed
-
Set up the frontend
cd frontend npm install # Copy environment variables template cp env.example .env # Edit .env file with your configuration: # VITE_API_BASE_URL=http://localhost:8080 # VITE_AUTH0_DOMAIN=your-tenant.us.auth0.com # VITE_AUTH0_CLIENT_ID=your-client-id # VITE_AUTH0_AUDIENCE=https://api.waffogamepay.local
-
Start the backend (from
backend/directory)npm run dev
Backend will run on
http://localhost:8080 -
Start the frontend (from
frontend/directory)npm run dev
Frontend will run on
http://localhost:5173 -
Access the application
- Frontend: http://localhost:5173
- Backend API: http://localhost:8080
- Health Check: http://localhost:8080/health
Create a .env file in the backend/ directory:
PORT=8080
NODE_ENV=development
# CORS
WEB_ORIGIN=http://localhost:5173
# Auth0
AUTH0_DOMAIN=your-tenant.us.auth0.com
AUTH0_AUDIENCE=https://api.waffogamepay.local
AUTH0_NAMESPACE=https://waffogamepay.example
# Database
DATABASE_URL=postgresql://gamepay:gamepay@localhost:5432/gamepay?schema=public
# Payments
STRIPE_SECRET_KEY=sk_test_xxx
STRIPE_WEBHOOK_SECRET=whsec_xxx
PAYPAL_CLIENT_ID=your_paypal_client_id
PAYPAL_CLIENT_SECRET=your_paypal_client_secret
PAYPAL_ENV=sandbox # or 'live'Create a .env file in the frontend/ directory:
VITE_API_BASE_URL=http://localhost:8080
VITE_AUTH0_DOMAIN=your-tenant.us.auth0.com
VITE_AUTH0_CLIENT_ID=your-client-id
VITE_AUTH0_AUDIENCE=https://api.waffogamepay.localGET /health- Service health status
GET /api/games- List all gamesGET /api/games/:id- Get game details
GET /api/skus- List SKUs (with optional filters)GET /api/skus/:id- Get SKU details
GET /api/orders- List orders (user-specific or admin view)POST /api/orders- Create a new orderGET /api/orders/:id- Get order details
GET /api/merchant- Get merchant informationPOST /api/merchant/apply- Submit merchant application
- Stripe:
POST /api/payments/stripe/create-intent- Create payment intentPOST /api/webhooks/stripe- Stripe webhook handler
- PayPal:
POST /api/payments/paypal/create-order- Create PayPal orderPOST /api/payments/paypal/capture- Capture payment
GET /api/admin/merchants- List all merchants (admin only)GET /api/users- List all users (admin only)
The API supports two authentication modes:
-
Production Mode: Auth0 JWT Bearer Token
Authorization: Bearer <jwt-token> -
Demo Mode (for development):
X-Demo-Role: visitor|user|merchant|admin X-Demo-Merchant-Id: <merchant-id> (optional)
- User: User accounts with roles (USER, MERCHANT, ADMIN)
- Merchant: Merchant entities with status (ACTIVE, SUSPENDED)
- Game: Games with multi-language support (nameZh, nameJa, nameEn)
- SKU: Product units with pricing, discounts, and bonuses
- Order: Order records with status tracking (PENDING, PAID, FAILED, CANCELED)
- MerchantApplication: Merchant application workflow
- Many-to-Many: Merchant β User, Merchant β Game
- One-to-Many: User β Orders, Merchant β Games β SKUs
The platform implements multiple layers of security:
- HTTP Security Headers (Helmet) - XSS protection, Content Security Policy (CSP), HSTS
- CORS Configuration - Restricted origins with credential support
- JWT Authentication - Secure token-based authentication via Auth0
- Role-Based Access Control (RBAC) - Fine-grained permissions for USER, MERCHANT, and ADMIN roles
- Webhook Signature Verification - Secure payment webhook handling (Stripe webhook secret validation)
- Input Validation - Zod schema validation for all API endpoints
- SQL Injection Prevention - Prisma ORM with parameterized queries
- Environment Variable Protection - Sensitive data stored in environment variables, never in code
- HTTPS Enforcement - Production-ready SSL/TLS configuration
- Never commit
.envfiles to version control - Use strong, unique secrets for production
- Regularly update dependencies for security patches
- Implement rate limiting for API endpoints
- Monitor and log security events
cd frontend
npm run dev # Start development server (http://localhost:5173)
npm run build # Build for production
npm run preview # Preview production build locally
npm run lint # Run ESLint for code quality checkscd backend
npm run dev # Start development server with hot reload (http://localhost:8080)
npm run build # Compile TypeScript to JavaScript
npm start # Run production server (requires build first)
npm run prisma:generate # Generate Prisma Client from schema
npm run prisma:migrate # Run database migrations
npm run prisma:studio # Open Prisma Studio (database GUI at http://localhost:5555)- Hot Reload: Both frontend and backend support hot reload during development
- Database GUI: Use
npm run prisma:studioto visually inspect and edit database records - Type Safety: TypeScript ensures type safety across the entire stack
- Environment Variables: Always use
.envfiles (never commit them to version control)
# Start database services
cd database
docker-compose up -d
# Stop database services
docker-compose down
# View database logs
docker-compose logs -f postgresThe platform supports three languages with full i18n implementation:
- Chinese (δΈζ) -
zh - Japanese (ζ₯ζ¬θͺ) -
ja - English -
en(default)
Translation files are located in frontend/src/i18n/locales/. The language is automatically detected from the user's browser settings, and users can manually switch languages via the UI.
- Create a new translation file in
frontend/src/i18n/locales/{lang}.json - Add the language code to the i18n configuration
- Update the language switcher component
-
Build the frontend
cd frontend npm run buildOutput will be in
frontend/dist/ -
Build the backend
cd backend npm run buildOutput will be in
backend/dist/ -
Run migrations
cd backend npm run prisma:migrate -
Start the backend
npm start
Before deploying to production, ensure:
- β
Set
NODE_ENV=production - β Use production database credentials with connection pooling
- β Configure production Auth0 settings and API audiences
- β Set up production payment provider keys (Stripe Live keys, PayPal Live credentials)
- β Configure proper CORS origins (remove localhost origins)
- β Set up webhook endpoints for payment providers (Stripe, PayPal)
- β Enable HTTPS/SSL certificates
- β Set up proper logging and monitoring
- β Configure backup strategies for database
- β Review and update security headers
- β Set up rate limiting for API endpoints
- β Configure proper error tracking (e.g., Sentry)
You can containerize the application using Docker:
# Build backend image
cd backend
docker build -t game-recharge-backend .
# Build frontend image
cd frontend
docker build -t game-recharge-frontend .
# Run with docker-compose
docker-compose up -dThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Follow TypeScript best practices and maintain type safety
- Write clear, self-documenting code with meaningful variable names
- Add appropriate error handling and validation
- Update documentation for any API or feature changes
- Ensure all tests pass before submitting PRs
- Use ESLint for code linting
- Follow the existing code structure and patterns
- Use meaningful commit messages
For support, please open an issue in the repository or contact the development team.
Q: Do I need to set up Auth0, Stripe, and PayPal to run the application?
A: For full functionality, yes. However, you can use the demo authentication mode for development without Auth0. Payment providers are required for actual payment processing.
Q: Can I use this platform for production?
A: Yes, the platform is production-ready. However, ensure you configure all security settings, use production credentials, and follow the deployment checklist.
Q: How do I add a new payment provider?
A: Create a new payment service in backend/src/payments/, add the provider enum to the schema, and create corresponding API routes.
Q: How do I customize the UI?
A: The frontend uses Tailwind CSS. You can modify components in frontend/src/components/ and update styles using Tailwind utility classes.
Q: Can I deploy the frontend and backend separately?
A: Yes, they are completely decoupled. You can deploy the frontend to a CDN (e.g., Vercel, Netlify) and the backend to any Node.js hosting service.
Q: Why Prisma instead of other ORMs?
A: Prisma provides excellent TypeScript support, type safety, and a great developer experience with migrations and Prisma Studio.
Q: How do I reset the database?
A: You can drop and recreate the database, then run npm run prisma:migrate to apply all migrations.
Q: How do I enable Redis caching?
A: Redis is configured in Docker Compose. You'll need to implement caching logic in your API routes using the Redis client.
Q: What's the difference between demo mode and production auth?
A: Demo mode uses headers (X-Demo-Role) for development/testing. Production mode uses Auth0 JWT tokens for secure authentication.
- Enhanced caching with Redis implementation
- Real-time order status updates via WebSocket
- Additional payment providers integration (e.g., Alipay, WeChat Pay)
- Advanced analytics and reporting dashboard
- Mobile app support (React Native)
- Enhanced admin dashboard features
- Automated testing suite (unit, integration, e2e)
- CI/CD pipeline configuration
- API rate limiting and throttling
- Email notifications for order status
This project is built with the help of excellent open-source technologies and services:
- Auth0 - Enterprise-grade authentication and authorization
- Stripe - Payment processing infrastructure
- PayPal - Global payment solutions
- Prisma - Next-generation ORM for TypeScript
- React - UI library
- Express - Web framework
- Tailwind CSS - Utility-first CSS framework
- Vite - Next-generation frontend tooling
Special thanks to all open-source contributors and the communities behind these amazing tools.
Built with β€οΈ using TypeScript, React, and Node.js
Made with modern web technologies and best practices