Skip to content

A complete multi-tenant cricket management SaaS platform with secure super admin functionality, player self-service portals, and real-time match tracking. Built with React, Node.js, and Supabase.

Notifications You must be signed in to change notification settings

nitishb-dev/Cricket-Management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Multi-Tenant Cricket Management System

From Single Club to Multi-Club Excellence ๐Ÿš€

A comprehensive multi-tenant cricket management platform that evolved from a single-club system to support unlimited cricket clubs with complete data isolation, player authentication, and advanced statistics tracking.

๐ŸŒŸ Project Evolution: Single โ†’ Multi-Tenant

This project showcases a real-world transformation from a basic single-tenant application to a sophisticated multi-tenant SaaS platform:

Phase 1: Single-Tenant Foundation ๐Ÿ—๏ธ

  • โœ… Basic player and match management
  • โœ… Simple statistics tracking
  • โœ… Single club operations

Phase 2: Multi-Tenant Revolution ๐Ÿš€

  • โœ… Complete architectural overhaul
  • โœ… Club-based data isolation
  • โœ… JWT-based authentication system
  • โœ… Player self-service profiles
  • โœ… Admin and player role separation
  • โœ… Scalable SaaS architecture

๐ŸŽฏ AI-Powered Development Journey

This project demonstrates the power of AI-augmented development:

  • ๐Ÿ’ก Conceptualization: ChatGPT for system design and architecture
  • ๐Ÿ”ง Rapid Prototyping: bolt.new for initial code generation
  • ๐Ÿง  Advanced Implementation: Copilot, Google Gemini, and ChatGPT for complex features
  • ๐Ÿ”„ Iterative Refinement: Human creativity + AI assistance for optimal solutions

Result: A production-ready multi-tenant system built efficiently through AI collaboration.

โœจ Multi-Tenant Features

๐Ÿข Club Management

  • Club Registration: Self-service club registration with auto-generated admin credentials
  • Data Isolation: Complete separation between clubs - no cross-club data access
  • Admin Dashboard: Comprehensive club management interface
  • Password Reset: Secure password reset for club admins

๐Ÿ‘ฅ Player Management

  • Dual Authentication: Separate login systems for admins and players
  • Player Profiles: Self-service profile editing (DOB, country, personal info)
  • Auto-Generated Credentials: Automatic username/password generation for new players
  • Role-Based Access: Players see only their own data, admins manage their club

๐Ÿ Match & Statistics

  • Dynamic Team Creation: Flexible team formation from club players
  • Live Match Tracking: Real-time score and wicket tracking
  • Advanced Statistics: Comprehensive player and match analytics
  • Match History: Complete historical data with filtering and search
  • Performance Analytics: Batting averages, bowling figures, win percentages

๐Ÿ” Security & Authentication

  • JWT-Based Security: Secure token-based authentication
  • Multi-Tenant Isolation: Database-level data separation
  • Role-Based Permissions: Admin vs Player access controls
  • Secure Password Management: Bcrypt hashing and secure storage

๐Ÿ“ฑ User Experience

  • Responsive Design: Mobile-first, works on all devices
  • Intuitive Navigation: Role-based navigation and dashboards
  • Real-Time Updates: Immediate reflection of data changes
  • Professional UI: Modern, clean interface with Tailwind CSS

๐Ÿ› ๏ธ Technology Stack

Frontend ๐ŸŽจ

  • React 18 + TypeScript - Modern, type-safe UI development
  • Tailwind CSS - Utility-first styling for responsive design
  • React Router - Client-side routing with protected routes
  • Context API - State management for authentication and data
  • Vite - Lightning-fast build tool and dev server

Backend โš™๏ธ

  • Node.js + Express - Scalable server architecture
  • JWT Authentication - Secure token-based auth system
  • Bcrypt - Password hashing and security
  • Multi-tenant Architecture - Club-based data isolation
  • RESTful APIs - Clean, documented API endpoints

