How seema24jauhari/nestjs-rate-shield works
nestjs-rate-shield is a Redis-backed NestJS rate-limiting library. A request covered by the blacklist guard is checked against the IP list; routes configured with @RateLimit() are then evaluated by the interceptor, which identifies the caller, checks Redis, and either allows the request with rate-limit headers or returns 429. The README also documents whitelist bypass and both algorithms. The sampled interceptor does not show the whitelist check, so that relationship is cited to the README; Lua script execution is visible in RedisService, but script internals were not sampled.
Main entry points: redis.service.ts Redis service · rate-limit.interceptor.ts Rate-limit interceptor · ip-list.service.ts IP lists · app.module.ts Application module
Components 13
Request controls
- Blacklist guard
src/common/gaurds/blacklist.guard.ts - IP lists
src/common/services/ip-list.service.ts
Rate limiting
- RateLimit decorator
src/common/decorators/rate-limit.decorator.ts - Rate-limit interceptor
src/common/interceptors/rate-limit.interceptor.ts - Sliding-window script
src/redis/lua-scripts/sliding-window.lua - Token-bucket script
src/redis/lua-scripts/token-bucket.lua
Redis layer
- Redis service
src/redis/redis.service.ts
NestJS wiring
- Redis module
src/redis/redis.module.ts - Common module
src/common/common.module.ts - Application module
src/app.module.ts
Other components
- HTTP caller
- Redis server
- API response
Connections 16
- HTTP caller → Blacklist guard: sends request
README.md - Blacklist guard → IP lists: checks blacklist
src/common/gaurds/blacklist.guard.ts - HTTP caller → RateLimit decorator: configures route
README.md - RateLimit decorator → Rate-limit interceptor: provides rule
src/common/interceptors/rate-limit.interceptor.ts - Rate-limit interceptor → IP lists: checks whitelist
README.md - Rate-limit interceptor → Redis service: checks limit
src/common/interceptors/rate-limit.interceptor.ts - Redis service → Sliding-window script: loads and evaluates
src/redis/redis.service.ts - Redis service → Token-bucket script: loads and evaluates
src/redis/redis.service.ts - Redis service → Redis server: reads and writes
src/redis/redis.service.ts - IP lists → Redis service: stores IP sets
src/common/services/ip-list.service.ts - Rate-limit interceptor → API response: sets headers or 429
src/common/interceptors/rate-limit.interceptor.ts - Application module → Redis module: registers
src/app.module.ts - Application module → Common module: registers
src/app.module.ts - Application module → Blacklist guard: registers globally
src/app.module.ts - Redis module → Redis service: provides
src/redis/redis.module.ts - Common module → IP lists: provides
src/common/common.module.ts