Quality control for your software factory.

Source-controlled AI checks on every pull request. Standards as checks, enforced by AI, decided by humans.

Add rate limiting to API endpoints

#847

CHECKS 0/2
Needs Review
Anti-Slop
Accessibility

ChangesLogs

File: src/middleware/rateLimit.ts
Lines: +9-47

25 unmodified lines
26  if (apiKeyHeader) return `key:${apiKeyHeader}`;
27  const clientIpAddress: string = req.ip ?? "unknown";
28  return `ip:${clientIpAddress}`;
29const buckets = new Map<string, TokenBucket>();
30function getClientKey(req: Request) {
31  const apiKey = req.headers["x-api-key"] as string | undefined;
32  if (apiKey) return `key:${apiKey}`;
33  return `ip:${req.ip ?? "unknown"}`;
34}
30/**
31 * Refills tokens in the bucket based on elapsed time.
32 * @param bucket - The token bucket to refill
33 * @param config - The rate limit configuration
34 */
35function refillBucket(bucket: TokenBucket, config: RateLimitConfig): void {
36  // Get the current timestamp
37  const currentTimestamp: number = Date.now();
38  // Calculate the elapsed time since last refill
39  const elapsedTimeSinceLastRefill: number = currentTimestamp - bucket.lastRefill;
40  // Calculate the number of tokens to add based on elapsed time
41  const numberOfTokensToAdd: number = Math.floor(
42    (elapsedTimeSinceLastRefill / config.windowMs) * config.maxRequests,
43  );
44  // Only update if there are tokens to add
45  if (numberOfTokensToAdd > 0) {
46    bucket.tokens = Math.min(config.maxRequests, bucket.tokens + numberOfTokensToAdd);
47    bucket.lastRefill = currentTimestamp;
48  }
49}

Reject Accept

Scales with your factory

Your factory gets faster every week. Checks keep pace. Every PR checked against your engineering standards, automatically. Quality control that never falls behind, no matter how fast the factory runs.

Consistency over breadth

Only enforce what you told them to catch, and never miss it. No surprise bugs. No unsolicited opinions. The opposite of generic AI review.

Focus on designing, not reviewing

You're building a factory, not running a review queue. Checks handle the mechanical enforcement so you focus on direction, architecture, and making the system better.

Run AI checks on every pull request

Write checks as markdown in your repo. Continue runs them as native GitHub status checks with suggested fixes when code misses the mark.