FairPlay is a full-stack Django web application that enables users to build and manage balanced football teams with their friends. Each user can register, create their own player roster by adding registered users, and generate fair teams using a sophisticated Snake Draft Algorithm. With user authentication and data isolation, every user has their own personalized team management experience.
- User registration with username, email, password, and preferred position
- Secure login/logout functionality
- User profile creation with preferred playing position
- Password validation and email uniqueness checks
- Session management and authentication state tracking
- Login-required protection for player/team management
- Search and add registered users as players to your roster
- Each user manages their own private player list
- View player's username, position, and skill rating
- Override user's preferred position when adding them
- Edit player ratings and positions (only your own players)
- Delete players from your roster
- Data isolation - users only see their own players
- Automatic profile creation on registration
- Preferred position selection (Striker/Defender/Midfielder/Goalkeeper)
- Profile linked to user account via signal
- Default position used when adding user as player
- Add players by searching registered usernames
- View all your players in an organized table
- Edit player details (position, rating) - only your own
- Delete players from your roster
- Skill rating system (50-100 scale)
- Bootstrap-styled responsive UI with dark theme
- Snake Draft Algorithm for balanced team distribution
- Players sorted by rating (highest to lowest) before distribution
- Alternating pick order ensures fair team composition
- Support for 2-10 teams per user
- Automatic team rating calculations
- User-specific teams - only uses your players
- Teams owned by individual users (private)
- Beautiful card-based team display with dark theme
- Individual player cards showing position and rating
- Team statistics: total rating and average rating per team
- Balance summary table comparing all teams
- Responsive design for all screen sizes
- Modern landing page with authentication options
- User-aware navigation (login status displayed)
- Welcome messages with username
- Intuitive navigation throughout the app
- Success/error message notifications
- Dark theme with consistent styling
- Mobile-responsive Bootstrap 5 design
- Separate login and registration pages
- Login required for all player/team operations
- Users can only view/edit/delete their own data
- Reset function only deletes current user's players
- Team generation uses only user's own players
- Ownership validation on all CRUD operations
- Protection against unauthorized access
- Custom admin panels for Player, Team, Match, and UserProfile models
- Enhanced admin views with user filtering
- Easy data management for testing and debugging
- Register: Create account with username, email, password, and preferred position
- Login: Access your personal dashboard
- Add Players: Search for other registered users and add them to your roster
- Set Ratings: Assign skill ratings (50-100) to each player
- Generate Teams: Create balanced teams from your player roster
- View Teams: See team compositions with statistics
- Manage: Edit ratings, remove players, or reset your roster
- User: Registered account holder who manages their own players/teams
- Player: A registered user added to someone's roster with a rating
- Owner: The user who added a player to their roster
- Preferred Position: Default position set during registration
- Position Override: Ability to assign different position when adding player
The heart of FairPlay is its intelligent team balancing algorithm:
- Sort Players: All players are sorted by rating (descending) and then by position
- Snake Pattern Distribution: Players are distributed in a snake/zigzag pattern:
- Round 1: Team A โ Team B โ Team C (forward)
- Round 2: Team C โ Team B โ Team A (backward)
- Round 3: Team A โ Team B โ Team C (forward)
- And so on...
- Result: Ensures the highest-rated players are evenly distributed across teams
If you have 9 players with ratings [5, 5, 4, 4, 3, 3, 2, 2, 1] for 3 teams:
- Team A: Players rated [5, 4, 2] = Total: 11
- Team B: Players rated [5, 3, 2] = Total: 10
- Team C: Players rated [4, 3, 1] = Total: 8
This creates much more balanced teams than random assignment!
- Backend: Django 4.2.11
- Frontend: HTML5, CSS3, Bootstrap 5.1.3, JavaScript
- Database: SQLite (development)
- Python Version: 3.9+
- CI/CD: GitHub Actions
fairplay/
โโโ .github/
โ โโโ workflows/
โ โโโ django.yml # CI/CD pipeline
โโโ fairplay/ # Django project root
โ โโโ fair_play/ # Main app
โ โ โโโ models.py # Player, Team, Match, UserProfile models
โ โ โโโ forms.py # PlayerSearchForm, CustomUserCreationForm, TeamForm
โ โ โโโ views.py # All views including auth and team generation
โ โ โโโ urls.py # App URL configurations
โ โ โโโ admin.py # Custom admin configurations
โ โ โโโ migrations/ # Database migrations
โ โ โโโ templates/ # HTML templates
โ โ โโโ index.html # Landing page
โ โ โโโ navbar.html # Reusable navbar component
โ โ โโโ registration/ # Authentication templates
โ โ โ โโโ register.html # User registration
โ โ โ โโโ login.html # User login
โ โ โโโ playeradd.html # Add player by username
โ โ โโโ playerslist.html # List user's players
โ โ โโโ playerupdate.html # Edit player
โ โ โโโ playerdelete.html # Delete confirmation
โ โ โโโ reset_confirm.html # Reset confirmation
โ โ โโโ team_form.html # Team generation form
โ โ โโโ teams_display.html # Display generated teams
โ โโโ fairplay/ # Project settings
โ โ โโโ settings.py
โ โ โโโ urls.py
โ โ โโโ wsgi.py
โ โโโ manage.py
โ โโโ db.sqlite3
โโโ requirements.txt # Python dependencies
โโโ README.md
username: Unique usernameemail: User's email addresspassword: Hashed password
user: OneToOneField to Userpreferred_position: CharField - Default playing positionbio: TextField - Optional user biography
user: ForeignKey to User - The registered user being added as playerowner: ForeignKey to User - The user who added this playerposition: CharField with choices (Striker, Defender, Midfielder, Goalkeeper)rating: IntegerField (50-100) - Skill level assigned by ownerteam: ForeignKey to Team (nullable) - Assigned during team generation
name: CharField - Team namecreated_at: DateTimeField - Auto-generated timestampowner: ForeignKey to User - User who created the team
date_created: DateTimeField - Match creation timeteam_A: ForeignKey to Teamteam_B: ForeignKey to Team
| URL | View | Description | Auth Required |
|---|---|---|---|
/ |
index | Landing page (redirects to players if authenticated) | No |
/register/ |
register_view | User registration | No |
/login/ |
login_view | User login | No |
/logout/ |
logout_view | User logout | Yes |
/player/add/ |
add_player_view | Add player by username search | Yes |
/players/ |
PlayerListView | View your players (filtered by owner) | Yes |
/player/<id>/update/ |
UpdatePlayerView | Edit player details (position, rating) | Yes |
/player/<id>/delete/ |
DeletePlayerView | Delete player from your roster | Yes |
/reset/ |
reset_players | Reset your players only | Yes |
/teams/generate/ |
team_form_view | Team generation form | Yes |
/teams/create/ |
generate_teams_view | Process team generation | Yes |
/teams/ |
teams_display_view | Display your generated teams | Yes |
/admin/ |
Django Admin | Admin panel | Superuser |
- Python 3.9 or higher
- pip (Python package manager)
- Git
-
Clone the repository
git clone https://github.com/Stembetevo/fairplay.git cd fairplay -
Install dependencies
pip install -r requirements.txt
-
Navigate to project directory
cd fairplay -
Run migrations
python manage.py migrate
-
Create a superuser (optional, for admin access)
python manage.py createsuperuser
-
Start the development server
python manage.py runserver
-
Visit the application
- Main app:
http://127.0.0.1:8000/ - Admin panel:
http://127.0.0.1:8000/admin/
- Main app:
-
Register Account:
- Navigate to the homepage
- Click "Create Account" or "Register"
- Fill in username, email, password, and preferred position
- Click "Create Account"
-
Add Friends as Players:
- Ask friends to register on the platform
- Once logged in, go to "Add Player"
- Search for friend's username
- Optionally override their preferred position
- Set their skill rating (50-100)
- Click "Add Player"
-
Build Your Roster:
- Continue adding registered users as players
- View all your players in "My Players"
- Edit ratings or positions as needed
-
Generate Teams:
- Once you have at least 2 players, click "Generate Teams"
- Enter number of teams (2-10)
- Provide team names
- Click "Generate Teams"
-
View Results:
- See balanced teams with statistics
- View player assignments and team ratings
- Generate new teams anytime with different configurations
- Edit Players: Click "Edit" on any player in your list to update rating/position
- Remove Players: Click "Remove" to delete a player from your roster
- Reset: Use "Reset All" to clear all your players and start fresh
- Logout: Click "Logout" in the navbar when done
- Public player profiles with statistics
- Friend system and invitations
- Team sharing between users
- Match history and statistics tracking
- Export teams to PDF
- Share team compositions via link
- Player performance tracking over time
- Advanced filtering (by position, rating, availability)
- Team comparison analytics across users
- Match scheduling system
- Email notifications for team assignments
- Player availability toggle for each match
- Social features (comments, likes on teams)
- Leaderboards and rankings
- Mobile app version
Run tests with:
cd fairplay
python manage.py testCI/CD pipeline runs automatically on push to main branch via GitHub Actions.
Current Phase: Multi-User System Complete โ
Status: Production Ready ๐
Version: 2.0.0
- โ Complete user authentication system
- โ User registration with preferred position
- โ Multi-user support with data isolation
- โ Username-based player search
- โ User profile system
- โ Ownership-based access control
- โ Updated UI with authentication state
- โ Secure login/logout functionality
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
This project is open source and available for educational purposes.
Stephen Kinyua
- GitHub: @Stembetevo
โฝ Built with Django | Balanced with Logic | Powered by Fair Play | Secured for Users