{"id":34684263,"url":"https://github.com/shivammm21/apigateway","last_synced_at":"2026-04-24T04:33:23.348Z","repository":{"id":326675787,"uuid":"1106107679","full_name":"shivammm21/apigateway","owner":"shivammm21","description":"A lightweight API Gateway built with Spring Boot + Redis, offering authentication, rate limiting, IP blocking, routing, and real-time analytics.","archived":false,"fork":false,"pushed_at":"2025-11-29T11:09:13.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-01T12:43:42.836Z","etag":null,"topics":["api-gateway","api-security","cyber-security","cybersecurity","developer","developer-tools","docker-image","dockerfile","security","testing"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/shivammm21/apigateway","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shivammm21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-28T16:35:25.000Z","updated_at":"2025-11-29T11:14:57.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/shivammm21/apigateway","commit_stats":null,"previous_names":["shivammm21/apigateway"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/shivammm21/apigateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivammm21%2Fapigateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivammm21%2Fapigateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivammm21%2Fapigateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivammm21%2Fapigateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shivammm21","download_url":"https://codeload.github.com/shivammm21/apigateway/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivammm21%2Fapigateway/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32209893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T03:15:14.334Z","status":"ssl_error","status_checked_at":"2026-04-24T03:15:11.608Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-gateway","api-security","cyber-security","cybersecurity","developer","developer-tools","docker-image","dockerfile","security","testing"],"created_at":"2025-12-24T21:40:02.822Z","updated_at":"2026-04-24T04:33:23.341Z","avatar_url":"https://github.com/shivammm21.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Secure API Gateway (Spring Boot + Redis)\n\nA lightweight API Gateway that provides JWT validation, per-user/IP rate limiting, IP blocking, request routing to microservices, analytics, recent logs, dynamic routing admin APIs, and health checks.\n\n## Tech Stack\n- Spring Boot 3 (Java 17)\n- Spring Web, Spring Security, Actuator\n- Spring Data Redis (Lettuce)\n- Redis\n- Docker + Docker Compose\n- Lombok\n\n## Run locally\n\n### Prerequisites\n- Java 17+\n- Docker (optional but recommended)\n- Redis (local or via docker)\n\n### Option A: Run with Docker Compose\n```\ndocker compose up --build\n```\nServices:\n- Gateway: http://localhost:8767\n- Redis: localhost:6379\n\n### Option B: Run locally with local Redis\n1) Start Redis (example):\n```\ndocker run --rm -p 6379:6379 redis:alpine\n```\n2) Run the app:\n```\n./mvnw spring-boot:run\n```\n\n## Admin APIs\n\n- GET `/auth/validate` — Validates JWT from `Authorization: Bearer \u003ctoken\u003e` header.\n- GET `/admin/rate-limit/status?userId=\u003cid\u003e` — Current usage for a user.\n- POST `/admin/rate-limit/update` — Update global limit.\n  Body:\n  ```json\n  { \"limitPerMinute\": 200 }\n  ```\n- GET `/admin/ip-block/list` — List blocked IPs.\n- POST `/admin/ip-block/block` — Block an IP.\n  ```json\n  { \"ip\": \"123.45.67.89\", \"reason\": \"Suspicious activity\" }\n  ```\n- POST `/admin/ip-block/unblock` — Unblock an IP.\n  ```json\n  { \"ip\": \"123.45.67.89\" }\n  ```\n- GET `/admin/analytics/traffic` — Traffic stats (by service/user).\n- GET `/admin/analytics/errors` — Error stats (4xx/5xx/jwt/routing).\n- GET `/admin/analytics/services` — Microservice statuses.\n- GET `/admin/logs/recent` — Last 100 logs (JSON strings).\n- GET `/admin/routes/list` — Current dynamic routes.\n- POST `/admin/routes/add` — Add a new route.\n  ```json\n  { \"path\": \"/payments/**\", \"serviceUrl\": \"http://payment-service:8083\" }\n  ```\n- GET `/health` — Liveness endpoint.\n\n## Dynamic Routing\nRoutes are stored in Redis hash `routes`: key is path pattern (e.g., `/users/**`), value is service base URL (e.g., `http://user-service:8081`). The gateway forwards any non-admin/non-internal requests by longest-prefix match.\n\nExample to add routes:\n```\ncurl -X POST http://localhost:8767/admin/routes/add \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"path\":\"/users/**\",\"serviceUrl\":\"http://user-service:8081\"}'\n```\n\n## JWT Validation\n`AuthenticationFilter` performs a stubbed validation in `JwtService`. Replace with actual JWT verification (public key / secret) and parse claims to set `userId` and `role`. The `/auth/validate` endpoint exposes the same logic for services to query if needed.\n\n## Rate Limiting\n`RateLimitService` uses minute windows with Redis keys:\n- `rate:user:{id}` and `rate:ip:{ip}` (with minute suffix)\n- Global limit key: `rate:config:limitPerMinute` (default 200)\n\n429 is returned when exceeded.\n\n## IP Blocking\n`IpBlockService` uses Redis set `block:ips`.\n\n## Analytics\n- Traffic: Redis hash `traffic:stats` (fields: `svc:\u003cname\u003e`, `user:\u003cid\u003e`)\n- Errors: Redis hash `errors:stats` (fields include `jwt`, `routing`, etc.)\n- Services status: Redis hash `services:status`\n\n## Logs\nRecent 100 logs are kept in Redis list `logs:recent`.\n\n## Security\n`SecurityConfig` currently permits `/admin/**`, `/auth/validate`, `/health`, `/actuator/**` for ease of testing. Lock these down as needed (e.g., with basic auth, IP allowlist, or OAuth2).\n\n## Actuator\n`/actuator` endpoints are enabled with detailed health for local operations. Review before production.\n\n## Build\n```\n./mvnw -DskipTests package\n```\nJar output: `target/apigateway-0.0.1-SNAPSHOT.jar`\n\n## Folder Structure\nSee `src/main/java/com/apigateway/` for `config/`, `controller/`, `filter/`, `service/`, and `model/` packages.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshivammm21%2Fapigateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshivammm21%2Fapigateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshivammm21%2Fapigateway/lists"}