Skip to content

feat(api): add per-user rate limiter on scan endpoints#83

Merged
jpdevhub merged 3 commits into
jpdevhub:mainfrom
Tirthpanchori:feat/rate-limiter
Jun 7, 2026
Merged

feat(api): add per-user rate limiter on scan endpoints#83
jpdevhub merged 3 commits into
jpdevhub:mainfrom
Tirthpanchori:feat/rate-limiter

Conversation

@Tirthpanchori
Copy link
Copy Markdown
Contributor

Description

Implements per-user rate limiting on the FreshScan AI backend to prevent abuse of the Hugging Face Space inference endpoint and Supabase resources.

What this PR does:

  • Adds slowapi==0.1.9 middleware for request rate limiting
  • Creates backend/rate_limiter.py with a get_user_id key function that keys limits by authenticated Supabase user ID, falling back to client IP for unauthenticated requests
  • Applies a global default limit of 100 requests/hour across all endpoints
  • Applies a stricter limit of 20 requests/minute on /api/v1/scan and /api/v1/scan-auto (the heavy ML inference endpoints)
  • Returns clean JSON 429 Too Many Requests responses with retry_after field
  • Adds a /api/v1/health endpoint for lightweight status checks
  • Adds 5 tests in backend/tests/test_rate_limiter.py covering 429 behavior and response shape

Closes #4

Checklist

  • npm run lint passes with no errors
  • npm run build compiles without TypeScript errors
  • python -m pytest passes (including new tests I added)
  • No .env files, API keys, secrets, model weights, or __pycache__ in this diff
  • Branch is rebased on main, not merged

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 6, 2026

@Tirthpanchori is attempting to deploy a commit to the karan3431's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🎉 Thank you for your Pull Request! We're thrilled to have your contribution to FreshScan AI.

Before we review, please make sure you have:

  • Followed the CONTRIBUTING.md guidelines.
  • Ensured all automated CI checks (linting, tests) are passing.
  • Checked that your commit messages follow the Conventional Commits format.

A maintainer will review your code as soon as possible!

@jpdevhub
Copy link
Copy Markdown
Owner

jpdevhub commented Jun 6, 2026

backend test is failing fix that.

@Tirthpanchori
Copy link
Copy Markdown
Contributor Author

backend test is failing fix that.

Fixed - added slowapi to requirements-base.txt and requirements-ci.txt so it's available in the CI environment. Latest commit 7a41d6e should resolve the ModuleNotFoundError.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fresh-scan-ai Ready Ready Preview, Comment Jun 7, 2026 4:17pm

Copy link
Copy Markdown
Owner

@jpdevhub jpdevhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing

@jpdevhub jpdevhub merged commit 839b0f5 into jpdevhub:main Jun 7, 2026
8 checks passed
@Tirthpanchori
Copy link
Copy Markdown
Contributor Author

Thanks for contributing

Happy to contribute! Looking forward to more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FE-01: Implement API Rate Limiting

2 participants