FastAPI-based RESTful API project for Secret Santa draw management.
- š User authentication and authorization
- š² Draw creation and management
- š„ Participant addition and removal
- š Automatic matching algorithm
- š§ Email notifications
- š Versioned API (v1)
- FastAPI 0.120.0 - Modern web framework
- Pydantic 2.12.3 - Data validation
- Python 3.13
- Uvicorn - ASGI server
- SQLAlchemy 2.0.36 - ORM
- PostgreSQL - Database
- Alembic 1.14.0 - Database migrations
# Clone the repository git clone <repository-url> cd santas_draw # Copy environment file cp .env.example .env # Start all services docker-compose up -d # That's it! Application is running at http://localhost:8000 # API Docs: http://localhost:8000/docs
A read-only panel at /admin shows draws, participants, match results and users.
It is switched off (every /admin URL answers 404) until both settings below are set
and SECRET_KEY has been changed from its default value.
# 1. Print the .env line for your password python -m scripts.hash_admin_password # 2. Add to .env (keep the single quotes around the hash) [email protected] ADMIN_PASSWORD_HASH='$2b$12$...'
- Locally over plain http also set
ADMIN_COOKIE_SECURE=false, otherwise the browser drops the session cookie. - In production the reverse proxy must forward
/admin(including/admin/static) to the app, not only/api. - The panel never writes to the database, and its session cannot be used against the user API.
- Docker & Docker Compose
No Python, PostgreSQL, or other dependencies needed!
# Start all services docker-compose up -d # Stop all services docker-compose down # View logs docker-compose logs -f # View application logs only docker-compose logs -f app # View database logs only docker-compose logs -f postgres # Rebuild and start docker-compose up -d --build # Stop and remove volumes docker-compose down -v
The application uses environment variables loaded from .env file. Key settings:
APP_NAME- Application nameAPP_VERSION- Application versionDEBUG- Debug mode (True/False)API_VERSION- API versionHOST- Server hostPORT- Server portCORS_ORIGINS- CORS allowed originsDATABASE_URL- PostgreSQL connection stringDATABASE_ECHO- Log SQL queries (True/False)DATABASE_POOL_SIZE- Connection pool sizeDATABASE_MAX_OVERFLOW- Max overflow connections
| When | Who | Template |
|---|---|---|
| Names are drawn | every participant | email-template-{tr,en}.html |
| Someone joins a draw | that participant | join-confirmation.html |
| An invite draw is created | the organizer | draw-created.html |
| 24 hours before a scheduled draw | the organizer | draw-reminder.html |
| A scheduled draw cannot run (fewer than 3 participants) | the organizer, once | draw-not-run.html |
| Password reset requested | the user | reset-password-template-{tr,en}.html |
All of them are sent from Celery tasks, so a mail problem never fails the request that caused it.
| When | Who |
|---|---|
| Names are drawn | participants |
| Someone joins | the organizer: right away for the first join, then at most one summary per hour |
| 24 hours before a scheduled draw | organizer and participants |
| A scheduled draw cannot run (fewer than 3 participants) | the organizer, once |
Campaign e-mails (for example the 2027 launch announcement) are sent with a script, never automatically:
python -m scripts.send_announcement # dry run: recipient counts only python -m scripts.send_announcement --to [email protected] # one test e-mail python -m scripts.send_announcement --apply # send to every registered user
Every e-mail carries a personal unsubscribe link (/api/v1/email/unsubscribe) and one-click
List-Unsubscribe headers. Unsubscribed addresses are skipped, and sent addresses are recorded so the
script can be re-run safely. API_URL must be the public URL of the API in production.
After running the application:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
app/
āāā main.py # Main application
āāā models/ # Database models
āāā schemas/ # Pydantic schemas
āāā api/
ā āāā deps.py # Dependency injection
ā āāā v1/ # API endpoints
āāā config/ # Configuration
āāā tasks/ # Background tasks
AGPL v3 - See LICENSE file for details.