A comprehensive web application for tracking and managing football team statistics, player performance, and match results. Built with modern web technologies, this application provides a complete solution for internal team management with real-time updates, detailed analytics, and an intuitive admin interface.
- Overview
- Features
- Tech Stack
- Project Structure
- Database Schema
- Authentication & Authorization
- API Routes
- Getting Started
- Environment Variables
- Deployment
- Contributing
- License
The Football Statistics Tracker is designed for managing company or team football matches. It provides a complete solution for:
- Player Management: Register, approve, and manage player profiles with photos and positions
- Match Tracking: Record internal and external matches with detailed statistics
- Real-time Statistics: Track goals, assists, cards, clean sheets, saves, and minutes played
- Leaderboards: Multiple leaderboard categories showcasing top performers
- Admin Panel: Comprehensive admin interface for managing all aspects of the system
- Public Statistics: Beautiful public-facing statistics page for showcasing team performance
- Email/Password Authentication: Secure login and registration via Supabase Auth
- User Approval System: Admin-controlled user approval workflow (pending β approved β rejected)
- Role-Based Access Control: Separate roles for admins and players
- User Profiles: Extended profiles with position, phone, and photo upload
- Session Management: Automatic session refresh and secure logout
- Player Registration: Self-registration with admin approval workflow
- Player Profiles:
- Profile photos with Supabase Storage integration
- Jersey numbers and preferred positions
- Contact information (email, phone)
- Player statistics aggregation
- Player Search & Filter: Real-time search by name, email, position, or jersey number
- Player Statistics: Individual player pages with detailed match history and stats
- Real-time Updates: Automatic UI updates when player data changes
- Match Types: Support for both internal and external matches
- Match Creation:
- Date, time, and location tracking
- Opponent information for external matches
- Team assignment (Team A vs Team B)
- Match status tracking (scheduled, in_progress, completed)
- Player Assignment: Assign players to teams for each match
- Score Tracking: Update match scores with real-time UI updates
- Match Details: Comprehensive match view with:
- Team lineups
- Individual player statistics per match
- Goals, assists, cards, minutes played
- Clean sheets and saves (for goalkeepers)
- Match Filtering: Filter by status (scheduled, in_progress, completed) and type (internal, external)
- Match Search: Search matches by teams, location, or status
- Comprehensive Statistics Tracking:
- Goals scored
- Assists provided
- Yellow and red cards
- Minutes played
- Clean sheets (for defenders/goalkeepers)
- Saves (for goalkeepers)
- Multiple Leaderboards:
- Top Goal Scorers
- Top Assist Makers
- Top Performers (Goals + Assists combined)
- Most Active Players (matches played)
- Goals per Match (efficiency)
- Most Minutes Played
- Top Clean Sheets
- Top Saves
- Player Statistics Pages: Individual player pages showing:
- Total goals, assists, cards
- Matches played and minutes
- Match-by-match breakdown
- Performance trends
- Dashboard Overview:
- Total players, matches, goals
- Top scorers and assisters
- Recent and upcoming matches
- Quick statistics cards
- Beautiful Landing Page: Modern, gradient-based design
- Upcoming Match Banner: Highlighted next match with countdown
- Overview Statistics: Key metrics at a glance
- Top Performers: Visual leaderboards with rankings
- Recent Matches: Latest match results with winner indicators
- Responsive Design: Mobile-friendly layout
- Admin Dashboard:
- System statistics overview
- Pending player approvals
- Recent activity feed
- Quick action buttons
- Player Management:
- Create, edit, and delete players
- Approve/reject player registrations
- Update player information
- Match Management:
- Create new matches
- Update match details and scores
- Assign players to teams
- Update individual player statistics per match
- Delete matches (with cascade deletion)
- System Administration:
- View all users and their status
- Manage user roles
- System health monitoring
- Responsive Design: Mobile-first approach with desktop optimization
- Real-time Updates: Supabase Realtime subscriptions for live data
- Loading States: Skeleton loaders and loading indicators
- Error Handling: Comprehensive error messages and fallbacks
- Toast Notifications: User-friendly success/error notifications
- Search & Filter: Advanced filtering across all major pages
- Image Upload: Profile photo uploads with preview
- Protected Routes: Route protection based on authentication and roles
- Sidebar Navigation: Collapsible sidebar with mobile support
- Next.js 14.0.4: React framework with App Router
- Server Components for SSR data fetching
- Client Components for interactive UI
- API Routes for backend operations
- React 18: UI library with hooks
- TypeScript 5: Type-safe development
- Tailwind CSS 3.3.0: Utility-first CSS framework
- shadcn/ui: High-quality component library built on Radix UI
- Card, Button, Input, Badge, Toast components
- Accessible and customizable
- Lucide React: Modern icon library
- React Context API: Global state management for user authentication
- Supabase: Backend-as-a-Service
- PostgreSQL Database: Relational database with Row Level Security
- Supabase Auth: Authentication and user management
- Supabase Storage: File storage for player photos
- Supabase Realtime: Real-time database subscriptions
- Row Level Security (RLS): Database-level security policies
- ESLint: Code linting with Next.js config
- PostCSS: CSS processing
- Autoprefixer: CSS vendor prefixing
- TypeScript: Static type checking
- Vercel: Hosting and deployment platform
- Environment Variables: Secure configuration management
football_stats/
βββ app/ # Next.js App Router pages
β βββ api/ # API route handlers
β β βββ admin-dashboard/ # Admin dashboard data
β β βββ create-admin/ # Admin creation utility
β β βββ create-match/ # Match creation
β β βββ create-player/ # Player creation
β β βββ dashboard/ # Main dashboard data
β β βββ leaderboards/ # Leaderboard data
β β βββ match-details/ # Match details API
β β βββ matches/ # Matches CRUD
β β βββ player-stats/ # Player statistics
β β βββ players/ # Players CRUD
β β βββ stats-page/ # Public stats page data
β β βββ update-*/ # Various update endpoints
β βββ admin/ # Admin pages
β β βββ create-match/ # Match creation form
β β βββ create-player/ # Player creation form
β β βββ page.tsx # Admin dashboard
β βββ auth/ # Authentication pages
β β βββ login/ # Login page
β β βββ register/ # Registration page
β βββ dashboard/ # Main dashboard
β βββ leaderboards/ # Leaderboards page
β βββ matches/ # Matches pages
β β βββ [id]/ # Match details page
β βββ player/ # Player detail pages
β β βββ [id]/ # Individual player page
β βββ players/ # Players list page
β βββ stats/ # Public statistics page
β βββ layout.tsx # Root layout with sidebar
β βββ globals.css # Global styles
β βββ page.tsx # Home/redirect page
βββ components/ # React components
β βββ ui/ # shadcn/ui components
β β βββ badge.tsx
β β βββ button.tsx
β β βββ card.tsx
β β βββ input.tsx
β β βββ toast.tsx
β βββ AdminCreationUtility.tsx # Admin creation component
β βββ ImageUpload.tsx # Image upload component
β βββ MatchCard.tsx # Match card component
β βββ MatchCreationForm.tsx # Match creation form
β βββ MatchDetailsModal.tsx # Match details modal
β βββ MatchDetailsView.tsx # Match details view
β βββ MobileHeader.tsx # Mobile navigation header
β βββ PendingApprovalsCard.tsx # Pending approvals component
β βββ PlayerAvatar.tsx # Player avatar component
β βββ PlayerCard.tsx # Player card component
β βββ PlayerCreationForm.tsx # Player creation form
β βββ PlayerEditModal.tsx # Player edit modal
β βββ ProtectedRoute.tsx # Route protection HOC
β βββ ScoreUpdateModal.tsx # Score update modal
β βββ Sidebar.tsx # Navigation sidebar
β βββ TopHeader.tsx # Top header component
βββ context/ # React Context providers
β βββ UserContext.tsx # User authentication context
βββ lib/ # Utility libraries
β βββ api.ts # API helper functions
β βββ auth.ts # Authentication helpers
β βββ supabaseClient.ts # Supabase client configuration
β βββ useRefresh.ts # Refresh hook
β βββ utils.ts # General utilities
βββ types/ # TypeScript type definitions
β βββ index.ts # All type definitions
βββ public/ # Static assets
β βββ favicon.ico
β βββ favicon.svg
βββ archive/ # Archived SQL files
β βββ sql-files/ # Database migration files
βββ next.config.js # Next.js configuration
βββ tailwind.config.js # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json # Dependencies and scripts
βββ env.example # Environment variables template
βββ README.md # This file
Extends Supabase Auth users with additional profile information.
id(UUID, Primary Key, References auth.users)email(TEXT, Unique)name(TEXT, Required)position(TEXT, Optional) - Player positionphone(TEXT, Optional)photo_url(TEXT, Optional) - Supabase Storage URLrole(TEXT) - 'admin' or 'player'status(TEXT) - 'pending', 'approved', or 'rejected'approved_at(TIMESTAMP, Optional)approved_by(UUID, Optional, References auth.users)created_at,updated_at(TIMESTAMP)
Player-specific information linked to user profiles.
id(UUID, Primary Key)user_id(UUID, Unique, References user_profiles)jersey_number(INTEGER, Optional)preferred_position(TEXT, Optional)created_at,updated_at(TIMESTAMP)
Match information and results.
id(UUID, Primary Key)type(TEXT) - 'internal' or 'external'date(TIMESTAMP, Required)opponent(TEXT, Optional) - For external matcheslocation(TEXT, Optional)status(TEXT) - 'scheduled', 'in_progress', 'completed'score_teamA(INTEGER, Default: 0)score_teamB(INTEGER, Default: 0)created_by(UUID, References auth.users)created_at,updated_at(TIMESTAMP)
Teams for each match (Team A, Team B, or custom names).
id(UUID, Primary Key)match_id(UUID, References matches, Cascade Delete)name(TEXT, Required) - 'Team A', 'Team B', or customcolor(TEXT, Optional) - Team colorcreated_at(TIMESTAMP)
Junction table linking players to matches and teams.
id(UUID, Primary Key)match_id(UUID, References matches, Cascade Delete)player_id(UUID, References players, Cascade Delete)team_id(UUID, References teams, Cascade Delete)position(TEXT, Optional) - Player position in this matchcreated_at(TIMESTAMP)- Unique constraint on (match_id, player_id)
Individual player statistics per match.
id(UUID, Primary Key)match_player_id(UUID, Unique, References match_players, Cascade Delete)goals(INTEGER, Default: 0)assists(INTEGER, Default: 0)yellow_cards(INTEGER, Default: 0)red_cards(INTEGER, Default: 0)minutes_played(INTEGER, Default: 90)clean_sheets(INTEGER, Default: 0) - For defenders/goalkeeperssaves(INTEGER, Default: 0) - For goalkeeperscreated_at,updated_at(TIMESTAMP)
- Email, role, and status indexes on
user_profiles - Date and status indexes on
matches - Match and player indexes on
match_players - Match player index on
stats
All tables have RLS enabled with policies for:
- Admins: Full CRUD access
- Players: Read access to approved data
- Public: Limited read access for public statistics
- Registration: Users register with email/password via Supabase Auth
- Profile Creation: User profile created with 'pending' status
- Admin Approval: Admin approves/rejects user registration
- Access Control: Only approved users can access protected routes
- Admin Role:
- Full access to all features
- Can create/edit/delete players and matches
- Can approve/reject user registrations
- Access to admin dashboard
- Player Role:
- View own profile and statistics
- View public statistics and leaderboards
- View matches and player information
- Cannot modify data
/dashboard- Requires approved user/admin/*- Requires admin role and approved status/players,/matches- Public read, admin write/leaderboards,/stats- Public access
POST /api/create-admin- Create admin user (development only)- User authentication handled via Supabase Auth client-side
GET /api/players- Get all playersGET /api/players/[id]- Get player detailsPOST /api/create-player- Create new player (admin only)PUT /api/update-player- Update player (admin only)DELETE /api/players/[id]- Delete player (admin only)
GET /api/matches- Get all matchesGET /api/matches/[id]- Get match detailsPOST /api/create-match- Create new match (admin only)PUT /api/update-match-info- Update match information (admin only)PUT /api/update-match-score- Update match score (admin only)PUT /api/update-match-details- Update match details and player stats (admin only)PUT /api/update-team-players- Update team player assignments (admin only)DELETE /api/matches/[id]- Delete match (admin only)
GET /api/dashboard- Get dashboard statisticsGET /api/leaderboards- Get all leaderboard dataGET /api/player-stats- Get player statisticsGET /api/stats-page- Get public statistics page dataGET /api/match-details/[id]- Get detailed match information
GET /api/admin-dashboard- Get admin dashboard data
- Node.js 18+ and npm/pnpm
- Supabase account and project
- Git (for version control)
-
Clone the repository
git clone <repository-url> cd football_stats
-
Install dependencies
npm install # or pnpm install -
Set up environment variables
cp env.example .env.local
Edit
.env.localwith your Supabase credentials:NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key SUPABASE_SERVICE_ROLE_KEY=your_service_role_key ADMIN_CREATION_SECRET_KEY=your_secret_key NEXT_PUBLIC_ADMIN_CREATION_KEY=your_secret_key
-
Set up Supabase Database
- Run the SQL schema from
supabase-schema-fixed.sqlin your Supabase SQL Editor - Enable Row Level Security on all tables
- Set up storage bucket for player photos (if using image uploads)
- Run the SQL schema from
-
Run the development server
npm run dev # or pnpm dev -
Open your browser Navigate to http://localhost:3000
-
Using the Admin Creation Utility (Development only)
- Navigate to
/create-admin - Enter admin credentials
- Use the secret key from environment variables
- Navigate to
-
Using SQL (Production recommended)
-- Insert admin user profile INSERT INTO user_profiles (id, email, name, role, status) VALUES ( 'user-uuid-from-auth', 'admin@example.com', 'Admin User', 'admin', 'approved' );
NEXT_PUBLIC_SUPABASE_URL- Your Supabase project URLNEXT_PUBLIC_SUPABASE_ANON_KEY- Supabase anonymous key
SUPABASE_SERVICE_ROLE_KEY- For server-side admin operationsADMIN_CREATION_SECRET_KEY- Secret key for admin creation utilityNEXT_PUBLIC_ADMIN_CREATION_KEY- Public key for admin creation (should match secret)
-
Push to GitHub
git add . git commit -m "Ready for deployment" git push origin main
-
Deploy on Vercel
- Import your GitHub repository
- Set environment variables in Vercel dashboard
- Deploy
-
Configure Supabase
- Add Vercel domain to Supabase allowed origins
- Verify RLS policies work in production
See DEPLOYMENT_GUIDE.md for detailed deployment instructions.
Set all environment variables in your hosting platform (Vercel, etc.):
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEY(if needed)ADMIN_CREATION_SECRET_KEY(if using admin utility)NODE_ENV=production
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLint
- TypeScript for type safety
- Functional React components with hooks
- Async/await for all async operations
- Semantic HTML and accessibility
- Tailwind CSS for styling
- shadcn/ui components for UI consistency
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code style
- Write TypeScript with proper types
- Use functional components and hooks
- Add error handling for all async operations
- Test your changes thoroughly
- Update documentation as needed
This project is licensed under the MIT License.
Shamim Ahmed
- Built with β€οΈ for tracking football team statistics
- Part of the SovWare Football Statistics system
- Built with Next.js
- Styled with Tailwind CSS
- Components from shadcn/ui
- Backend powered by Supabase
- Icons from Lucide
β½ Happy Tracking!