T-Race is a modern typing speed game built with Next.js, Firebase Authentication, and MongoDB Atlas. Players can compete in typing challenges and track their progress with user accounts and leaderboards.
- π Firebase Authentication (Google Sign-In)
- π― Real-time typing speed calculation
- π User leaderboards and statistics
- π MongoDB Atlas for data persistence
- π¨ Modern UI with Tailwind CSS
- π± Responsive design
- Frontend: Next.js, React, Tailwind CSS
- Authentication: Firebase Auth
- Database: MongoDB Atlas with Mongoose
- Deployment: Vercel (recommended)
Before you begin, ensure you have:
- Node.js (v16 or later)
- npm or yarn
- Firebase project with Authentication enabled
- MongoDB Atlas cluster (free tier available)
git clone <your-repo-url>
cd T-racenpm installCopy the example environment file:
cp .env.example .env.localEdit .env.local and add your configuration:
# MongoDB Atlas Connection String
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/trace-db?retryWrites=true&w=majority
# Firebase Configuration (update firebase.js with your config)
# Get these values from your Firebase project settings at https://console.firebase.google.com/
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key # Project settings > General > Web API Key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com # Project settings > General > Auth domain
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id # Project settings > General > Project ID
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com # Project settings > General > Storage bucket
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id # Project settings > Cloud Messaging > Sender ID
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id # Project settings > General > App ID
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your_measurement_id # Project settings > General > Measurement ID (optional, for analytics)- Create a Firebase project at Firebase Console
- Enable Authentication and configure Google Sign-In
- Update
src/firebase.jswith your Firebase configuration
- Create a MongoDB Atlas account at MongoDB Atlas
- Create a new cluster (free tier M0 is sufficient)
- Create a database user with read/write permissions
- Whitelist your IP address (use
0.0.0.0/0for development) - Get your connection string and add it to
.env.local
npm run devOpen http://localhost:3000 with your browser to see the result.
src/
βββ components/ # React components
βββ context/ # React Context (Auth)
βββ lib/ # Database connection
βββ models/ # Mongoose models
βββ pages/ # Next.js pages and API routes
β βββ api/ # API endpoints
β β βββ users/ # User-related API routes
βββ styles/ # Global styles
POST /api/users/create-or-update- Create or update user dataPUT /api/users/update-score- Update user's game scoreGET /api/users/leaderboard- Get leaderboard data
- Sign In: Use Google Sign-In to authenticate
- Play Game: Navigate to the race page to start typing
- Track Progress: Your scores and statistics are automatically saved
- View Leaderboard: Check your ranking against other players
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Commit changes:
git commit -am 'Add new feature' - Push to branch:
git push origin feature/new-feature - Submit a Pull Request
- Push your code to GitHub
- Connect your repository to Vercel
- Add environment variables in Vercel dashboard
- Deploy!
Make sure to set these in your deployment platform:
MONGODB_URIFIREBASE_API_KEYFIREBASE_AUTH_DOMAINFIREBASE_PROJECT_IDFIREBASE_STORAGE_BUCKETFIREBASE_MESSAGING_SENDER_IDFIREBASE_APP_IDFIREBASE_MEASUREMENT_ID
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.