# lithikhab/distributed-rate-limiter architecture

> Architecture diagram of the GitHub repository lithikhab/distributed-rate-limiter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lithikhab/distributed-rate-limiter
- Repository: https://github.com/lithikhab/distributed-rate-limiter

## Overview

This Spring Boot service applies a shared fixed-window rate limit to `/api/**` requests. The request path identifies clients by IP, checks an atomic Redis counter, then either stops with HTTP 429 or proceeds to the endpoint. Limits come from external configuration. The README documents the Redis and response flow; source excerpts show interceptor invocation, configuration registration, and the service’s Redis script. Other than those documented links, unsampled wiring is not inferred.

Main entry points: [`src/main/java/com/lithikha/rate_limiter/RateLimitInterceptor.java`](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimitInterceptor.java) (Rate interceptor), [`src/main/java/com/lithikha/rate_limiter/RateLimiterService.java`](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimiterService.java) (Rate limiter), [`src/main/java/com/lithikha/rate_limiter/PingController.java`](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/PingController.java) (Ping endpoint), [`src/main/java/com/lithikha/rate_limiter/RateLimiterProperties.java`](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimiterProperties.java) (Limit properties)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_request["Request handling"]
  node_interceptor["Rate interceptor"]
  node_controller["Ping endpoint"]
  node_webconfig["Web registration<br/>[WebConfig.java]"]
end

subgraph group_limiting["Limit enforcement"]
  node_service["Rate limiter"]
  node_redis[("Redis")]
end

subgraph group_configuration["Configuration"]
  node_properties["Limit properties"]
  node_yaml["Limit settings<br/>[application.yml]"]
end

node_client(("HTTP client"))

node_client -->|"sends request"| node_interceptor
node_webconfig -->|"registers for /api/**"| node_interceptor
node_interceptor -->|"checks limit"| node_service
node_service -->|"runs atomic script"| node_redis
node_redis -->|"returns count"| node_service
node_service -->|"reads limits"| node_properties
node_yaml -->|"configures"| node_properties
node_interceptor -->|"allows request"| node_controller
node_interceptor -->|"returns 429"| node_client
node_controller -->|"returns response"| node_client

click node_interceptor "https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimitInterceptor.java"
click node_controller "https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/PingController.java"
click node_webconfig "https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/WebConfig.java"
click node_service "https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimiterService.java"
click node_properties "https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimiterProperties.java"
click node_yaml "https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/resources/application.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_interceptor,node_controller,node_webconfig,node_client toneBlue
class node_service,node_redis toneAmber
class node_properties,node_yaml toneMint
```

## Components

### Request handling

- [Rate interceptor](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimitInterceptor.java): `src/main/java/com/lithikha/rate_limiter/RateLimitInterceptor.java`
- [Ping endpoint](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/PingController.java): `src/main/java/com/lithikha/rate_limiter/PingController.java`
- [Web registration](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/WebConfig.java): `src/main/java/com/lithikha/rate_limiter/WebConfig.java`

### Limit enforcement

- [Rate limiter](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimiterService.java): `src/main/java/com/lithikha/rate_limiter/RateLimiterService.java`
- **Redis**

### Configuration

- [Limit properties](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/java/com/lithikha/rate_limiter/RateLimiterProperties.java): `src/main/java/com/lithikha/rate_limiter/RateLimiterProperties.java`
- [Limit settings](https://github.com/lithikhab/distributed-rate-limiter/blob/main/src/main/resources/application.yml): `src/main/resources/application.yml`

### Other components

- **HTTP client**

## Connections

- HTTP client → Rate interceptor: sends request (evidence: `README.md`)
- Web registration → Rate interceptor: registers for /api/** (evidence: `src/main/java/com/lithikha/rate_limiter/WebConfig.java`)
- Rate interceptor → Rate limiter: checks limit (evidence: `src/main/java/com/lithikha/rate_limiter/RateLimitInterceptor.java`)
- Rate limiter → Redis: runs atomic script (evidence: `README.md`)
- Redis → Rate limiter: returns count (evidence: `README.md`)
- Rate limiter → Limit properties: reads limits (evidence: `src/main/java/com/lithikha/rate_limiter/RateLimiterService.java`)
- Limit settings → Limit properties: configures (evidence: `README.md`)
- Rate interceptor → Ping endpoint: allows request (evidence: `README.md`)
- Rate interceptor → HTTP client: returns 429 (evidence: `README.md`)
- Ping endpoint → HTTP client: returns response (evidence: `README.md`)
