How lokesh-1511/llm-gateway works
Purpose and Entry Points
PromptOps Gateway is a FastAPI reverse proxy for OpenAI-compatible chat-completion traffic. It sanitizes prompts, semantically reuses prior answers, forwards misses to Groq, and records request telemetry. The backend starts from main.py; the operator control plane starts at frontend/src/main.jsx and composes through frontend/src/App.jsx.
Request Gateway and Orchestration
main.py is the critical-path controller for POST /v1/chat/completions. It accepts client payloads, coordinates security, caching, upstream proxying, and background work while preserving an LLM-provider-style response. models.py defines shared request/response or persistence models, and routing_service.py likely centralizes route/provider selection policy.
Inline Security Boundary
The DLP boundary is implemented by security_service.py, with authentication/authorization concerns separated in auth_service.py. Before any external LLM request, the gateway analyzes prompt content with Presidio/SpaCy and substitutes sensitive entities with placeholders. This makes the sanitized payload—not the original client text—the material sent beyond the enterprise boundary.
Semantic Cache Layer
cache_service.py owns semantic lookup and response reuse; compression_service.py is an adjacent optimization component for reducing request/context size. Embeddings are backed by local ChromaDB persistence under .chroma_db/chroma.sqlite3 and its collection data directories. A cache hit short-circuits provider invocation; a miss proceeds upstream and schedules cache population after the response.
Upstream LLM Proxy
proxy_service.py encapsulates asynchronous HTTP forwarding to the configured Groq OpenAI-compatible endpoint. main.py should remain the policy/orchestration layer, while this service owns provider transport, API-key use, request forwarding, and upstream response handling. The external dependency is Groq, configured through GROQ_API_KEY and GROQ_BASE_URL.
Telemetry, Persistence, and Background Work
analytics.py records latency, token estimates, PII detection, cache status, and cost-savings metrics. database.py provides SQLAlchemy/PostgreSQL connectivity, with Supabase as the intended managed PostgreSQL deployment; llm_logs.db suggests a local persisted log/database artifact is also present. Writes and cache inserts are deliberately deferred using FastAPI/Starlette background tasks so they do not delay the client response.
Control Plane and Supporting Runtime
The React/Vite frontend displays operational and administrative views through frontend/src/Dashboard.jsx, frontend/src/AdminDashboard.jsx, and frontend/src/ChatPortal.jsx. Material runtime dependencies are Python/FastAPI/Uvicorn, async httpx, Presidio/SpaCy NER, Sentence Transformers embeddings, ChromaDB, tiktoken, PostgreSQL/Supabase, and React/Vite. Heavy local NLP and vector operations are intended to run off the async event loop via threadpool execution.
Main entry points: main.py Chat Completions Gateway · database.py SQLAlchemy Database · cache_service.py Semantic Cache · proxy_service.py Groq Proxy
Components 19
Gateway Runtime
FastAPI request path and policy services.
- Chat Completions Gateway · Owns POST /v1/chat/completions orchestration and provider-compatible responses.
main.py - Shared Models · Request, response, and persistence model definitions.
models.py - Routing Policy · Centralizes route and provider selection.
routing_service.py - Auth Service · Separates authentication and authorization from DLP.
auth_service.py - DLP Sanitizer · Replaces detected sensitive entities before external transmission.
security_service.py - Context Compression · Reduces request or context size.
compression_service.py - Groq Proxy · Forwards misses to the Groq OpenAI-compatible API.
proxy_service.py
Data & Background
Semantic storage, telemetry, and deferred writes.
- Semantic Cache · Finds semantically similar requests and reuses answers.
cache_service.py - ChromaDB Store · Local persistent embeddings and collection data.
.chroma_db/chroma.sqlite3 - Background Tasks · Defers cache population and telemetry writes after responding.
- Request Analytics · Records latency, tokens, PII, cache status, and savings.
analytics.py - SQLAlchemy Database · Provides application database connectivity.
database.py - Local Log Database
llm_logs.db
Operator Control Plane
React/Vite operational UI.
- Frontend Entry
frontend/src/main.jsx - Control Plane App · Composes operational and administrative views.
frontend/src/App.jsx - Operations Views · Dashboard, admin dashboard, and chat portal.
frontend/src/Dashboard.jsx
External Services
Upstream inference and managed persistence.
- Supabase PostgreSQL · Intended managed PostgreSQL deployment.
- Groq API · Configured by GROQ_API_KEY and GROQ_BASE_URL.
Other components
- API Clients
Connections 19
- API Clients → Chat Completions Gateway: POST chat completions
- Chat Completions Gateway → Shared Models: uses contracts
- Chat Completions Gateway → Auth Service: authorizes request
- Chat Completions Gateway → Routing Policy: selects route
- Chat Completions Gateway → DLP Sanitizer: sanitizes prompt
- Chat Completions Gateway → Context Compression: optimizes context
- Chat Completions Gateway → Semantic Cache: semantic lookup
- Semantic Cache → ChromaDB Store: embeddings and vectors
- Chat Completions Gateway → Groq Proxy: cache miss · Only sanitized payload proceeds upstream.
- Groq Proxy → Groq API: async OpenAI-compatible request
- Chat Completions Gateway → Background Tasks: schedules deferred work
- Background Tasks → Semantic Cache: populate on miss
- Background Tasks → Request Analytics: record telemetry
- Request Analytics → SQLAlchemy Database: persists metrics
- SQLAlchemy Database → Supabase PostgreSQL: managed deployment
- SQLAlchemy Database → Local Log Database: local artifact
- Frontend Entry → Control Plane App: mounts
- Control Plane App → Operations Views: renders
- Operations Views → Chat Completions Gateway: operates gateway