A production-grade API Gateway built to meticulously handle reverse proxying, per-API-key rate limiting, asynchronous traffic analytics, and live monitoring via Server-Sent Events.
- 🚀 Admin Dashboard: https://api-gateway-adesh.vercel.app
- 🔌 Gateway API: https://13-127-252-167.sslip.io
- 💖 Health Status: https://13-127-252-167.sslip.io/health
┌─────────────────────────────────────────────────────────────┐
│ VERCEL EDGE CLOUD │
│ │
│ ┌─────────────────┐ ┌────────────────┐ ┌────────────────┐ │
│ │ Admin UI │ │ Serverless │ │ Live Charts │ │
│ │ (Next.js) │ │ API Routes │ │ (Recharts) │ │
│ └─────────────────┘ └────────────────┘ └────────────────┘ │
└────────────────────────────┬────────────────────────────────┘
│
│ HTTPS / Live SSE Stream
▼
┌─────────────────────────────────────────────────────────────┐
│ AWS EC2 INSTANCE │
│ │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ CADDY REVERSE PROXY │ │
│ │ - SSL/TLS Termination (Let's Encrypt / sslip.io) │ │
│ │ - Read Timeout: 300s (Preserves SSE connections) │ │
│ └─────────────────────────┬─────────────────────────────┘ │
│ │ HTTP: 3001 (Internal) │
│ ▼ │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ NODE.JS API GATEWAY │ │
│ │ │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌───────────┐ │ │
│ │ │ Rate Limiter │ │ Route Proxy │ │ Analytics │ │ │
│ │ │ (Lua Config) │ │ (Express) │ │ Batch API │ │ │
│ │ └──────┬───────┘ └──────┬───────┘ └─────┬─────┘ │ │
│ └─────────┼──────────────────┼─────────────────┼────────┘ │
│ │ │ │ │
│ ┌─────────▼───────┐ ┌────────▼───────┐ ┌───────▼────────┐ │
│ │ REDIS DATATIER │ │ UPSTREAM APIs │ │ POSTGRES DB │ │
│ │ - Cache │ │ - Microservices│ │ - Auth Keys │ │
│ │ - Atomic Limits │ │ │ │ - Traffic Logs │ │
│ └─────────────────┘ └────────────────┘ └────────────────┘ │
└─────────────────────────────────────────────────────────────┘
-
Decoupled Architecture (Vercel + AWS)
The system is split to play to the strengths of both platforms. Vercel hosts the stateless React frontend globally on its Edge CDN. AWS EC2 handles the stateful, high-throughput, long-living Server-Sent Event (SSE) connections that serverless functions would otherwise prematurely terminate. -
Zero-Config SSL via sslip.io
Managing HTTPS manually in Node.js is cumbersome. By routing traffic through Caddy using ansslip.ioIP-based domain, the system automatically provisions and renews production-grade Let's Encrypt certificates with zero manual DNS mapping. -
High-Velocity Rate Limiting
The Gateway enforces strict API Quotas using Redis array-based Lua scripts. This pushes the rate-limit calculation directly into the Redis memory cache, ensuring atomic evaluations and preventing race conditions under high concurrency. -
Analytics Batch Processing
To prevent intense load from choking the PostgreSQL database during traffic spikes, the Gateway logs every request immediately into an in-memory queue. A highly optimizedBatch Writerflushes this memory buffer to PostgreSQL asynchronously every 5 seconds.
- Dashboard: Next.js 15, React, TailwindCSS v4, Recharts
- Gateway Core: Node.js, Express,
http-proxy-middleware, TypeScript - State & Data: PostgreSQL (
node-postgres), Redis (ioredis) - DevOps: Docker, GitHub Actions, Caddy
Clone the repository and bootstrap the workspaces:
npm installBoot the persistence databases locally via Docker:
docker compose up -d postgres redisRun schema migrations and initialize both frontend & backend simultaneously:
# Terminal 1: Backend
npm run migrate:gateway
npm run dev:gateway
# Terminal 2: Frontend
npm run dev:dashboardThe project implements an automated zero-downtime deployment pipeline via GitHub Actions.
- Any push to
maintriggers a GitHub Action runner. - The pipeline surgically builds a strictly minimized Node.js container for the Gateway, dynamically stripping all heavy Dashboard dependencies from the Docker build context to create a lightning-fast image.
- The image is published to GHCR.
- The runner connects via SSH into the AWS EC2 Host, pulls the latest images, safely runs PostgreSQL migrations via a temporary container, and gracefully spins up the PostgreSQL, Redis, Gateway, and Caddy instances without dropping existing traffic.