How parth-yangandul-df/querywise works
1. Overall shape
QueryWise is a three-tier system: a FastAPI backend, a React admin console, and an Angular chat UI. The backend owns all business logic, SQL generation/execution, metadata persistence, and LLM orchestration; the two frontends are thin clients with different audiences.
2. Primary user flows
There are two main paths: an admin/curation path in the React app for managing connections, glossary, knowledge, users, and metrics; and an end-user conversational path in the Angular app for asking natural-language questions and reviewing results. Both call the same backend API, but with different UI and role constraints.
3. Backend API boundary
The backend exposes versioned REST endpoints under /api/v1, including auth, users, connections, glossary, knowledge, sessions, query, query history, sample queries, metrics, and health/ready checks. The API layer is mostly a routing and validation boundary; orchestration lives deeper in services and LangGraph nodes.
4. Query orchestration core
The center of the system is the LangGraph-based query pipeline in backend/app/llm/graph. A request flows through history loading, turn resolution, optional follow-up handling, context building, SQL composition, SQL validation, database execution, result interpretation, and history writing. This is the main place where natural language becomes executable SQL and then a user-facing answer.
5. State and turn management
The graph uses explicit state models in backend/app/llm/graph/state.py and related node code to carry context across turns. That state includes conversation history, resolved intent, SQL, execution output, and status flags such as empty-result handling. Recent work also added turn context persistence so follow-up queries can reuse prior context safely.
6. Semantic metadata layer
A separate semantic subsystem builds database-aware context from glossary terms, schema metadata, relationships, sample queries, embeddings, and knowledge chunks. Its job is to improve retrieval and grounding before SQL generation, not to execute queries. This layer is important because QueryWise is not only an LLM-to-SQL system; it is a metadata-augmented system.
7. Data persistence
The metadata store is PostgreSQL with async SQLAlchemy models under backend/app/db/models. It stores users, connections, chat sessions, query history, schema cache, glossary, knowledge, metrics, audit logs, and embeddings-related data. Migrations in Alembic show the schema has evolved to support RBAC, chat sessions, manual relationships, turn context, and auditability.
8. Database connectors
Actual source databases are accessed through connector plugins in backend/app/connectors, with PostgreSQL and SQL Server implementations present. The connector registry lets the backend support multiple database backends while keeping the query pipeline and UI agnostic to the specific source system.
9. Safety and control boundaries
The system explicitly separates SQL generation from execution safety. SQL goes through validation/sanitization before execution, and the backend includes retry/correction logic when LLM-generated SQL fails. Scope constraints such as resource_id and employee_id are part of the architecture, not just UI filters, so end-user access is enforced server-side.
10. Session, history, and streaming
QueryWise persists conversation state per session and query history for follow-ups. It also streams progress over SSE from the query API, which means the frontend can render incremental state rather than waiting for the final answer. Empty-result responses are treated as a first-class outcome with a dedicated status and message.
11. Observability and operational support
The backend includes logging, metrics, rate limiting, Redis integration, query cache, tracing hooks, and exception handlers. These are not decorative; they support safe production operation of an LLM-driven system where latency, retries, and failures are expected. There are also scripts for backup/restore, re-embedding, and metadata seeding.
12. Frontend responsibilities
The React admin console is a standard Vite app with API clients and route-level pages for operational management. The Angular app is a separate chat-focused client with its own service layer and result-table interactions such as search, sort, pagination, and CSV export. The split suggests two independently evolving UIs sharing one backend contract.
13. Deployment and environments
The repo is containerized with Docker Compose for local end-to-end startup and GitHub Actions for backend/frontend deployment workflows. Environment files, startup auto-setup flags, and migration scripts indicate the architecture is designed to be reproducible across local dev, test, and deployment environments.
14. Testing and validation
The test suite mixes backend unit tests, semantic-layer tests, and end-to-end tests for auth, connections, sessions, query flow, streaming, and pipeline behavior. This matches the architecture: most important failures occur at the boundaries between metadata, LLM orchestration, and real database execution, so those boundaries are heavily tested.
Main entry points: v1 API layer · graph Query graph · nodes Graph nodes · models Metadata store
Components 19
Backend
FastAPI API, query orchestration, semantic layer, connectors, and persistence
- API layer · Versioned REST boundary for auth, users, connections, glossary, knowledge, sessions, query, history, sample queries, metrics, and health
backend/app/api/v1 - Query service · Coordinates query requests, session handling, streaming, history, and safety checks
backend/app/services/query_service.py - Query graph · Main natural-language-to-SQL workflow and answer generation pipeline
backend/app/llm/graph - Graph state · Conversation and execution state carried across query turns
backend/app/llm/graph/state.py - Graph nodes · History loading, turn resolution, follow-up handling, context building, SQL composition, validation, execution, interpretation, and history writing
backend/app/llm/graph/nodes - Semantic layer · Builds retrieval and grounding context from glossary, schema, relationships, samples, embeddings, and knowledge
backend/app/semantic - LLM providers · OpenAI, Anthropic, Groq, Ollama, and OpenRouter provider integrations
backend/app/llm/providers - SQL safety · Validates and sanitizes generated SQL before execution
backend/app/llm/agents/sql_validator.py - DB connectors · Pluggable database access for PostgreSQL and SQL Server
backend/app/connectors - Connector registry · Selects the correct source database connector implementation
backend/app/connectors/connector_registry.py - Metadata store · Persistent metadata for users, connections, sessions, history, glossary, knowledge, metrics, audits, schema cache, and sample queries
backend/app/db/models - Migrations · Database evolution for RBAC, sessions, turn context, audit logs, and related metadata
backend/alembic/versions - Core services · Logging, metrics, Redis, caching, rate limiting, tracing, exceptions, and retry support
backend/app/core - Auth & RBAC · JWT auth, protected routes, and server-side role and scope enforcement
backend/app/api/v1/endpoints/auth.py - Query API · Query, history, session, and SSE streaming contract used by both frontends
backend/app/api/v1/endpoints/query.py - Admin APIs · Connections, glossary, knowledge, users, sample queries, metrics, and dictionary management
backend/app/api/v1/endpoints - Health checks · Liveness and readiness endpoints for operational monitoring
backend/app/api/v1/endpoints/health.py
Frontends
Admin console and chat UI clients
- Admin console · Operational UI for managing connections, glossary, knowledge, users, metrics, and history
frontend/src - Chat UI · Conversation-focused UI for natural-language question asking and result review
angular-test/src/app
Connections 22
- Admin console → API layer: calls · Admin console uses the REST API for management actions
- Chat UI → API layer: calls · Chat UI uses the same backend contract for conversational queries
- API layer → Auth & RBAC: routes to · Authentication and role checks are handled at the API boundary
- API layer → Admin APIs: routes to · Operational CRUD endpoints for curation and administration
- API layer → Query API: routes to · Query and streaming endpoints for conversational use
- API layer → Health checks: routes to · Health and readiness checks
- Query API → Query service: delegates to · Query endpoints orchestrate through the service layer
- Query service → Query graph: invokes · Service hands requests to the LangGraph pipeline
- Query graph → Graph state: uses · Workflow state carries turn context and execution results
- Query graph → Graph nodes: composed of · Pipeline is implemented as a sequence of workflow nodes
- Graph nodes → Semantic layer: enriches with · Nodes retrieve semantic grounding and context
- Graph nodes → SQL safety: validates · Generated SQL is checked before execution
- Graph nodes → DB connectors: executes via · Validated SQL runs against the selected source database connector
- DB connectors → Connector registry: selected by · Registry resolves connector implementations by database type
- Query graph → LLM providers: uses · LLM-backed nodes call provider adapters for generation and interpretation
- Semantic layer → Metadata store: reads/writes · Semantic context depends on stored metadata, glossary, embeddings, and cache
- Admin APIs → Metadata store: persists · Admin operations update metadata records in the store
- Query service → Metadata store: persists · Sessions, history, and query outcomes are written to the metadata store
- Core services → API layer: supports · Cross-cutting runtime behavior wraps the API layer
- Migrations → Metadata store: evolves · Alembic migrations track schema changes for stored metadata
- Admin console → Auth & RBAC: enforces · Protected routes and role-aware UI depend on auth state
- Chat UI → Query API: streams · Chat client consumes incremental query progress and results