A full-stack, closed-loop telemetry and proxy system. This project acts as an API Gateway that intercepts incoming network traffic, mathematically rate-limits requests using a custom Token Bucket algorithm, proxies the traffic to a target server, and visualizes the network health in a real-time React dashboard.
- Custom Rate Limiting Engine: A mathematical implementation of the Token Bucket algorithm built from scratch in Express. Handles burst capacity and recovery rates without relying on third-party limiting libraries.
- Asynchronous Telemetry Logging: Middleware that extracts request metadata (IP, latency, status codes) and writes to MongoDB asynchronously, ensuring zero blocking of the main thread and ultra-low overhead.
- Live Analytics Dashboard: A React frontend utilizing Vite and Recharts to poll the MongoDB aggregation pipeline, visualizing traffic volume and system latency spikes in real-time.
- Closed-Loop UI Testing: Built-in dashboard controls to actively fire network requests at the protected proxy and immediately visualize the rate-limiter's defensive responses (HTTP 429s).
- Data Lifecycle Management: TTL (Time-To-Live) indexing in MongoDB automatically expires old logs after 1 day, keeping database costs and query times down.
- The Shield (Proxy & Limiter): External requests hit
/api/*. The gateway checks the Token Bucket. If permitted, the request is proxied to the target. If empty, the connection is instantly severed (429). - The Surveillance (Logger): The exact millisecond latency and status code of the interaction is recorded and pushed to MongoDB Atlas.
- The Monitor (Dashboard): React fetches aggregated minute-by-minute metrics from the unprotected
/admin/*routes, mapping the data cleanly onto SVG charts.
- Frontend: React (Vite), Recharts, Axios
- Backend: Node.js, Express, HTTP-Proxy-Middleware, CORS
- Database: MongoDB Atlas, Mongoose (with advanced Aggregation Pipelines)
- Node.js (v18+)
- A MongoDB Atlas cluster (or local instance)
git clone https://github.com/Arya125-droid/api-gateway-analytics.git
cd api-gateway-analyticsCreate a .env file in the root directory and add your MongoDB connection string:
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/gateway
PORT=5001You need to install packages for both the backend and frontend.
# Install backend dependencies
npm install
# Install frontend dependencies
cd frontend
npm install
cd ..You will need two terminal windows to run both servers simultaneously.
cd backend
npm run devRuns on http://localhost:5001
cd frontend
npm run devRuns on http://localhost:5173
- Open the dashboard in your browser.
- Click the "Fire Test Request" button to simulate external traffic hitting your proxy.
- Rapidly click the button to exhaust the Token Bucket and trigger the rate limiter.
- Watch the charts instantly stack red (Blocked) traffic over green (Success) traffic, while monitoring the latency curve for cold-start spikes.
- Click "Wipe Data" to clear the database directly from the UI and start a fresh testing session.
By default, the gateway is configured with a strict Token Bucket policy to demonstrate the blocking capabilities of the UI.
- Burst Capacity (Bucket Size): 5 tokens total
- Refill Rate: 1 token per second
How to adjust these limits:
Navigate to backend/src/rateLimiter.js and modify these two variables:
// backend/src/rateLimiter.js
const BUCKET_CAPACITY = 5; // Change this to increase/decrease instant burst allowance
const REFILL_RATE = 1; // Change this to adjust how fast tokens regenerateNote: If you change these values while the backend is running, Nodemon will automatically restart the server and apply your new limits instantly.