A full-stack cricket-themed mathematics quiz game with MongoDB backend integration.
- ✅ Frontend: React + TypeScript + Vite
- ✅ Backend: Node.js + Express + MongoDB
- ✅ Database: MongoDB for persistent game data storage
- ✅ UI: Beautiful animations with Framer Motion
- ✅ Team Management: Import/Export teams (CSV/JSON)
- ✅ Parallel Games: Run multiple games simultaneously
- ✅ Game History: Track all past games in MongoDB
- ✅ Professional Popups: Animated event notifications
MPL25/
├── src/ # Frontend source
│ ├── components/ # React components
│ ├── services/ # API service (connects to backend)
│ ├── data/ # Questions data
│ └── ...
├── backend/ # Backend server
│ ├── src/
│ │ ├── config/ # Database configuration
│ │ ├── controllers/ # Business logic
│ │ ├── models/ # MongoDB schemas
│ │ ├── routes/ # API routes
│ │ └── server.js # Express server
│ ├── package.json
│ └── ...
├── dist/ # Built frontend
└── package.json
- Node.js (v14 or higher)
- MongoDB (Docker, local, or Atlas)
- npm or yarn
-
Clone/Navigate to the project
cd "MPL25"
-
Install Frontend Dependencies
npm install
-
Install Backend Dependencies
cd backend npm install cd ..
-
Start MongoDB (Choose one)
Docker (Recommended):
docker run -d -p 27017:27017 --name mongodb mongo:latest
OR Local MongoDB:
# Make sure MongoDB is running on port 27017 -
Run Both Frontend and Backend
npm run dev:both
This starts:
- Frontend on:
http://localhost:5173 - Backend on:
http://localhost:3000
- Frontend on:
Terminal 1 - Frontend:
npm run devTerminal 2 - Backend:
npm run dev:backenddocker run -d -p 27017:27017 --name mongodb mongo:latestDownload from: https://www.mongodb.com/try/download/community
- Go to https://www.mongodb.com/cloud/atlas
- Create free account
- Create cluster
- Update
backend/.env:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/mpl_gamesCreate MPL25/.env:
VITE_API_URL=http://localhost:3000/api/gamesAlready configured in backend/.env:
MONGODB_URI=mongodb://localhost:27017/mpl_games
PORT=3000
NODE_ENV=developmentnpm run dev:bothNavigate to: http://localhost:5173
- Enter team names and player lists
- OR import from CSV/JSON using "Import Teams" button
- Export teams using "Export Teams" button
- Complete the toss
- Answer questions to score runs
- Watch professional animated popups for events
- Track your game history in MongoDB
GET http://localhost:3000/health
POST http://localhost:3000/api/games
Content-Type: application/json
{
"teamA": { name, players, score },
"teamB": { name, players, score },
"battingFirst": "A" | "B",
"winner": string,
"gameOver": boolean
}
GET http://localhost:3000/api/games?limit=20
GET http://localhost:3000/api/games/:id
All game data is stored in MongoDB:
- Name:
mpl_games - Collection:
games
- Team names and players
- Final scores (runs/wickets/overs)
- Winner information
- Timestamp (for proofs)
- Batting order
- Download: https://www.mongodb.com/products/compass
- Connect to:
mongodb://localhost:27017 - Browse:
mpl_games→gamescollection
{
teamA: {
name: String, // Team A name
players: [String], // List of players
score: { // Final score
runs: Number,
wickets: Number,
overs: Number
}
},
teamB: {
name: String, // Team B name
players: [String], // List of players
score: { // Final score
runs: Number,
wickets: Number,
overs: Number
}
},
battingFirst: "A" | "B", // Which team batted first
winner: String, // Winner name
gameOver: Boolean, // Is game complete
timestamp: Date, // Game timestamp (proof)
createdAt: Date, // Record created
updatedAt: Date // Last updated
}npm run dev # Start dev server
npm run build # Build for production
npm run preview # Preview production buildcd backend
npm run dev # Start with nodemon (auto-reload)
npm start # Start production servernpm run dev:both # Start both frontend and backend{
"teamA": {
"name": "Team A",
"players": ["Player 1", "Player 2", "Player 3"]
},
"teamB": {
"name": "Team B",
"players": ["Player 4", "Player 5", "Player 6"]
}
}Team A,Player 1,Player 2,Player 3
Team B,Player 4,Player 5,Player 6Issue: "Could not connect to MongoDB"
Solution:
- Check MongoDB is running:
docker ps - Verify connection string in
backend/.env - For Atlas, check IP whitelist
Issue: "Failed to fetch game data"
Solution:
- Check backend is running:
http://localhost:3000/health - Verify
VITE_API_URLin.env - Check CORS settings in backend
Issue: "Port 3000/5173 already in use"
Solution:
- Stop the process using the port
- Change port in configuration files
- Update frontend
.envaccordingly
npm run build
# Deploy dist/ folder to hosting servicecd backend
NODE_ENV=production npm start- Backend Setup:
backend/README.md - Frontend Changes:
CHANGES.md - Backend Guide:
BACKEND_SETUP.md
- Add user authentication
- Implement real-time multiplayer
- Add advanced analytics
- Create tournament mode
- Add custom question sets
This project is part of the Mathematics Premier League initiative.