How nakacya/llm-gateway-oauth works
Project type and purpose
• From the file tree and README (“llm-gateway-oauth”), this is an API/Gateway service that sits in front of an LLM endpoint, enforcing OAuth2 authentication and issuing/verifying JWTs.
• It is neither a monolithic full-stack app nor a compiler; it is an authentication proxy/API-gateway with some lightweight management UI.
File structure
• Top-level:
• Dockerfile, docker-compose.yml → containerized deployment
• nginx.conf → Nginx reverse proxy + Lua module integration
• lua/*.lua → Lua scripts implementing all OAuth flows, JWT validation, token management, keys
• oauth2_proxy.cfg.sample, litellm_config.yaml.sample, .env_sample → config templates
• admin_manager.html, token_manager.html → static HTML UIs for admins and token viewers
• scripts/ → setup.sh (initial provisioning), test_api.sh (smoke tests)
• No traditional “frontend” or “backend” directories; Nginx+Lua acts as backend logic, HTML files are static UIs.
README for additional insights
• Very minimal; implies you must infer architecture from naming conventions and config samples.
a. Main components
1. User clients (e.g., browser or LLM client library)
2. Nginx Gateway Container
– Lua auth_handler.lua, jwt_validator.lua, token_*.lua, key_generate_handler.lua
– Serves admin_manager.html & token_manager.html
3. External OAuth 2.0 Provider (e.g., GitHub, Google, Keycloak)
4. Downstream LLM service or API (could be an OpenAI, self-hosted LLM, etc.)
5. (Optional) Token store or cache (in-memory or external, not explicit here)
6. Configuration & Secrets (env files, litellm_config.yaml, oauth2_proxy.cfg)
7. Docker / Docker-Compose orchestration
b. Relationships & interactions
1. Client → Nginx Gateway: initial request
2. Nginx + Lua → JWT Validator: checks authorization header
3. If no valid JWT → redirect to External OAuth Provider
4. OAuth callback → token_generator.lua issues JWT, stores it
5. JWT returned to Client
6. Client → Nginx with JWT → Nginx forwards request to LLM service
7. Admin client → Nginx serves admin_manager.html → admin uses token_list.lua, token_revoke.lua
c. Architectural patterns & principles
– Reverse-proxy gateway pattern
– Layered security: OAuth2 at edge, JWT for downstream calls
– Modular functions in Lua for each concern (validation, generation, revocation)
– Containerized microservice with externalized config
d. Key technologies
– Nginx + OpenResty (Lua)
– OAuth2 protocol
– JWT (json web tokens)
– Docker & Docker-Compose
– Shell scripts for setup and testing
– Static HTML UIs for management