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.
This project showcases a real-world transformation from a basic single-tenant application to a sophisticated multi-tenant SaaS platform:
- โ Basic player and match management
- โ Simple statistics tracking
- โ Single club operations
- โ Complete architectural overhaul
- โ Club-based data isolation
- โ JWT-based authentication system
- โ Player self-service profiles
- โ Admin and player role separation
- โ Scalable SaaS architecture
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.
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
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
- 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
- Node.js v16+ and npm
- Supabase Account (free tier available)
- Git for cloning the repository
# 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-
Copy environment files:
cp backend/.env.example backend/.env cp frontend/.env.example frontend/.env
-
Create a Supabase project at supabase.com
-
Get your credentials from Project Settings โ API/Database
Note: The
.envfiles are not included in the repository for security. You must create them from the.env.exampletemplates and add your own credentials.
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-hereFrontend (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# Initialize multi-tenant database schema
cd backend
npm run init-db# Terminal 1: Start backend server
cd backend
npm run dev
# Terminal 2: Start frontend development server
cd frontend
npm run dev- Frontend: http://localhost:5174
- Backend API: http://localhost:5000
- Health Check: http://localhost:5000/api/health
- Visit the application โ "Admin Login"
- Click "Register Your Cricket Club"
- Enter club name and admin name
- Save the generated credentials (shown only once!)
- Login and start managing your club
- Ask your club admin to add you as a player
- Get your auto-generated credentials from admin
- Visit the application โ "Player Login"
- Login and customize your profile (DOB, country, etc.)
- View your statistics and match history
npm run dev # Start development server with hot reload
npm run init-db # Initialize/update multi-tenant database schema
npm start # Start production servernpm 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# Full development setup
npm run init-db # Initialize database (run once)
npm run dev # Start both servers simultaneouslyPOST /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 infoPOST /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 statisticsGET /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 statisticsGET /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- 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
The database automatically creates and maintains a multi-tenant architecture with complete data isolation between clubs.
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()
);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()
);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)
);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()
);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()
);- Data Isolation: Every table includes
club_idfor 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
-
Register Club ๐ข
- Visit application โ "Admin Login" โ "Register Your Cricket Club"
- Enter club name and admin name
- Save generated credentials (username/password shown once)
-
Manage Players ๐ฅ
- Add players โ System auto-generates login credentials
- Reset player passwords when needed
- View comprehensive player statistics
-
Organize Matches ๐
- Create matches with dynamic team selection
- Track live scores and wickets
- Record match results and statistics
-
Analyze Performance ๐
- View club-wide statistics and trends
- Track player performance over time
- Generate match reports and history
-
Get Credentials ๐
- Receive login credentials from club admin
- Username auto-generated from name (e.g., "john.doe")
-
Customize Profile ๐ค
- Login โ Profile dropdown โ "Edit Profile"
- Set date of birth and country
- View calculated age and career stats
-
Track Performance ๐
- View personal match history
- Analyze batting and bowling statistics
- Monitor career progression
-
Stay Updated ๐
- Real-time match updates
- Performance notifications
- Club announcements
# 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# 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"}'# 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- 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
- โ 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
- โ 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
- โ 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
- โ 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
- โ 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
- โ 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
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
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