rmnr
DocsTourSlicesBest PracticeAgentsInstall

Command Palette

Search for a command to run...

New

Slice · AI prompt

Rate Limit

Convex-backed per-key request counter. Atomic check-and-increment via `consume` mutation; expired rows pruned by `_pruneExpired` internalMutation wired to a 5-min cron. Replaces single-replica in-memory Map so multi-replica Next deployments share buckets. Limits live in an in-code POLICY map keyed by namespace prefix (admin-login:<ip>, mcp:<ip>) — never caller-supplied; optional RATE_LIMIT_SERVER_KEY env gates anonymous calls. Lifted 2026-05-16 from rahmanef.com; hardened 2026-06-07.

Resource detail View source
Copy this prompt into Claude / Codex / Cursor
rate-limit.prompt.mdmarkdown
# Install `rate-limit` — Rate Limit

> Convex-backed per-key request counter.

📚 Knowledge base : https://resource.rahmanef.com/llms.txt
📦 Slice detail   : https://resource.rahmanef.com/slices/rate-limit
🧠 JSON catalog   : https://resource.rahmanef.com/api/knowledge?slice=rate-limit
🔗 Source         : https://github.com/rahmanef63/resource-site/tree/main/frontend/slices/rate-limit

## 1. Install

```bash
npx rahman-resources add rate-limit
# alias: npx rr add rate-limit
```

The CLI copies `frontend/slices/rate-limit/` into your project + augments `.env.example` + installs npm deps automatically. Run it from your project root.

## 2. What it ships

- convex feature paths: `convex/features/rate_limit`

## 3. Wire it up

Run `npx rr add rate-limit`. Compose `rateLimitTables` into root convex/schema.ts. Wire `internal.features.rate_limit.mutations._pruneExpired` into convex/crons.ts every 5 min. Add your namespace to the in-code POLICY map, then call `api.features.rate_limit.mutations.consume({ key, serverKey })` from server-side handlers — keep a fail-open wrapper so a Convex outage doesn't 503 the route. Set RATE_LIMIT_SERVER_KEY on the deployment to block anonymous consume calls.

## Rules of engagement

- shadcn-only UI primitives. No raw `<button>` / `<dialog>` / native date or file inputs.
- 200-line hard cap per source file (extract neighbours when over).
- All Convex queries hit an index (`.withIndex(...)`); never bare `.collect()`.
- Public mutations/queries declare `args:` validators + authz.
- Full ruleset: https://resource.rahmanef.com/best-practice

The agent will fetch /llms.txt for the full ruleset and use /api/knowledge for the JSON catalog.