Sign-in & shared code

Rate limits

Pathshared/rate-limits
Statuslive
Drill-down pages—
Pop-ups—
Tabs—
API routes—

Business rules

Data comes from: dh_rate_limits (one row per counted request: key = IP + group, time). Code: middleware/rateLimit.ts, run on every /api request.

How it works:

  • Limits per IP, by group:
    • auth: /auth/login, /auth/password, /auth/forgot-password, /auth/reset-password: 5 a minute.
    • invite: /auth/invite, /auth/accept-invite: 10 per 5 minutes.
    • sync: Dentrix, NexHealth and Acuity calls and syncs (a path segment dentrix, nexhealth, acuity, sync or sync-…), but not patient records: 10 a minute.
    • default: everything else (including office lists such as /data/dentrix-locations): 60 a minute.
  • Groups go by whole path segments, not by "contains".
  • auth and invite are always counted in the database, so the count holds across the whole Cloudflare fleet.
  • Other signed-in calls (with a session token) are counted in the worker's memory only. This is free, but each worker copy counts on its own.
  • Calls without a token are counted in the database.
  • Over the limit: 429 "Too many requests. Please try again later."
  • If the database count fails, the request is let through (logged).
  • Clean-up runs in the background (waitUntil) on about 1 counted request in 20: it removes that IP's rows older than its window, plus up to 1,000 rows of any IP older than a day. The table only holds recent counts.

Database tables & columns

TableColumns used
dh_rate_limitskey, timestamp

File structure

Its own files

  • apps/
    • worker/
      • src/
        • middleware/
          • rateLimit.ts

Shared code it uses (followed through its imports and the helpers its API calls; sign-in/access plumbing and UI primitives left out)

  • apps/
    • worker/
      • src/
        • db/
          • index.ts