How pragatheeswaran-sv/llm_gateway works
LLM Gateway is a FastAPI service that registers client applications, issues access tokens, and generates or updates database schemas as DBML. The main workflow validates a bearer token, builds a prompt from the user's query and existing DBML, calls an LLM directly or through configured fallback models, and returns DBML, an explanation, and optionally a summary; request outcomes are logged. Registration and token issuance form a separate onboarding workflow. Some service and fallback source is excerpted only partially, so uncertain internal call details are omitted.
Main entry points: service.py Generation orchestration · main.py FastAPI app · api.py Generation API · database.py Database engine and sessions
Components 15
API entry
- FastAPI app
src/main.py - Generation API
src/conversation/api.py
Application onboarding
- Registration API
src/register_application/api.py - Registration service
src/register_application/service.py - Application record
src/register_application/models.py - Credential and token helpers
src/utils/helper.py
DBML generation
- Generation orchestration
src/conversation/service.py - Request and response schemas
src/conversation/schemas.py - Fallback selection and provider calls
src/conversation/fallback.py
Persistence and configuration
- Conversation and fallback records
src/conversation/models.py - Request logs
src/conversation/models.py - Database engine and sessions
src/database.py - Runtime settings
src/config.py
Other components
- API client
- LLM provider
Connections 21
- API client → FastAPI app: sends requests
src/main.py - FastAPI app → Registration API: routes requests
src/main.py - FastAPI app → Generation API: routes requests
src/main.py - Registration API → Registration service: calls
src/register_application/api.py - Registration service → Application record: reads and writes
src/register_application/service.py - Registration service → Credential and token helpers: uses credentials
src/register_application/service.py - Registration API → API client: returns credentials or token
src/register_application/api.py - Generation API → Request and response schemas: validates and shapes
src/conversation/api.py - Generation API → Generation orchestration: calls
src/conversation/api.py - Generation orchestration → Credential and token helpers: validates token
src/conversation/service.py - Generation orchestration → Fallback selection and provider calls: calls provider logic
src/conversation/service.py - Fallback selection and provider calls → LLM provider: sends completion request
src/conversation/fallback.py - Generation orchestration → Conversation and fallback records: reads fallback state
src/conversation/service.py - Generation orchestration → Request logs: records attempts
src/conversation/service.py - Generation API → Request logs: starts and finishes logs
src/conversation/api.py - Application record → Database engine and sessions: uses ORM base
src/register_application/models.py - Conversation and fallback records → Database engine and sessions: uses ORM base
src/conversation/models.py - FastAPI app → Database engine and sessions: creates tables at startup
src/main.py - Database engine and sessions → Runtime settings: reads database URL
src/database.py - Credential and token helpers → Runtime settings: reads token settings
src/utils/helper.py - Generation orchestration → Runtime settings: reads generation settings
src/conversation/service.py