Database ๐Ÿ—„๏ธ

  • Supabase (PostgreSQL) - Managed database with real-time features
  • Multi-tenant Schema - Club-scoped data with foreign key constraints
  • Automatic Migrations - Schema updates and data migration scripts
  • Connection Pooling - Optimized database connections

DevOps & Tools ๐Ÿ”ง

  • Environment Configuration - Separate dev/prod configurations
  • Hot Reload - Development efficiency with instant updates
  • TypeScript - End-to-end type safety
  • ESLint + Prettier - Code quality and formatting

๐Ÿ“ Project Architecture

CricketManagementApp/
โ”œโ”€โ”€ ๐ŸŽจ frontend/                    # React Multi-Tenant Frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AdminLogin.tsx      # Club admin authentication
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ClubRegistration.tsx # Self-service club registration
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ PlayerLogin.tsx     # Player authentication
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ PlayerProfile.tsx   # Player profile management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ EditProfile.tsx     # Self-service profile editing
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Dashboard.tsx       # Admin dashboard
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ PlayerDashboard.tsx # Player dashboard
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Navigation.tsx      # Role-based navigation
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ProtectedRoute.tsx  # Route protection
โ”‚   โ”‚   โ”œโ”€โ”€ context/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AuthContext.tsx     # Multi-tenant authentication
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ CricketContext.tsx  # Data management
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ usePlayerApi.ts     # Player API hooks
โ”‚   โ”‚   โ”œโ”€โ”€ types/cricket.ts        # TypeScript definitions
โ”‚   โ”‚   โ””โ”€โ”€ App.tsx                 # Multi-tenant routing
โ”‚   โ””โ”€โ”€ .env                        # Frontend configuration
โ”‚
โ”œโ”€โ”€ โš™๏ธ backend/                     # Node.js Multi-Tenant Backend
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ auth.js                 # Club & admin authentication
โ”‚   โ”‚   โ”œโ”€โ”€ player-auth.js          # Player authentication & profiles
โ”‚   โ”‚   โ”œโ”€โ”€ players.js              # Player management (admin)
โ”‚   โ”‚   โ””โ”€โ”€ matches.js              # Match management
โ”‚   โ”œโ”€โ”€ db-setup.js                 # Multi-tenant schema & migrations
โ”‚   โ”œโ”€โ”€ index.js                    # Express server with JWT middleware
โ”‚   โ””โ”€โ”€ .env                        # Backend configuration
โ”‚
โ””โ”€โ”€ ๐Ÿ“– README.md                    # This comprehensive guide

Key Architectural Decisions ๐Ÿ—๏ธ

  • Multi-Tenant Database Design: Club-scoped tables with foreign key constraints
  • JWT Authentication: Stateless authentication with role-based access
  • Component Separation: Distinct admin and player interfaces
  • API Isolation: Club-filtered endpoints preventing cross-tenant access
  • Self-Service Registration: Automated club onboarding without manual intervention

๐Ÿš€ Quick Start Guide

Prerequisites ๐Ÿ“‹

  • Node.js v16+ and npm
  • Supabase Account (free tier available)
  • Git for cloning the repository

1. Clone & Install ๐Ÿ“ฆ

# Clone the repository
git clone https://github.com/yourusername/cricket-management-app.git
cd cricket-management-app

# Install dependencies for both frontend and backend
cd frontend && npm install
cd ../backend && npm install

2. Environment Setup ๐Ÿ”ง

  1. Copy environment files:

    cp backend/.env.example backend/.env
    cp frontend/.env.example frontend/.env
  2. Create a Supabase project at supabase.com

  3. Get your credentials from Project Settings โ†’ API/Database

Note: The .env files are not included in the repository for security. You must create them from the .env.example templates and add your own credentials.

3. Environment Configuration โš™๏ธ

Backend (backend/.env):

# Supabase Database Connection
SUPABASE_DB_URL=postgresql://postgres:[password]@[host]:5432/postgres

# Server Configuration  
PORT=5000
NODE_ENV=development

# JWT Secret (generate a secure random string)
JWT_SECRET=your-super-secret-jwt-key-here

Frontend (frontend/.env):

# API Configuration
VITE_API_URL=http://localhost:5000

