# brijeshvadalia/sql-debug-env architecture

> Architecture diagram of the GitHub repository brijeshvadalia/sql-debug-env, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/brijeshvadalia/sql-debug-env
- Repository: https://github.com/brijeshvadalia/sql-debug-env

## Overview

1. This repository is a Dockerized, OpenEnv-compatible SQL debugging environment. The central product is a FastAPI service that runs SQL tasks against a seeded SQLite database and scores agent-submitted queries episode by episode.

2. The main runtime lives under `server/`. `server/app.py` is the HTTP entrypoint and exposes the environment API described in the README: `/reset`, `/step`, `/evaluate`, `/hint`, `/curriculum`, `/leaderboard`, `/tasks`, `/stats`, plus health and metadata endpoints. This is the boundary that agents and clients talk to.

3. `server/environment.py` is the core orchestration layer. It likely owns episode state, task selection, query execution, reward calculation, step counting, history tracking, and the transition from one observation to the next. This is where the “environment” semantics are implemented, not just raw request handling.

4. The database layer is intentionally self-contained. `server/db/seed.sql` defines the SQLite schema and initial data for customers, products, orders, order_items, and reviews. The README makes clear the database is in-memory or locally managed, so the environment has no external data-service dependency.

5. Task definitions are separated from execution logic in `server/tasks/`. This package appears to hold the eight task configurations: broken SQL, task descriptions, step limits, thresholds, and likely the metadata needed for curriculum and batch evaluation.

6. Grading is isolated in `server/graders/`. That boundary matters: task-specific correctness, partial credit, and performance-sensitive scoring are handled separately from the API and from the database seed. The README’s reward breakdown, query complexity, and performance metrics suggest graders compute deterministic scores and analysis from executed SQL and query plans.

7. `models.py` defines the shared typed contract for the environment. The README shows `SQLAction`, `SQLObservation`, and several nested analytics structures, so this file is the schema boundary between server, client, tests, and any external agent code.

8. `client.py` is the consumer-side SDK for interacting with the environment. It wraps the HTTP API into a Python interface for `reset`, `step`, and related calls, making the repo usable as both a service and a library for agent workflows.

9. `inference.py` is the evaluation/baseline runner. It connects an LLM client to the environment, submits SQL repairs, and measures performance across tasks. This is the main integration point with external model endpoints, but it is not required for the environment itself to run.

10. `validate_submission.py` is a submission-time contract checker. Together with `openenv.yaml`, `Dockerfile`, `pyproject.toml`, `requirements.txt`, and `uv.lock`, it forms the packaging and deployment layer that ensures the repo can be built reproducibly and exposed as an OpenEnv space.

11. The static UI is lightweight and auxiliary. `server/homepage.html` and `static/tester.html` provide a human-facing homepage and interactive tester, but they sit on top of the same API and do not contain the environment logic.

12. Tests are focused on environment behavior rather than frontend behavior. `tests/test_environment.py` and `tests/conftest.py` validate the server/environment contract, likely checking task resets, scoring, state transitions, and deterministic outputs.

13. From an architecture-diagram perspective, the key flow is: client or agent submits an action → FastAPI route in `server/app.py` → environment logic in `server/environment.py` → SQLite query execution against seeded data → grader computes reward and diagnostics → observation returned to the client. Optional branches include hinting, curriculum progression, and batch evaluation.

14. The important boundary in this repo is that all “world state” is inside the environment process: task state, episode history, scoring, and the database. External systems are only used by tooling around the environment, such as inference scripts or deployment platforms.

