A complete, responsive recipe discovery website and REST API built with HTML/CSS/JavaScript, FastAPI, SQLAlchemy 2, Alembic, JWT authentication, Docker, and a local TF-IDF content-based recommendation engine.
Quick Recipe is designed as a secure modular monolith. It is a strong portfolio/deployment baseline, not a claim of third-party security certification or a guarantee that every hosting environment is configured safely.
- Polished responsive frontend with recipe browsing, search, category filters, recipe detail views, registration/login, and an ingredient-powered AI sous-chef.
- The FastAPI backend serves the frontend at
/, static assets at/assets/, API docs at/docs, and the versioned API under/api/v1. - User registration and JWT login with Argon2 password hashing.
- Public recipe browsing, search, filtering, pagination, and detail endpoints.
- Chef-only recipe creation and edits; ownership enforced for updates, deletes, and uploads.
- Role assignment restricted to administrators; registration always creates a regular user.
- Recipe categories, cuisine, servings, dietary tags, prep time, and image URL.
- Validated JPEG/PNG/WebP image uploads with content verification, random server-side names, and a configurable size cap.
- AI/ML-style ingredient-to-recipe recommendations using local TF-IDF cosine similarity and ingredient overlap. No external API key or data transfer is required.
- SQLAlchemy 2 data models and real Alembic migrations; application startup never auto-creates tables.
- Health/readiness endpoints, structured logs, security headers, restricted CORS, Docker Compose, tests, and GitHub Actions CI.
- SQLite for quick local setup; MySQL 8 for Docker and production-like development.
Python 3.11+, FastAPI, Pydantic Settings, SQLAlchemy 2, Alembic, MySQL 8, SQLite, Argon2, JWT, Pillow, pytest, Docker.
git clone https://github.com/YOUR_USERNAME/quick-recipe.git
cd quick-recipe
python -m venv .venv
# macOS/Linux
source .venv/bin/activate
# Windows PowerShell: .venv\Scripts\Activate.ps1
pip install -e ".[dev]"
cp .env.example .env
alembic upgrade head
uvicorn quick_recipe.main:app --reloadOpen the website at http://127.0.0.1:8000/. The API docs are at http://127.0.0.1:8000/docs; liveness is /health/live, and readiness (including database connectivity) is /health/ready.
For a first-run experience with starter recipes, create an administrator after migrations (python -m scripts.create_admin), then run python -m scripts.seed_demo. This adds sample recipes owned by the admin account so browsing and AI recommendations have data to work with. The seed script is safe to rerun.
Windows note: use copy .env.example .env in Command Prompt if cp is unavailable.
- Copy
.env.exampleto.envand set a uniqueSECRET_KEYplus strong MySQL passwords. The compose file also acceptsMYSQL_PASSWORD,MYSQL_ROOT_PASSWORD,MYSQL_USER, andMYSQL_DATABASEfrom.env. - Start services:
docker compose up --build -d
docker compose logs -f apiThe container applies Alembic migrations before starting the API. For real production deployments, run migrations as a controlled release step rather than allowing multiple replicas to race migrations.
| Variable | Purpose | Default |
|---|---|---|
APP_ENV |
development or production |
development |
APP_NAME |
API title | Quick Recipe API |
API_V1_PREFIX |
Versioned route prefix | /api/v1 |
DATABASE_URL |
SQLAlchemy URL | local SQLite |
SECRET_KEY |
JWT signing secret | development-only value; replace it |
ACCESS_TOKEN_EXPIRE_MINUTES |
JWT lifetime, 1β1440 | 30 |
CORS_ORIGINS |
Comma-separated allowed origins | localhost frontend origins |
UPLOAD_DIR |
Image storage directory | uploads |
MAX_UPLOAD_BYTES |
Upload cap (1 KiBβ25 MiB) | 5242880 |
For production, set APP_ENV=production, use a unique random secret of at least 32 characters, specify exact CORS origins, use managed database credentials, terminate TLS at a trusted proxy/load balancer, and configure backups and monitoring. Do not commit .env.
mysql+pymysql://USERNAME:PASSWORD@HOST:3306/DATABASE
URL-encode reserved characters in credentials. The Compose configuration creates a MySQL database and persistent volumes for database data and uploaded images.
Public registration always creates a user. It cannot accept a role field to grant privileges. To create the first administrator, run after migrations:
python -m scripts.create_adminThe script prompts for credentials without echoing the password. Sign in through /api/v1/auth/token. An administrator can grant or revoke chef access using PATCH /api/v1/auth/users/{user_id}/role with {"role":"chef"} or {"role":"user"}. The admin endpoint does not permit creating another administrator through this route.
All application endpoints are prefixed with /api/v1.
| Method | Endpoint | Access | Description |
|---|---|---|---|
POST |
/auth/register |
Public | Register ordinary user |
POST |
/auth/token |
Public | OAuth2 form login; returns JWT |
GET |
/auth/users/me |
Authenticated | Current profile |
PATCH |
/auth/users/{id}/role |
Admin | Assign user or chef role |
GET |
/recipes |
Public | Search, filters, pagination |
GET |
/recipes/{id} |
Public | Recipe details |
POST |
/recipes |
Chef/admin | Create recipe |
PUT |
/recipes/{id} |
Owner chef/admin | Replace recipe |
PATCH |
/recipes/{id} |
Owner chef/admin | Partially update recipe |
DELETE |
/recipes/{id} |
Owner chef/admin | Delete recipe |
POST |
/recipes/{id}/image |
Owner chef/admin | Upload verified image |
GET |
/ai/recommendations?ingredients=tomato,garlic |
Public | Rank stored recipes by ingredient/text similarity |
GET |
/health/live |
Public | Liveness check |
GET |
/health/ready |
Public | Database readiness check |
Interactive OpenAPI documentation is at /docs; ReDoc is at /redoc.
After a user has been granted the chef role, obtain a token and send it as a bearer token:
curl -X POST http://127.0.0.1:8000/api/v1/recipes \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"title": "Tomato Chickpea Curry",
"ingredients": "tomato, chickpeas, onion, garlic, cumin",
"instructions": "Cook onion and garlic, add tomato and chickpeas, then simmer.",
"prep_time_minutes": 30,
"servings": 3,
"category": "Dinner",
"cuisine": "Indian",
"dietary_tags": "vegan"
}'curl 'http://127.0.0.1:8000/api/v1/ai/recommendations?ingredients=tomato,chickpeas,garlic&limit=5'The recommender computes local TF-IDF cosine similarity over title, ingredients, instructions, category, cuisine, and tags, then blends that with explicit ingredient overlap. It only recommends recipes already stored in the database. Scores are ranking signals, not calibrated probabilities. For larger catalogs, replace in-process ranking with a measured search/vector service and add evaluation datasets before claiming recommendation quality.
Schema changes are managed only through Alembic:
alembic upgrade head
alembic revision --autogenerate -m "describe change"
# Review generated migration carefully, then apply it.
alembic downgrade -1Never edit a migration that has already been applied to shared environments. Back up production data before migrations and test upgrades/downgrades on a disposable database first.
pip install -e ".[dev]"
ruff check .
pytestTests cover registration role escalation, authentication, CRUD, ownership, validation, readiness, duplicate registration, and AI recommendations. CI runs lint and tests on pushes and pull requests.
- Use HTTPS in production and keep secrets outside source control.
- JWT is bearer-token authentication; this baseline does not implement refresh tokens or server-side token revocation.
- Add distributed rate limiting (for example, Redis-backed) at the gateway before exposing login/register publicly at meaningful scale.
- Local uploads use a persistent volume. For multi-replica deployments, use private object storage and a CDN with safe content delivery rules.
- Review dependency updates and run automated dependency/container scanning before production releases.
- Configure database backups, retention, observability, and incident response appropriate to your deployment.
quick-recipe/
βββ frontend/ # Responsive public website (served by FastAPI)
β βββ index.html
β βββ assets/ # CSS and browser JavaScript
βββ quick_recipe/
β βββ routers/ # API routes
β βββ ai.py # Local TF-IDF recommender
β βββ config.py # Validated settings
β βββ database.py # SQLAlchemy engine/session
β βββ dependencies.py# Authentication and role dependencies
β βββ models.py # ORM models
β βββ schemas.py # Request/response validation
β βββ main.py # App factory/lifespan, middleware, health
βββ alembic/ # Versioned database migrations
βββ scripts/ # Administrative utilities
βββ tests/ # Automated tests
βββ .github/workflows/ # CI pipeline
βββ Dockerfile
βββ docker-compose.yml
βββ pyproject.toml
βββ .env.example
βββ .gitignore
βββ LICENSE
βββ README.md
Released under the MIT License. See LICENSE.
The frontend and backend are served from the same origin, so one deployment gives you the public homepage (/), API (/api/v1/...), OpenAPI docs (/docs), and health check (/health/ready). The render.yaml file provides a Render Blueprint for a single Docker web service with a persistent disk. This uses SQLite on that disk and is appropriate for a small single-instance portfolio demo; the configured Render Starter service and persistent disk are paid resources. Free hosting plans may sleep, impose limits, or lack persistent disks, so they are not a guarantee of 24/7 uptime.
- Push this repository to GitHub. Confirm
.env, database files, passwords, and tokens are not committed. - In Render, choose New β Blueprint, connect your GitHub repository, and select this repository. Render reads
render.yaml. - Review the service and disk costs before approving. The blueprint generates a
SECRET_KEYand stores SQLite data and uploaded images on/var/data. - Wait for the build and deploy to complete. Open the service URL;
/should show the website,/docsthe API documentation, and/health/readyshould return ready. - In the service shell or a one-off command environment, create your first administrator with
python -m scripts.create_admin, then seed starter recipes withpython -m scripts.seed_demo. If your selected host does not provide a shell, run those commands locally with the same production database connection securely configured, or use a one-off job. Never paste secrets into public logs or GitHub.
For a growing app or multiple instances, use a managed MySQL database and private object storage for uploads instead of a shared SQLite file. The docker-compose.yml demonstrates the MySQL setup for local Docker use.
GitHub Pages hosts static files; it cannot run this Python/FastAPI backend, database migrations, or the recommendation endpoint. You can host a frontend-only static site on GitHub Pages if it is configured to call a separately hosted backend and that backend allows the Pages origin in CORS. This repository's default frontend uses same-origin relative API paths, so the easiest setup is to deploy the whole project together as described above.