<style>

  body { font-family: sans-serif; background: #f3f3f3; padding: 10px; }

  .fantasy-box { max-width: 600px; margin: auto; background: white; border-radius: 10px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }

  h2 { text-align: center; }

  .player { display: flex; justify-content: space-between; padding: 8px; border-bottom: 1px solid #eee; }

  .player:last-child { border-bottom: none; }

  .btn { padding: 10px 20px; background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; width: 100%; margin-top: 15px; }

  .btn:hover { background: #218838; }

  .selected { background-color: #d1e7dd; }

</style>


<div class="fantasy-box">

  <h2>Mini Fantasy Cricket</h2>

  <p>Select 3 players for your team:</p>


  <div id="playerList">

    <div class="player" onclick="selectPlayer(this)">Virat Kohli</div>

    <div class="player" onclick="selectPlayer(this)">Rohit Sharma</div>

    <div class="player" onclick="selectPlayer(this)">MS Dhoni</div>

    <div class="player" onclick="selectPlayer(this)">Hardik Pandya</div>

    <div class="player" onclick="selectPlayer(this)">Jasprit Bumrah</div>

  </div>


  <button class="btn" onclick="submitTeam()">Join Contest</button>


  <p id="result" style="margin-top: 10px; font-weight: bold;"></p>

</div>


<script>

  let selected = [];


  function selectPlayer(elem) {

    const name = elem.textContent;

    if (selected.includes(name)) {

      selected = selected.filter(p => p !== name);

      elem.classList.remove("selected");

    } else {

      if (selected.length >= 3) {

        alert("You can select only 3 players.");

        return;

      }

      selected.push(name);

      elem.classList.add("selected");

    }

  }


  function submitTeam() {

    if (selected.length !== 3) {

      alert("Please select exactly 3 players.");

      return;

    }

    document.getElementById("result").innerText =

      "Your Team: " + selected.join(", ") + " ✅";

  }

</script>

 

Aapka idea — Dream11 jaise ek fantasy sports platform banana — ek achha startup concept hai, lekin ismein legal compliance, security, aur real-money transaction kaafi mahatvapurn hote hain. Main aapko yahan ek basic fantasy cricket app ka backend code (Node.js + Express.js) ka demo dunga, jo aapko start karne mein madad karega.

⚠️ Note:

  • Real-money games India ke kuch states mein illegal hain (e.g., Assam, Odisha, Telangana, etc.)
  • Aapko RNG certificate, legal gaming license, aur payment gateway compliance (PCI-DSS) ki zarurat padegi agar aap real money involve karte ho.
  • Yeh sirf learning purpose ke liye code hai, production mein daalne se pehle security audit zaroor karein.

✅ Step 1: Project Setup (Express.js + MongoDB)

mkdir fantasy-app
cd fantasy-app
npm init -y
npm install express mongoose bcryptjs jsonwebtoken dotenv

✅ Step 2: server.js – Basic Express Server

const express = require('express');
const mongoose = require('mongoose');
require('dotenv').config();

const app = express();
app.use(express.json());

// Connect MongoDB
mongoose.connect(process.env.MONGO_URI)
  .then(() => console.log('MongoDB Connected'))
  .catch(err => console.log(err));

// Routes
app.get('/', (req, res) => {
  res.send('Fantasy Game API is running');
});

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

✅ Step 3: Secure User Auth (models/User.js)

const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');

const userSchema = new mongoose.Schema({
  name: String,
  email: { type: String, unique: true },
  password: String,
  wallet: { type: Number, default: 0 }
});

userSchema.pre('save', async function (next) {
  if (!this.isModified('password')) return next();
  const salt = await bcrypt.genSalt(10);
  this.password = await bcrypt.hash(this.password, salt);
  next();
});

module.exports = mongoose.model('User', userSchema);

✅ Step 4: Auth Routes (routes/auth.js)

const express = require('express');
const router = express.Router();
const User = require('../models/User');
const jwt = require('jsonwebtoken');
const bcrypt = require('bcryptjs');

// Register
router.post('/register', async (req, res) => {
  const { name, email, password } = req.body;
  const user = new User({ name, email, password });
  await user.save();
  res.send('User registered');
});

// Login
router.post('/login', async (req, res) => {
  const { email, password } = req.body;
  const user = await User.findOne({ email });
  if (!user) return res.status(400).send('Invalid email');

  const isMatch = await bcrypt.compare(password, user.password);
  if (!isMatch) return res.status(400).send('Invalid password');

  const token = jwt.sign({ id: user._id }, process.env.JWT_SECRET, {
    expiresIn: '1d'
  });
  res.json({ token });
});

module.exports = router;

✅ Step 5: Fantasy Match Logic (basic idea only)

You can store matches like this:

{
  "match_id": "INDvPAK2025",
  "players": ["Virat", "Rohit", "Babar", "Shaheen"],
  "users": [
    {
      "user_id": "abc123",
      "team": ["Virat", "Shaheen"]
    }
  ]
}

Aur jab match end ho jaye, to har player ke points assign karo, aur user ki team ke points calculate karke, winner ka wallet update karo.


✅ Step 6: .env File

MONGO_URI=mongodb://localhost:27017/fantasy-game
JWT_SECRET=supersecurekey

🔐 Security Tips:

  • Passwords hashed (bcrypt)
  • Token-based auth (JWT)
  • Use HTTPS in production
  • Validate all inputs
  • Sanitize DB queries (NoSQL injection)
  • Use CSRF tokens for frontend
  • Deploy on secure cloud (like Vercel backend + Firebase/Cloudflare frontend)

✅ Future Features You Can Add:

  • Admin panel for match creation
  • Live points update (use sockets or cron)
  • Payment integration (Razorpay/Paytm/Stripe)
  • Contest entry, leaderboard, withdrawals
  • 2FA login

Agar aap chahte ho ki main aapke liye is idea ka complete app design (backend + frontend + UI UX) banau, to mujhe batayein — main step by step help kar sakta hoon.

Chahen to aapko APK banwane ka tarika bhi sikha sakta hoon.

 <style>   body { font-family: sans-serif; background: #f3f3f3; padding: 10px; }   .fantasy-box { max-width: 600px; margin: auto; back...