# Optional: Supabase Client (for future features)
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your-anon-key

4. Initialize Database ๐Ÿ”ง

# Initialize multi-tenant database schema
cd backend
npm run init-db

5. Start the Application ๐Ÿš€

# Terminal 1: Start backend server
cd backend
npm run dev

# Terminal 2: Start frontend development server  
cd frontend
npm run dev

6. Access the Application ๐ŸŒ

๐ŸŽฏ Getting Started as a User

For Club Admins ๐Ÿ‘จโ€๐Ÿ’ผ

  1. Visit the application โ†’ "Admin Login"
  2. Click "Register Your Cricket Club"
  3. Enter club name and admin name
  4. Save the generated credentials (shown only once!)
  5. Login and start managing your club

For Players ๐Ÿ

  1. Ask your club admin to add you as a player
  2. Get your auto-generated credentials from admin
  3. Visit the application โ†’ "Player Login"
  4. Login and customize your profile (DOB, country, etc.)
  5. View your statistics and match history

๐Ÿ“‹ Available Commands

Backend Commands โš™๏ธ

npm run dev              # Start development server with hot reload
npm run init-db          # Initialize/update multi-tenant database schema  
npm start                # Start production server

Frontend Commands ๐ŸŽจ

npm run dev              # Start Vite development server
npm run build            # Build optimized production bundle
npm run preview          # Preview production build locally
npm run lint             # Run ESLint for code quality

Development Workflow ๐Ÿ”„

# Full development setup
npm run init-db          # Initialize database (run once)
npm run dev              # Start both servers simultaneously

๐Ÿ”ง Multi-Tenant API Documentation

Authentication Endpoints ๐Ÿ”

POST /api/auth/register-club     # Register new cricket club
POST /api/auth/login             # Club admin login  
POST /api/auth/reset-password    # Reset admin password
GET  /api/auth/me                # Get current admin info

Player Authentication ๐Ÿ‘ฅ

POST /api/player/login           # Player login
GET  /api/player/profile         # Get player profile
PUT  /api/player/profile         # Update player profile (DOB, country)
GET  /api/player/history         # Get player's match history
GET  /api/player/detailed-stats  # Get player's detailed statistics

Admin Player Management ๐Ÿ‘จโ€๐Ÿ’ผ

GET    /api/players              # Get all club players
POST   /api/players              # Add new player (auto-generates credentials)
PUT    /api/players/:id          # Update player name
DELETE /api/players/:id          # Delete player
POST   /api/players/:id/reset-password  # Reset player password
GET    /api/players/stats/all    # Get all players' statistics
GET    /api/players/stats/:id    # Get specific player statistics

Match Management ๐Ÿ

GET    /api/matches              # Get all club matches
GET    /api/matches/:id          # Get specific match
POST   /api/matches              # Create new match
DELETE /api/matches/:id          # Delete match
GET    /api/matches/:id/stats    # Get match player statistics

API Security Features ๐Ÿ›ก๏ธ

  • JWT Authentication: All endpoints require valid tokens
  • Club Isolation: Automatic filtering by club_id
  • Role-Based Access: Admin vs Player endpoint separation
  • Input Validation: Comprehensive request validation
  • Error Handling: Consistent error responses

๐Ÿ—„๏ธ Multi-Tenant Database Schema

The database automatically creates and maintains a multi-tenant architecture with complete data isolation between clubs.

Core Multi-Tenant Tables ๐Ÿข

Clubs Table

CREATE TABLE clubs (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  name TEXT NOT NULL UNIQUE,
  created_at TIMESTAMPTZ DEFAULT NOW(),
  updated_at TIMESTAMPTZ DEFAULT NOW()
);

Admins Table