Main entry points: [`server/app.py`](https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/app.py) (API server), [`server/environment.py`](https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/environment.py) (Environment), [`validate_submission.py`](https://github.com/brijeshvadalia/sql-debug-env/blob/main/validate_submission.py) (Submission check), [`inference.py`](https://github.com/brijeshvadalia/sql-debug-env/blob/main/inference.py) (Baseline runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_server_app["API server<br/>FastAPI entrypoint<br/>[app.py]"]
  node_server_env["Environment<br/>orchestrator<br/>[environment.py]"]
end

subgraph group_data["Data & rules"]
  node_db_seed[("Seed DB<br/>sqlite schema<br/>[seed.sql]")]
  node_tasks_pkg["Tasks<br/>task configs<br/>[__init__.py]"]
  node_graders_pkg["Graders<br/>scoring rules<br/>[__init__.py]"]
  node_models["Models<br/>typed contracts<br/>[models.py]"]
end

subgraph group_tooling["Tooling"]
  node_client["Client SDK<br/>python client<br/>[client.py]"]
  node_inference["Baseline runner<br/>llm eval<br/>[inference.py]"]
  node_validate["Submission check<br/>validator"]
  node_openenv["OpenEnv spec<br/>deployment config<br/>[openenv.yaml]"]
  node_dockerfile["Container build<br/>build config"]
  node_deps["Python deps<br/>package config<br/>[pyproject.toml]"]
end

subgraph group_ui["UI & tests"]
  node_server_homepage["Homepage<br/>static page<br/>[homepage.html]"]
  node_static_tester["Tester UI<br/>static page<br/>[tester.html]"]
  node_server_tests["Env tests<br/>behavior tests"]
  node_conftest["Test setup<br/>pytest fixtures<br/>[conftest.py]"]
end

node_client -->|"calls API"| node_server_app
node_server_app -->|"delegates"| node_server_env
node_server_env -->|"executes SQL"| node_db_seed
node_server_env -->|"selects task"| node_tasks_pkg
node_server_env -->|"scores"| node_graders_pkg
node_server_env -->|"uses schemas"| node_models
node_server_app -->|"serializes"| node_models
node_inference -->|"uses SDK"| node_client
node_inference -->|"drives eval"| node_server_app
node_validate -->|"checks spec"| node_openenv
node_validate -->|"verifies build"| node_dockerfile
node_validate -->|"verifies deps"| node_deps
node_server_tests -->|"tests behavior"| node_server_env
node_server_tests -->|"uses fixtures"| node_conftest
node_server_app -->|"serves page"| node_server_homepage
node_server_app -->|"serves UI"| node_static_tester

click node_server_app "https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/app.py"
click node_server_env "https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/environment.py"
click node_server_homepage "https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/homepage.html"
click node_static_tester "https://github.com/brijeshvadalia/sql-debug-env/blob/main/static/tester.html"
click node_db_seed "https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/db/seed.sql"
click node_tasks_pkg "https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/tasks/__init__.py"
click node_graders_pkg "https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/graders/__init__.py"
click node_models "https://github.com/brijeshvadalia/sql-debug-env/blob/main/models.py"
click node_client "https://github.com/brijeshvadalia/sql-debug-env/blob/main/client.py"
click node_inference "https://github.com/brijeshvadalia/sql-debug-env/blob/main/inference.py"
click node_validate "https://github.com/brijeshvadalia/sql-debug-env/blob/main/validate_submission.py"
click node_openenv "https://github.com/brijeshvadalia/sql-debug-env/blob/main/openenv.yaml"
click node_dockerfile "https://github.com/brijeshvadalia/sql-debug-env/tree/main/Dockerfile"
click node_deps "https://github.com/brijeshvadalia/sql-debug-env/blob/main/pyproject.toml"
click node_server_tests "https://github.com/brijeshvadalia/sql-debug-env/blob/main/tests/test_environment.py"
click node_conftest "https://github.com/brijeshvadalia/sql-debug-env/blob/main/tests/conftest.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server_app,node_server_env toneBlue
class node_db_seed,node_tasks_pkg,node_graders_pkg,node_models toneAmber
class node_client,node_inference,node_validate,node_openenv,node_dockerfile,node_deps toneMint
class node_server_homepage,node_static_tester,node_server_tests,node_conftest toneRose
```

## Components

### Runtime

Live environment service and its core execution path

- [API server](https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/app.py): FastAPI entrypoint · HTTP boundary exposing the environment endpoints · `server/app.py`
- [Environment](https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/environment.py): orchestrator · Episode state, task flow, query execution, scoring, and observations · `server/environment.py`

### Data & rules

Seeded database, tasks, and grading logic

- [Seed DB](https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/db/seed.sql): sqlite schema · Customers, products, orders, items, and reviews seed data · `server/db/seed.sql`
- [Tasks](https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/tasks/__init__.py): task configs · Task definitions, limits, thresholds, and curriculum metadata · `server/tasks/__init__.py`
- [Graders](https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/graders/__init__.py): scoring rules · Deterministic task scoring and SQL analysis boundaries · `server/graders/__init__.py`
- [Models](https://github.com/brijeshvadalia/sql-debug-env/blob/main/models.py): typed contracts · Shared request, response, and analytics schemas · `models.py`

### Tooling

Client, evaluation, packaging, and submission support

- [Client SDK](https://github.com/brijeshvadalia/sql-debug-env/blob/main/client.py): python client · Convenience wrapper around the HTTP environment API · `client.py`
- [Baseline runner](https://github.com/brijeshvadalia/sql-debug-env/blob/main/inference.py): llm eval · Runs model-driven SQL repair against the environment · `inference.py`
- [Submission check](https://github.com/brijeshvadalia/sql-debug-env/blob/main/validate_submission.py): validator · Verifies submission contract and packaging expectations · `validate_submission.py`
- [OpenEnv spec](https://github.com/brijeshvadalia/sql-debug-env/blob/main/openenv.yaml): deployment config · Environment metadata for packaging and platform integration · `openenv.yaml`
- [Container build](https://github.com/brijeshvadalia/sql-debug-env/tree/main/Dockerfile): build config · Containerization entry for the service runtime · `Dockerfile`
- [Python deps](https://github.com/brijeshvadalia/sql-debug-env/blob/main/pyproject.toml): package config · Reproducible dependency and lockfile set · `pyproject.toml`

### UI & tests

Lightweight web UI and behavioral tests

- [Homepage](https://github.com/brijeshvadalia/sql-debug-env/blob/main/server/homepage.html): static page · Human-facing landing page for the service · `server/homepage.html`
- [Tester UI](https://github.com/brijeshvadalia/sql-debug-env/blob/main/static/tester.html): static page · Interactive browser tester layered on the API · `static/tester.html`
- [Env tests](https://github.com/brijeshvadalia/sql-debug-env/blob/main/tests/test_environment.py): behavior tests · Validates environment resets, scoring, and state transitions · `tests/test_environment.py`
- [Test setup](https://github.com/brijeshvadalia/sql-debug-env/blob/main/tests/conftest.py): pytest fixtures · Shared fixtures for environment behavior tests · `tests/conftest.py`

## Connections

- Client SDK → API server: calls API · Client submits reset, step, and related requests to the service
- API server → Environment: delegates · Routes HTTP actions into environment orchestration
- Environment → Seed DB: executes SQL · Runs agent queries against the seeded SQLite dataset
- Environment → Tasks: selects task · Loads task configuration and episode metadata
- Environment → Graders: scores · Computes reward and diagnostics for submitted SQL
- Environment → Models: uses schemas · Produces and consumes typed actions and observations
- API server → Models: serializes · HTTP layer exposes typed payloads to clients
- Baseline runner → Client SDK: uses SDK · Runner interacts with the environment through the client wrapper
- Baseline runner → API server: drives eval · Baseline evaluation ultimately exercises the API
- Submission check → OpenEnv spec: checks spec · Submission validation uses the OpenEnv contract metadata
- Submission check → Container build: verifies build · Ensures the packaged runtime can be built and shipped
- Submission check → Python deps: verifies deps · Checks reproducible dependency configuration
- Env tests → Environment: tests behavior · Exercises environment semantics and deterministic outcomes
- Env tests → Test setup: uses fixtures · Shares setup for environment state and test resources
- API server → Homepage: serves page · Exposes the lightweight homepage from the API service
- API server → Tester UI: serves UI · Provides the interactive tester as a thin client-facing layer
