Skip to content
rmnr
DocsTourSlicesBest PracticeAgentsInstall

Command Palette

Search for a command to run...

New

Slice · AI prompt

Rate Limit

Backend-only Convex per-key request counter with atomic consume, server-owned namespace policy, optional server-key gate, and bounded cron pruning. The copied runtime/config/tool source is framework-neutral TypeScript: React/Next remains the default contract while explicit Svelte/SvelteKit installs reuse the same source with no duplicate UI or framework runtime dependency.

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

> Backend-only Convex per-key request counter with atomic consume, server-owned namespace policy, optional server-key gate, and bounded cron pruning.

📚 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

- npm: `convex`
- env vars:
  - `RATE_LIMIT_SERVER_KEY` (convex) — Optional shared secret for server-only consume calls; recommended for user-facing or security-sensitive namespaces.
- convex feature paths: `convex/features/rate_limit`

## 3. Wire it up

Run `npx rr add rate-limit` (or `--framework sveltekit`; both copy the same framework-neutral source). Compose `rateLimitTables` from `convex/features/rate_limit/_schema` into `convex/schema.ts`, add the namespace to the server-owned POLICY map, call `api.features.rate_limit.mutation.consume({ key, serverKey })` from server handlers, and wire `internal.features.rate_limit.mutation._pruneExpired` into `convex/crons.ts`. Set RATE_LIMIT_SERVER_KEY for sensitive namespaces and choose fail-open versus fail-closed behavior explicitly in the host wrapper.

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