A FastAPI-based backend application for tracking FIFA match results and player statistics with JWT authentication.
- JWT Authentication: Secure token-based authentication for all API endpoints
- Player Management: Register, view, update, and delete players
- Match Tracking: Record and manage match results
- Tournament Support: Create and manage tournaments
- Statistics: Comprehensive player and tournament statistics
- MongoDB Integration: NoSQL database for flexible data storage
- Docker Support: Easy deployment with Docker containers
- Python 3.12+
- MongoDB (local or MongoDB Atlas)
- Docker (optional)
- uv (recommended) or pip
git clone <repository-url>
cd fifa-rivalry-trackerUsing uv (recommended):
uv syncOr using pip:
pip install -r requirements.txtCreate a .env file in the root directory:
# Environment
ENVIRONMENT=development
# Database
MONGO_URI=your-mongodb-connection-string
# JWT Authentication
SECRET_KEY=your-super-secret-key-change-this-in-production
ACCESS_TOKEN_EXPIRE_MINUTES=43200
# Logging (optional)
LOG_LEVEL=INFO
LOG_FILE=logs/app.logFor detailed configuration options, see CONFIGURATION.md.
Run the user creation script to set up default users:
# Using uv
uv run python create_admin_user.py
# Or using pip
python create_admin_user.pyThis creates:
- Admin User:
admin/admin123(superuser) - Test User:
testuser/test123(regular user)
Using uv:
uv run uvicorn main:app --reload --host 0.0.0.0 --port 8000Or using pip:
uvicorn main:app --reload --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000
- Interactive Docs:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc - Authentication Guide: See AUTHENTICATION.md
sudo docker compose -f ./docker-compose-rpi.yaml up -dsudo docker compose -f ./docker-compose-standard.yaml up -dsudo docker compose -f ./docker-compose.yml up -dPOST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- Login with form dataPOST /api/v1/auth/login-json- Login with JSONGET /api/v1/auth/me- Get current user infoPOST /api/v1/auth/refresh- Refresh access token
GET /api/v1/players- Get all playersPOST /api/v1/players- Register new playerGET /api/v1/players/{id}- Get specific playerPUT /api/v1/players/{id}- Update playerDELETE /api/v1/players/{id}- Delete playerGET /api/v1/players/{id}/stats- Get player statisticsGET /api/v1/players/{id}/matches- Get player matches
GET /api/v1/matches- Get all matchesPOST /api/v1/matches- Record new matchPUT /api/v1/matches/{id}- Update matchDELETE /api/v1/matches/{id}- Delete match
GET /api/v1/tournaments- Get all tournamentsPOST /api/v1/tournaments- Create new tournamentGET /api/v1/tournaments/{id}- Get specific tournamentGET /api/v1/tournaments/{id}/matches- Get tournament matchesGET /api/v1/tournaments/{id}/stats- Get tournament statisticsPOST /api/v1/tournaments/{id}/players- Add player to tournamentDELETE /api/v1/tournaments/{id}/players/{player_id}- Remove player from tournament
GET /api/v1/stats- Get player leaderboard
All protected endpoints require a JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>- Register a user:
curl -X POST "http://localhost:8000/api/v1/auth/register" \
-H "Content-Type: application/json" \
-d '{"username": "john", "email": "[email protected]", "password": "password123"}'- Login to get token:
curl -X POST "http://localhost:8000/api/v1/auth/login-json" \
-H "Content-Type: application/json" \
-d '{"username": "john", "password": "password123"}'- Use token to access protected endpoints:
curl -X GET "http://localhost:8000/api/v1/players" \
-H "Authorization: Bearer <your-token>"Run the test suite:
Using uv:
uv run pytestOr using pip:
pytestThe application uses centralized logging configuration. You can control log levels and output through environment variables:
# Debug logging to console
LOG_LEVEL=DEBUG uvicorn main:app --reload
# Info logging to file
LOG_LEVEL=INFO LOG_FILE=logs/app.log uvicorn main:app --reloadFor detailed logging configuration, see CONFIGURATION.md.
# Install dependencies
uv sync
# Run the application
uv run uvicorn main:app --reload --host 0.0.0.0 --port 8000
# Run tests
uv run pytest
# Run user creation script
uv run python create_admin_user.py
# Add new dependencies
uv add package-name
# Add development dependencies
uv add --dev package-name# Install dependencies
pip install -r requirements.txt
# Run the application
uvicorn main:app --reload --host 0.0.0.0 --port 8000
# Run tests
pytest
# Run user creation script
python create_admin_user.pyfifa-rivalry-tracker/
├── app/
│ ├── api/
│ │ ├── v1/
│ │ │ ├── endpoints/
│ │ │ │ ├── auth.py # Authentication endpoints
│ │ │ │ ├── players.py # Player management
│ │ │ │ ├── matches.py # Match management
│ │ │ │ ├── tournaments.py # Tournament management
│ │ │ │ └── stats.py # Statistics
│ │ │ └── router.py # API router
│ │ └── dependencies.py # Database dependencies
│ ├── models/
│ │ ├── auth.py # Authentication models
│ │ ├── player.py # Player models
│ │ ├── match.py # Match models
│ │ └── tournament.py # Tournament models
│ ├── utils/
│ │ ├── auth.py # Authentication utilities
│ │ └── helpers.py # Helper functions
│ └── main.py # FastAPI application
├── create_admin_user.py # User creation script
├── AUTHENTICATION.md # Authentication documentation
├── pyproject.toml # Project configuration (uv)
├── uv.lock # Lock file (uv)
├── requirements.txt # Python dependencies (pip)
└── docker-compose*.yaml # Docker configurations
- Change the default
SECRET_KEYin production - Use strong passwords for admin accounts
- Configure CORS properly for your frontend domain
- Implement rate limiting for production deployments
- Use HTTPS in production
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License.