Skip to content

About

Quick Recipe is an AI-powered recipe discovery platform that helps users explore recipes, find meal inspiration, and discover dishes based on their preferences. Built with a modern web interface and a Python FastAPI backend, it features recipe recommendations, user authentication, and recipe management.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

Repository files navigation

Quick Recipe 🍲

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.

Features

  • 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.

Tech stack

Python 3.11+, FastAPI, Pydantic Settings, SQLAlchemy 2, Alembic, MySQL 8, SQLite, Argon2, JWT, Pillow, pytest, Docker.

Quick start (SQLite)

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 --reload

Open 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.

Docker Compose (MySQL)

  1. Copy .env.example to .env and set a unique SECRET_KEY plus strong MySQL passwords. The compose file also accepts MYSQL_PASSWORD, MYSQL_ROOT_PASSWORD, MYSQL_USER, and MYSQL_DATABASE from .env.
  2. Start services:
docker compose up --build -d
docker compose logs -f api

The 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.

Environment variables

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 URL format

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.

First administrator and chef access

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_admin

The 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.

API overview

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.

Example: create a recipe

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"
  }'

Example: ingredient recommendations

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.

Database migrations

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 -1

Never 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.

Tests and code quality

pip install -e ".[dev]"
ruff check .
pytest

Tests cover registration role escalation, authentication, CRUD, ownership, validation, readiness, duplicate registration, and AI recommendations. CI runs lint and tests on pushes and pull requests.

Security notes

  • 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.

Project structure

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

License

Released under the MIT License. See LICENSE.

Deploy the complete website and API

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.

Deploy with Render Blueprint

  1. Push this repository to GitHub. Confirm .env, database files, passwords, and tokens are not committed.
  2. In Render, choose New β†’ Blueprint, connect your GitHub repository, and select this repository. Render reads render.yaml.
  3. Review the service and disk costs before approving. The blueprint generates a SECRET_KEY and stores SQLite data and uploaded images on /var/data.
  4. Wait for the build and deploy to complete. Open the service URL; / should show the website, /docs the API documentation, and /health/ready should return ready.
  5. In the service shell or a one-off command environment, create your first administrator with python -m scripts.create_admin, then seed starter recipes with python -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.

Can GitHub Pages host it?

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.

About

Quick Recipe is an AI-powered recipe discovery platform that helps users explore recipes, find meal inspiration, and discover dishes based on their preferences. Built with a modern web interface and a Python FastAPI backend, it features recipe recommendations, user authentication, and recipe management.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages