{"id":50273344,"url":"https://github.com/ksb0896/api-gateway-service","last_synced_at":"2026-05-27T18:32:39.566Z","repository":{"id":320708470,"uuid":"1076267795","full_name":"ksb0896/api-gateway-service","owner":"ksb0896","description":"API gateway a central entry point for all microservices in the User-profile project","archived":false,"fork":false,"pushed_at":"2026-03-18T14:42:56.000Z","size":352,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-19T05:00:30.245Z","etag":null,"topics":["cloud-gateway","java17","jwt-token","openapi-spec","spring-boot","spring-security","spring-webflux","swagger-api","swagger-ui"],"latest_commit_sha":null,"homepage":"","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/ksb0896.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-10-14T16:13:44.000Z","updated_at":"2026-03-18T14:36:21.000Z","dependencies_parsed_at":"2025-10-25T12:21:59.548Z","dependency_job_id":"4f2a0c31-8d6c-4089-815c-7408591dd329","html_url":"https://github.com/ksb0896/api-gateway-service","commit_stats":null,"previous_names":["ksb0896/api-gateway-service"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ksb0896/api-gateway-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksb0896%2Fapi-gateway-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksb0896%2Fapi-gateway-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksb0896%2Fapi-gateway-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksb0896%2Fapi-gateway-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksb0896","download_url":"https://codeload.github.com/ksb0896/api-gateway-service/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksb0896%2Fapi-gateway-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33579665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cloud-gateway","java17","jwt-token","openapi-spec","spring-boot","spring-security","spring-webflux","swagger-api","swagger-ui"],"created_at":"2026-05-27T18:32:38.682Z","updated_at":"2026-05-27T18:32:39.556Z","avatar_url":"https://github.com/ksb0896.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 API Gateway for User Profile Service\n\n## Overview\n\nA **Spring Cloud Gateway** service that acts as the central entry point for all microservices in the system. It provides JWT authentication, request routing, API aggregation, and Swagger/OpenAPI documentation.\n\n---\n\n## 📋 Quick Start\n\n- **Port**: 8080\n- **Type**: Spring Cloud Gateway (Reactive/WebFlux)\n- **Java Version**: 17\n- **Spring Boot Version**: 3.5.6\n- **Spring Cloud Version**: 2025.0.0\n\n---\n\n## 🏗️ Architecture\n\n### Services Managed by Gateway\n\n| Service | Port | Endpoint | Purpose |\n|---------|------|----------|---------|\n| **API Gateway** | 8080 | `http://localhost:8080` | Main entry point, routing, authentication |\n| **User Profile Service** | 8081 | `http://localhost:8081` | User management, profiles |\n| **Profile Photo Service** | 8082 | `http://localhost:8082` | Photo upload and management |\n| **Auth Service** | 8083 | `http://localhost:8083` | Authentication, JWT token generation |\n\n---\n\n## 🔐 Authentication\n\n### JWT Token-Based Authentication\n\nAll requests to protected endpoints require a Bearer token:\n\n```bash\ncurl -X GET http://localhost:8080/v1/banks/100/users \\\n  -H \"Authorization: Bearer YOUR_JWT_TOKEN\"\n```\n\n**Token Generation:**\n1. Call Auth Service: `POST http://localhost:8083/auth/login`\n2. Provide credentials: `{\"username\": \"user\", \"password\": \"pass\"}`\n3. Receive JWT token in response\n4. Use token in `Authorization: Bearer \u003ctoken\u003e` header\n\n### JWT Configuration\n\n- **Algorithm**: HS256 (HMAC with SHA-256)\n- **Secret Key**: `MySecureKeyForMicroservicesMustBeVeryLongAndSafe`\n- **Expiration**: 1 hour (3600000 ms)\n\n---\n\n## 🛣️ API Routes\n\n### Route 1: User Profile Service\n\n**Path**: `/v1/banks/*/users/**`  \n**Target**: `http://localhost:8081`  \n**Filters**: Authentication, RewritePath  \n**Example**: `GET /v1/banks/103/users/7025868222864118611`\n\n### Route 2: Profile Photo Service\n\n**Path**: `/v1/banks/*/users/*/photo/**`  \n**Target**: `http://localhost:8082`  \n**Filters**: Authentication, CircuitBreaker, RewritePath  \n**Example**: `POST /v1/banks/103/users/7025868222864118611/photo`\n\n### Route 3: Auth Service\n\n**Path**: `/auth/**`  \n**Target**: `http://localhost:8083`  \n**Filters**: StripPrefix  \n**Example**: `POST /auth/login`, `GET /auth/validate`\n\n---\n\n## 📚 API Documentation\n\n### Swagger UI\n\n- **Main Page**: http://localhost:8080/swagger-ui/index.html\n- **OpenAPI Spec**: http://localhost:8080/v3/api-docs\n\n### Service Documentation\n\n| Service | Swagger URL | OpenAPI Spec |\n|---------|-------------|--------------|\n| Gateway | `http://localhost:8080/swagger-ui.html` | `http://localhost:8080/v3/api-docs` |\n| User Service | `http://localhost:8081/swagger-ui.html` | `http://localhost:8081/v3/api-docs` |\n| Auth Service | `http://localhost:8083/swagger-ui.html` | `http://localhost:8083/v3/api-docs` |\n\n---\n\n## 🔧 Technologies \u0026 Dependencies\n\n### Core Framework\n- Spring Boot 3.5.6\n- Spring Cloud Gateway 2025.0.0\n- Spring WebFlux (Reactive)\n- Spring Security\n\n### API Documentation\n- springdoc-openapi-starter-webflux-ui 2.5.0\n- Swagger UI\n- OpenAPI 3.0\n\n### Security \u0026 JWT\n- JJWT 0.11.5\n- Spring Security\n- JWT Token-based authentication\n\n### Resilience\n- Resilience4j 2.x\n- Circuit Breaker\n- Retry Logic\n- Timeout Management\n\n### Monitoring \u0026 Health\n- Spring Boot Actuator\n- Health Endpoints\n\n---\n\n## 🚀 Running the Application\n\n### Option 1: Using Batch Script (Recommended)\n\n```powershell\n# Windows - From project root\n.\\batch\\START_GATEWAY_DEBUG.cmd\n```\n\n### Option 2: Manual Start\n\n```powershell\n# Kill any existing Java processes\nStop-Process -Name java -Force -ErrorAction SilentlyContinue\n\n# Wait 3 seconds\nStart-Sleep -Seconds 3\n\n# Start the gateway\ncd C:\\ksb096-B\\prjcts\\sts\\user-service\\api-gateway-service\njava -jar target\\api_gateway-0.0.1-SNAPSHOT.jar\n```\n\n### Option 3: Using Maven\n\n```bash\nmvn clean package -DskipTests\njava -jar target/api_gateway-0.0.1-SNAPSHOT.jar\n```\n\n---\n\n## 📝 Configuration Files\n\n### Main Configuration\n**File**: `src/main/resources/application.properties`\n\nKey settings:\n- Server port: 8080\n- Gateway routes: 5 routes configured\n- JWT configuration\n- Logging levels\n- Resilience4j settings\n- Swagger/OpenAPI configuration\n\n---\n\n## 🔄 Request Flow\n\n```\nClient Request\n    ↓\nAPI Gateway (8080)\n    ├─ Spring Security: Allow all routes\n    ├─ Path Predicate: Match route pattern\n    ├─ Authentication Filter: Validate JWT token\n    │   ├─ Extract token from Authorization header\n    │   ├─ Validate JWT signature\n    │   ├─ Check token expiration\n    │   └─ Extract username\n    ├─ RewritePath Filter: Transform path if needed\n    ├─ CircuitBreaker: Check service health\n    └─ Forward to Backend Service\n        ↓\n    Backend Service (8081/8082/8083)\n        ├─ Process request\n        ├─ Return response\n        └─ Send to Gateway\n            ↓\n    API Gateway (8080)\n        └─ Return response to Client\n            ↓\nClient Response\n```\n\n---\n\n## 🧪 Testing\n\n### Test with cURL\n\n```bash\n# 1. Login to get token\ncurl -X POST http://localhost:8083/auth/login \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"username\":\"DecUserOne\",\"password\":\"password123\"}'\n\n# 2. Use token to call protected endpoint\ncurl -X GET http://localhost:8080/v1/banks/103/users/7025868222864118611 \\\n  -H \"Authorization: Bearer YOUR_TOKEN_HERE\"\n```\n\n### Test with Swagger UI\n\n1. Open: http://localhost:8080/swagger-ui/index.html\n2. Select service from dropdown\n3. Click \"Try it out\" on any endpoint\n4. Add Bearer token if required\n5. Click \"Execute\"\n\n---\n\n## 🐛 Issues Fixed\n\n### ✅ Issue 1: 401 Unauthorized Error\n- **Cause**: JWT API incompatibility between token generation and validation\n- **Fix**: Updated to modern JJWT 0.11.x+ API\n- **Status**: RESOLVED\n\n### ✅ Issue 2: Spring Security Blocking Requests\n- **Cause**: `.authenticated()` requirement blocking all requests\n- **Fix**: Changed to `.permitAll()` to let JWT filter handle auth\n- **Status**: RESOLVED\n\n### ✅ Issue 3: 404 Route Not Matching\n- **Cause**: Invalid path pattern for Spring Cloud Gateway 4.3.0\n- **Fix**: Updated to valid wildcard patterns\n- **Status**: RESOLVED\n\n### ✅ Issue 4: 500 Backend Service Error\n- **Cause**: Path rewriting losing bank ID\n- **Fix**: Preserved full path with `StripPrefix=0`\n- **Status**: RESOLVED\n\n### ✅ Issue 5: Swagger 404 Error\n- **Cause**: Gateway routes pointing to non-existent paths\n- **Fix**: Updated URIs to point to service base URLs with correct RewritePath\n- **Status**: RESOLVED\n\n---\n\n## 📚 Documentation\n\nComprehensive documentation available in `/documents/` folder:\n\n| Document | Purpose |\n|----------|---------|\n| SWAGGER_SETUP_SUMMARY.md | Swagger setup guide |\n| DEBUGGING_GUIDE.md | Troubleshooting reference |\n| FIX_SUMMARY.md | Technical details of fixes |\n| COMPLETE_TESTING_CHECKLIST.md | Testing procedures |\n| QUICK_REFERENCE.txt | Command cheat sheet |\n\n---\n\n## 🛠️ Scripts\n\nAvailable in `/batch/` folder:\n\n| Script | Purpose |\n|--------|---------|\n| START_GATEWAY_DEBUG.cmd | Start with full console output |\n| RESTART_GATEWAY.bat | Restart with clean process |\n| test_gateway.ps1 | Automated testing script |\n\n---\n\n## 📊 Logging\n\n### Debug Logging Enabled\n\n```properties\nlogging.level.org.springframework.cloud.gateway=DEBUG\nlogging.level.reactor.netty.http.client=DEBUG\nlogging.level.com.ksb.micro.api_gateway.filter=DEBUG\nlogging.level.com.ksb.micro.api_gateway.util=DEBUG\n```\n\n### Log Output Examples\n\n```\n\u003e\u003e\u003e [GATEWAY FILTER] Processing request to: /v1/banks/103/users\n\u003e\u003e\u003e [GATEWAY FILTER] Authorization header present, length: 350\n\u003e\u003e\u003e [JWT] ✓ Token validation SUCCESSFUL\n\u003e\u003e\u003e [GATEWAY FILTER] ✓ TOKEN VALID - Username: DecUserOne\n```\n\n---\n\n## 🔗 Related Services\n\n### User Profile Service (8081)\n- Manages user profiles and data\n- Requires JWT authentication\n- Documentation: http://localhost:8081/swagger-ui.html\n\n### Auth Service (8083)\n- Handles user authentication\n- Generates JWT tokens\n- No authentication required\n- Documentation: http://localhost:8083/swagger-ui.html\n\n### Profile Photo Service (8082)\n- Manages photo uploads\n- Requires JWT authentication\n- Documentation: http://localhost:8082/swagger-ui.html\n\n---\n\n## ✅ Deployment Checklist\n\nBefore deploying to production:\n\n- [ ] JWT secret key changed to secure value\n- [ ] All services configured and running\n- [ ] Swagger documentation complete\n- [ ] API endpoints tested with valid tokens\n- [ ] CORS configured if needed\n- [ ] Logging levels appropriate\n- [ ] Circuit breaker thresholds set correctly\n- [ ] Health endpoints working\n- [ ] Error handling tested\n- [ ] Rate limiting configured (if needed)\n\n---\n\n## 📞 Support\n\nFor issues or questions:\n\n1. Check: `/documents/DEBUGGING_GUIDE.md` for troubleshooting\n2. Review: `/documents/QUICK_REFERENCE.txt` for common commands\n3. Test: Use Swagger UI at http://localhost:8080/swagger-ui/index.html\n\n---\n\n## 📝 Version History\n\n| Version | Date | Changes |\n|---------|------|---------|\n| 1.0.0 | 2025-12-06 | Initial setup with JWT auth, routes, and Swagger |\n\n---\n\n## 🎯 Key Features\n\n✅ **JWT Authentication** - Secure token-based authentication  \n✅ **Route Aggregation** - Central gateway for all services  \n✅ **API Documentation** - Swagger/OpenAPI with multiple services  \n✅ **Request Routing** - Intelligent path matching and forwarding  \n✅ **Error Handling** - Comprehensive error messages and logging  \n✅ **Circuit Breaker** - Resilience4j for fault tolerance  \n✅ **CORS Support** - Cross-origin request handling  \n✅ **Health Checks** - Service health monitoring  \n\n---\n\n**Last Updated**: December 6, 2025  \n**Status**: ✅ Production Ready  \n**Maintainer**: ksb0896\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksb0896%2Fapi-gateway-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksb0896%2Fapi-gateway-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksb0896%2Fapi-gateway-service/lists"}