CREATE TABLE admins (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  club_id UUID NOT NULL REFERENCES clubs(id) ON DELETE CASCADE,
  username TEXT NOT NULL UNIQUE,
  admin_name TEXT NOT NULL,
  password_hash TEXT NOT NULL,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

Club-Scoped Data Tables ๐Ÿ

Players Table

CREATE TABLE players (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  club_id UUID NOT NULL REFERENCES clubs(id) ON DELETE CASCADE,
  name TEXT NOT NULL,
  username TEXT,
  password_hash TEXT,
  date_of_birth DATE,
  country TEXT,
  created_at TIMESTAMPTZ DEFAULT NOW(),
  CONSTRAINT players_name_club_id_key UNIQUE(name, club_id),
  CONSTRAINT players_username_club_id_key UNIQUE(username, club_id)
);

Matches Table

CREATE TABLE matches (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  club_id UUID NOT NULL REFERENCES clubs(id) ON DELETE CASCADE,
  team_a_name TEXT NOT NULL,
  team_b_name TEXT NOT NULL,
  overs INT NOT NULL,
  toss_winner TEXT,
  toss_decision TEXT,
  team_a_score INT DEFAULT 0,
  team_a_wickets INT DEFAULT 0,
  team_b_score INT DEFAULT 0,
  team_b_wickets INT DEFAULT 0,
  winner TEXT,
  man_of_match TEXT,
  match_date DATE DEFAULT CURRENT_DATE,
  is_completed BOOLEAN DEFAULT false,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

Match Player Stats Table

CREATE TABLE match_player_stats (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  club_id UUID NOT NULL REFERENCES clubs(id) ON DELETE CASCADE,
  match_id UUID NOT NULL REFERENCES matches(id) ON DELETE CASCADE,
  player_id UUID NOT NULL REFERENCES players(id) ON DELETE CASCADE,
  team TEXT NOT NULL,
  runs INT DEFAULT 0,
  wickets INT DEFAULT 0,
  ones INT DEFAULT 0,
  twos INT DEFAULT 0,
  threes INT DEFAULT 0,
  fours INT DEFAULT 0,
  sixes INT DEFAULT 0,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

Multi-Tenant Features ๐Ÿ”’

  • Data Isolation: Every table includes club_id for complete separation
  • Cascading Deletes: Automatic cleanup when clubs are removed
  • Unique Constraints: Player names and usernames unique per club
  • Referential Integrity: Foreign key constraints maintain data consistency
  • Automatic Migration: Schema updates applied automatically on startup

๐ŸŽฎ Multi-Tenant Usage Guide

Club Admin Workflow ๐Ÿ‘จโ€๐Ÿ’ผ

  1. Register Club ๐Ÿข

    • Visit application โ†’ "Admin Login" โ†’ "Register Your Cricket Club"
    • Enter club name and admin name
    • Save generated credentials (username/password shown once)
  2. Manage Players ๐Ÿ‘ฅ

    • Add players โ†’ System auto-generates login credentials
    • Reset player passwords when needed
    • View comprehensive player statistics
  3. Organize Matches ๐Ÿ

    • Create matches with dynamic team selection
    • Track live scores and wickets
    • Record match results and statistics
  4. Analyze Performance ๐Ÿ“Š

    • View club-wide statistics and trends
    • Track player performance over time
    • Generate match reports and history

Player Workflow ๐Ÿ

  1. Get Credentials ๐Ÿ”‘

    • Receive login credentials from club admin
    • Username auto-generated from name (e.g., "john.doe")
  2. Customize Profile ๐Ÿ‘ค

    • Login โ†’ Profile dropdown โ†’ "Edit Profile"
    • Set date of birth and country
    • View calculated age and career stats
  3. Track Performance ๐Ÿ“ˆ

    • View personal match history
    • Analyze batting and bowling statistics
    • Monitor career progression
  4. Stay Updated ๐Ÿ”„

    • Real-time match updates
    • Performance notifications
    • Club announcements

๐Ÿ”ง Troubleshooting Guide

Database Issues ๐Ÿ—„๏ธ

# Check database connection
curl http://localhost:5000/api/health

# Reinitialize database schema
cd backend && npm run init-db

# Common fixes:
# - Verify SUPABASE_DB_URL in backend/.env
# - Check Supabase project is active
# - Ensure database URL includes password

Authentication Issues ๐Ÿ”

# Clear browser storage and cookies
# Check JWT_SECRET is set in backend/.env
# Verify API_URL in frontend/.env matches backend

# Test authentication:
curl -X POST http://localhost:5000/api/auth/register-club \
  -H "Content-Type: application/json" \
  -d '{"clubName": "Test Club", "adminName": "Test Admin"}'

Development Issues ๐Ÿ’ป

# Port conflicts
# Frontend: Change port in vite.config.ts
# Backend: Change PORT in .env

# Module not found errors
rm -rf node_modules package-lock.json
npm install

# CORS issues
# Check VITE_API_URL matches backend URL
# Verify backend CORS configuration

Common Solutions โœ…

  • 404 Errors: Check API endpoints and authentication
  • Blank Pages: Verify environment variables are set
  • Login Failures: Ensure database is initialized
  • Permission Errors: Check JWT token and role-based access

๐ŸŽ‰ Complete Feature Set

Multi-Tenant Core ๐Ÿข

  • โœ… Club Registration System - Self-service onboarding
  • โœ… Data Isolation - Complete separation between clubs
  • โœ… Admin Authentication - Secure club admin access
  • โœ… Player Authentication - Individual player accounts
  • โœ… Role-Based Access - Admin vs Player permissions
  • โœ… Password Management - Reset functionality for both roles

Player Management ๐Ÿ‘ฅ

  • โœ… Auto-Generated Credentials - Seamless player onboarding
  • โœ… Self-Service Profiles - Players edit their own info
  • โœ… Profile Customization - DOB, country, personal details
  • โœ… Age Calculation - Automatic age computation from DOB
  • โœ… Player Statistics - Comprehensive performance tracking

Match Management ๐Ÿ

  • โœ… Dynamic Team Creation - Flexible team formation
  • โœ… Live Match Tracking - Real-time score updates
  • โœ… Toss & Innings Management - Complete match flow
  • โœ… Automatic Winner Detection - Smart result calculation
  • โœ… Man of the Match - Performance-based selection
  • โœ… Match History - Complete historical records

Analytics & Statistics ๐Ÿ“Š

  • โœ… Player Performance Metrics - Batting/bowling averages
  • โœ… Career Statistics - Long-term performance tracking
  • โœ… Match Analytics - Detailed match breakdowns
  • โœ… Boundary Analysis - Ones, twos, threes, fours, sixes
  • โœ… Win/Loss Records - Team and individual performance
  • โœ… Historical Trends - Performance over time

User Experience ๐ŸŽจ

  • โœ… Responsive Design - Mobile-first, works everywhere
  • โœ… Intuitive Navigation - Role-based menus and dashboards
  • โœ… Real-Time Updates - Instant data synchronization
  • โœ… Professional UI - Modern, clean interface
  • โœ… Error Handling - Comprehensive error management
  • โœ… Loading States - Smooth user experience

Technical Excellence ๐Ÿ”ง

  • โœ… TypeScript - End-to-end type safety
  • โœ… JWT Security - Stateless authentication
  • โœ… Database Migrations - Automatic schema updates
  • โœ… API Documentation - Well-documented endpoints
  • โœ… Environment Configuration - Flexible deployment
  • โœ… Hot Reload - Efficient development workflow

๐Ÿš€ Deployment Ready

This application is production-ready with:

  • Environment-based configuration
  • Secure authentication system
  • Scalable multi-tenant architecture
  • Comprehensive error handling
  • Mobile-responsive design
  • Database migration system

๐Ÿ“ˆ Future Enhancements

Potential additions for further development:

  • Tournament Management - Multi-team tournaments
  • Live Streaming Integration - Real-time match broadcasting
  • Mobile App - Native iOS/Android applications
  • Advanced Analytics - ML-powered insights
  • Social Features - Player interactions and messaging
  • Payment Integration - Subscription management for clubs

Built with โค๏ธ using AI-augmented development
Showcasing the power of human creativity + AI assistance

About

A complete multi-tenant cricket management SaaS platform with secure super admin functionality, player self-service portals, and real-time match tracking. Built with React, Node.js, and Supabase.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published