Putnam Area Robotics Team Web API - A Django REST Framework application for managing team operations.
📚 Complete Documentation Index
- Poetry Setup Guide - Comprehensive guide to using Poetry for dependency management
- Contributing Guidelines - How to contribute to this project
- Django Best Practices - Coding standards and patterns
- Testing Guide - Testing strategy and coverage roadmap
- Test Organization - How tests are organized
- Reorganization Summary - Project structure changes
- Refactoring Summary - Code quality improvements
The project follows Django best practices with a src/ layout:
PARTs_WebAPI/
├── src/
│ ├── parts_webapi/ # Django project package
│ │ ├── settings/ # Split settings
│ │ │ ├── base.py # Common settings
│ │ │ ├── development.py # Development settings
│ │ │ ├── production.py # Production settings
│ │ │ └── test.py # Test settings
│ │ ├── urls.py # URL configuration
│ │ ├── wsgi.py # WSGI entry point
│ │ └── asgi.py # ASGI entry point
│ ├── manage.py # Django management script
│ ├── admin/ # Admin app
│ ├── alerts/ # Alerts app
│ ├── attendance/ # Attendance app
│ ├── form/ # Form app
│ ├── general/ # General utilities
│ ├── public/ # Public API app
│ ├── scouting/ # Scouting app
│ ├── sponsoring/ # Sponsoring app
│ ├── tba/ # The Blue Alliance integration
│ └── user/ # User management app
├── tests/ # Test suite
├── docs/ # Documentation
│ ├── README.md # Documentation index
│ ├── POETRY.md # Poetry setup guide
│ ├── REORGANIZATION_SUMMARY.md
│ └── REFACTORING_SUMMARY.md
├── templates/ # Django templates
├── .env.example # Environment variables template
├── requirements.txt # Python dependencies
├── pyproject.toml # Poetry configuration
└── README.md # This file
- Python 3.11 or higher
- Poetry (Python package manager) - See Poetry Setup Guide for detailed installation and usage
- Clone the repository:
git clone https://github.com/3492PARTs/PARTs_WebAPI.git
cd PARTs_WebAPI- Install dependencies using Poetry:
poetry install --with dev📖 New to Poetry? Check out our comprehensive Poetry Setup Guide for:
- Installing Poetry
- Understanding dependency groups (dev, wvnet, uat)
- Common commands and workflows
- Troubleshooting tips
- Set up environment variables:
Copy the example environment file:
cp .env.example .envEdit .env and set your values for:
SECRET_KEY- Generate a random string for DjangoDEBUG- Set toTruefor development,Falsefor productionDB_ENGINE,DB_NAME,DB_USER,DB_PASSWORD,DB_HOST,DB_PORT- Database configurationCLOUDINARY_URL- Cloudinary configuration for media storageTBA_KEY- The Blue Alliance API key- Other optional settings as needed
Important: Never commit the .env file to version control!
- Set the Django settings module (for development):
export DJANGO_SETTINGS_MODULE=parts_webapi.settings.developmentOr for production:
export DJANGO_SETTINGS_MODULE=parts_webapi.settings.productionNote: The default is parts_webapi.settings.development if not set.
- Run migrations:
cd src
python manage.py migrate- Create a superuser (optional):
python manage.py createsuperuser- Start the development server:
python manage.py runserverThe API will be available at http://127.0.0.1:8000/
The project uses split settings for different environments:
-
Development:
parts_webapi.settings.development- DEBUG=True
- Uses local database (SQLite by default)
- Console email backend
- Allows localhost CORS
-
Production:
parts_webapi.settings.production- DEBUG=False
- Enhanced security settings
- Production-ready CORS and ALLOWED_HOSTS
- Uses production database
-
Testing:
parts_webapi.settings.test- Used by pytest
- In-memory database
- Simplified authentication
export DJANGO_SETTINGS_MODULE=parts_webapi.settings.development
cd src
python manage.py runservercd src
python manage.py runserver --settings=parts_webapi.settings.developmentSet DJANGO_SETTINGS_MODULE in your .env file:
DJANGO_SETTINGS_MODULE=parts_webapi.settings.development
Run all tests with coverage:
poetry run pytestRun tests without coverage (faster for development):
poetry run pytest --no-covRun specific test file:
poetry run pytest tests/general/test_general_security.pyRun all tests for a specific app:
poetry run pytest tests/user/Run tests with verbose output:
poetry run pytest -vView coverage in terminal:
poetry run pytest --cov=src --cov-report=term-missingGenerate HTML coverage report:
poetry run pytest --cov=src --cov-report=html
# Open htmlcov/index.html in your browserThis project maintains high test coverage. All pull requests should maintain or improve test coverage:
- The CI pipeline will fail if coverage drops significantly
- Add tests for any new code you write
- Update tests when modifying existing code
Tests are organized in the tests/ directory. Test files should:
- Be named
test_*.py - Use pytest fixtures from
tests/conftest.py - Mock external dependencies (Cloudinary, email, Discord, etc.)
- Test both success and error cases
Example test:
import pytest
from unittest.mock import patch
@pytest.mark.django_db
def test_my_view(api_client, test_user):
api_client.force_authenticate(user=test_user)
response = api_client.get('/api/endpoint/')
assert response.status_code == 200From the repository root:
cd src
python manage.py makemigrations
python manage.py migrateAll Django management commands should be run from the src/ directory:
cd src
# Create migrations
python manage.py makemigrations
# Apply migrations
python manage.py migrate
# Create superuser
python manage.py createsuperuser
# Run development server
python manage.py runserver
# Start Django shell
python manage.py shell
# Collect static files (for production)
python manage.py collectstaticWe welcome contributions! Please see CONTRIBUTING.md for detailed guidelines.
Quick Start:
- Create a new branch for your feature
- Write tests for new functionality
- Ensure all tests pass:
poetry run pytest - Follow the Django Best Practices
- Submit a pull request
Key Guidelines:
- Use explicit imports (no
from module import *) - Add
app_nameto allurls.pyfiles - Name all URL patterns
- Write tests for all new code
- Add docstrings to public functions
See DJANGO_BEST_PRACTICES.md for comprehensive coding standards.
The project uses GitHub Actions for continuous integration:
- Tests run on Python 3.11 and 3.12
- Coverage reports are generated and uploaded to Codecov
- Linting can be added as needed
The CI workflow is defined in .github/workflows/ci.yml
Set these environment variables in your production environment:
DJANGO_SETTINGS_MODULE=parts_webapi.settings.production
SECRET_KEY=<your-secure-secret-key>
DEBUG=False
ENVIRONMENT=main # or 'uat' for staging
DB_ENGINE=django.db.backends.postgresql
DB_NAME=<database-name>
DB_USER=<database-user>
DB_PASSWORD=<database-password>
DB_HOST=<database-host>
DB_PORT=5432For production deployment with Gunicorn:
cd src
gunicorn parts_webapi.wsgi:application --bind 0.0.0.0:8000For ASGI (async) with Uvicorn:
cd src
uvicorn parts_webapi.asgi:application --host 0.0.0.0 --port 8000[Add your license information here]
Team 3492 - team3492@gmail.com
After pulling this branch, follow these steps to test the new structure:
-
Install dependencies:
poetry install --with dev
-
Set up environment:
cp .env.example .env # Edit .env with your SECRET_KEY and other settings -
Run migrations:
cd src python manage.py migrate -
Run tests:
cd .. # back to root poetry run pytest
-
Start dev server:
cd src python manage.py runserver -
Verify the API is accessible at http://127.0.0.1:8000/
All existing functionality should work exactly as before, just with a better organized project structure.