How hackathon-x/text-to-sql works
The product is a Streamlit application for exploring Pagila data through dashboards and natural-language questions. In the dashboard workflow, the UI requests analytics from frontend SQL helpers, which read PostgreSQL. In the chat workflow, the UI sends a question to the FastAPI endpoint; the LangChain SQL agent uses the database and an OpenAI model to produce an answer returned to the UI. The README documents the Pagila database and read-only backend access; unsampled deployment wiring is not expanded here.
Main entry points: agent_service.py SQL agent · main.py Chat and dashboards · endpoints.py Query endpoint · session.py Backend DB session
Components 16
Streamlit frontend
- Chat and dashboards
frontend/main.py - Dashboard queries
frontend/services/queries.py - Frontend DB connection
frontend/db/connection.py - API client
frontend/utils/api_client.py
FastAPI query service
- FastAPI app
backend/app/main.py - Query endpoint
backend/app/api/endpoints.py - Query schemas
backend/app/schemas/query.py - SQL agent
backend/app/services/agent_service.py - Backend DB session
backend/app/db/session.py - Backend settings
backend/app/core/config.py
Pagila data
- Pagila PostgreSQL
- Database schema
sql/01-schema.sql - Pagila sample data
sql/02-insert-data.sql - Read-only access
sql/03-readonly-user.sql
External integrations
- OpenAI LLM
Other components
- User
Connections 17
- User → Chat and dashboards: asks or views
README.md - Chat and dashboards → Dashboard queries: loads dashboards
frontend/main.py - Dashboard queries → Frontend DB connection: runs SQL through
frontend/services/queries.py - Frontend DB connection → Pagila PostgreSQL: connects to
README.md - Chat and dashboards → API client: sends question
frontend/main.py - API client → FastAPI app: POSTs query
frontend/utils/api_client.py - FastAPI app → Query endpoint: registers routes
backend/app/main.py - Query endpoint → Query schemas: validates and returns
backend/app/api/endpoints.py - Query endpoint → SQL agent: processes question
backend/app/api/endpoints.py - SQL agent → Backend DB session: uses database
backend/app/services/agent_service.py - Backend DB session → Backend settings: reads settings
backend/app/db/session.py - SQL agent → Backend settings: reads settings
backend/app/services/agent_service.py - Backend DB session → Pagila PostgreSQL: connects to
README.md - SQL agent → OpenAI LLM: uses model
README.md - Database schema → Pagila PostgreSQL: defines schema
- Pagila sample data → Pagila PostgreSQL: loads sample data
- Read-only access → Pagila PostgreSQL: configures access
README.md