Configure Limits • Monitor Requests • Detect Breaches • Test APIs
API Rate Limiter is a full-stack MERN application that controls how frequently clients can access an API. It allows administrators to configure request limits, monitor violations, and analyze API activity through an interactive dashboard.
The application uses a Sliding Window Counter algorithm to track requests within a specified time period. When a client exceeds the configured limit, the system can reject further requests with an HTTP 429 Too Many Requests response.
- ⚙️ Configurable Rate Limits — Define request limits by IP address, domain, or user identity and by minute, hour, or day.
- 🚦 Sliding Window Counter — Reduce boundary-burst issues associated with fixed-window rate limiting.
- 📊 Admin Dashboard — Monitor request statistics and rate-limit breach activity.
- 📝 Breach Logs — Record and review requests that exceed configured limits.
- 🔔 Notifications — Display in-app alerts and optionally send email notifications through SMTP.
- 🧪 Interactive API Tester — Generate requests and observe rate-limit enforcement in action.
- 🗄️ Automatic Counter Cleanup — Use MongoDB TTL indexes to expire eligible request-counter documents.
- ✅ Automated Testing — Includes 65 documented unit and integration tests using Jest and Supertest.
Client Requests
│
▼
┌───────────────┐
│ Express Server│
└───────┬───────┘
│
▼
┌───────────────┐
│ Rate Limiter │
│ Middleware │
└───────┬───────┘
│
▼
┌───────────────┐
│ Check Rules & │
│ Request Count │
└───────┬───────┘
│
┌─────┴─────┐
▼ ▼
Within Limit Limit Exceeded
│ │
▼ ▼
Allow Request HTTP 429
│
▼
Breach Log &
Notification
| Component | Technology |
|---|---|
| Frontend | React 18, Vite, React Router, Axios |
| Backend | Node.js, Express.js |
| Database | MongoDB, Mongoose |
| Testing | Jest, Supertest, mongodb-memory-server |
| Email Notifications | Nodemailer, SMTP |
| Version Control | Git & GitHub |
- Node.js 18 or higher
- npm
- MongoDB running locally or an accessible MongoDB instance
git clone https://github.com/baraiyash/API-Rate-Limiter.git
cd API-Rate-Limiternpm run install:allCreate a .env file inside the server/ directory:
PORT=5000
MONGODB_URI=mongodb://localhost:27017/rateLimiter
# Optional: Email notifications
SMTP_HOST=
SMTP_PORT=587
SMTP_USER=
SMTP_PASS=
ADMIN_EMAIL=[email protected]npm run devOpen the frontend URL displayed in the terminal. The expected URL is http://localhost:3000 if Vite is configured to use that port.
Suppose an administrator configures a rule allowing 10 requests per minute per IP address.
- Create the rate-limit rule from the dashboard.
- Open the API Tester and send multiple requests.
- Observe successful responses while requests remain within the configured limit.
- Exceed the limit and observe HTTP
429responses. - Review the recorded violations in Breach Logs.
- Check in-app notifications or configure SMTP for email alerts.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/rules |
Retrieve rate-limit rules |
| POST | /api/rules |
Create a rule |
| PUT | /api/rules/:id |
Update a rule |
| DELETE | /api/rules/:id |
Delete a rule |
| GET | /api/test |
Test rate-limit enforcement |
| GET | /api/breaches |
Retrieve breach logs |
| DELETE | /api/breaches |
Clear breach logs |
| GET | /api/notifications |
Retrieve notifications |
| PATCH | /api/notifications/:id/read |
Mark a notification as read |
| PATCH | /api/notifications/read-all |
Mark all notifications as read |
| GET | /api/stats |
Retrieve dashboard statistics |
| GET | /api/health |
Check server health |
The project includes unit and integration tests covering utility functions, rule management, rate-limiting middleware, and notifications.
| Test Suite | Tests |
|---|---|
helpers.test.js |
17 |
rules.test.js |
16 |
rateLimiter.test.js |
21 |
notification.test.js |
11 |
| Total | 65 |
Run the test suite:
npm testGenerate a test coverage report:
npm run test:coverageThe counts reflect the documented test suite. Run the tests to verify the current results.
- Sliding Window Counter: Helps reduce sudden request bursts around time-window boundaries.
- Atomic Counter Updates: Uses MongoDB's
findOneAndUpdateand$incfor atomic counter increments. - TTL Indexes: Automatically remove eligible expired counter documents.
- Fail-Open Strategy: Allows requests to continue when the database is unavailable, prioritizing availability over strict rate-limit enforcement.
- Notification Cooldown: Uses a five-minute cooldown to reduce repetitive alerts during sustained breaches.
AI tools, including Google Antigravity and Claude, assisted with requirement analysis, architecture planning, code generation, test design, documentation, and troubleshooting.
- REST API development using Express.js
- Middleware-based request processing
- Rate-limiting algorithms and request tracking
- MongoDB data modeling and atomic operations
- TTL-based data expiration
- HTTP status codes and error handling
- Unit and integration testing
Yash Barai
- GitHub: @baraiyash
- Project: API Rate Limiter
⭐ If you find this project interesting, consider giving the repository a star!