# sarthakdeshmukh34887-ui/sentinelsql architecture

> Architecture diagram of the GitHub repository sarthakdeshmukh34887-ui/sentinelsql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sarthakdeshmukh34887-ui/sentinelsql
- Repository: https://github.com/sarthakdeshmukh34887-ui/sentinelsql

## Overview

SentinelSQL turns a natural-language question into guarded PostgreSQL results. The user enters through the CLI or production FastAPI gateway; the trusted pipeline screens input, assembles permission-filtered schema and approved metrics, obtains an untrusted structured draft, validates it deterministically, executes it read-only, verifies results, then masks and renders output. The diagram preserves the documented trust boundaries and major runtime subsystems. Some pipeline stages and wiring are unsampled; those links are omitted or marked unverified rather than inferred as certain.

Main entry points: [`sentinelsql/orchestrator/pipeline.py`](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/orchestrator/pipeline.py) (Query pipeline), [`sentinelsql/cli/app.py`](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/cli/app.py) (CLI), [`sentinelsql/catalog/schema.py`](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/catalog/schema.py) (Schema catalog), [`sentinelsql/api/gateway.py`](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/api/gateway.py) (REST gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI<br/>[app.py]"]
  node_gateway["REST gateway<br/>[gateway.py]"]
end

subgraph group_control["Trusted query control"]
  node_pipeline["Query pipeline<br/>[pipeline.py]"]
  node_llm["LLM provider<br/>[providers.py]"]
  node_validator["AST validator<br/>[ast_validator.py]"]
  node_eval["Evaluation runner<br/>[runner.py]"]
end

subgraph group_data["Catalog and database"]
  node_catalog["Schema catalog<br/>[schema.py]"]
  node_metrics["Metrics catalog<br/>[metrics.py]"]
  node_executor["Query executor<br/>[executor.py]"]
  node_engine["Read-only engine<br/>[engine.py]"]
end

subgraph group_safety["Security and operations"]
  node_screen["Input screening<br/>[screener.py]"]
  node_verifier["Result verifier<br/>[auditor.py]"]
  node_guard["Result guard<br/>[renderer.py]"]
  node_cache["Two-tier cache<br/>[manager.py]"]
  node_cache_backends["Cache backends<br/>[backends.py]"]
  node_audit["Audit logger<br/>[logger.py]"]
  node_config["Settings<br/>[config.py]"]
end

node_user(("Analyst"))
node_llm_service(("External LLM"))
node_postgres[("PostgreSQL")]

node_user -->|"asks via"| node_cli
node_user -->|"asks via"| node_gateway
node_cli -.->|"submits query"| node_pipeline
node_cli -->|"starts server"| node_gateway
node_gateway -.->|"routes query"| node_pipeline
node_pipeline -.->|"screens input"| node_screen
node_pipeline -.->|"builds snapshot"| node_catalog
node_catalog -->|"includes metrics"| node_metrics
node_pipeline -.->|"requests draft"| node_llm
node_llm -.->|"generates draft"| node_llm_service
node_pipeline -.->|"validates draft"| node_validator
node_pipeline -->|"executes plan"| node_executor
node_executor -->|"opens transaction"| node_engine
node_engine -->|"queries read-only"| node_postgres
node_pipeline -->|"verifies results"| node_verifier
node_pipeline -.->|"guards output"| node_guard
node_pipeline -.->|"checks caches"| node_cache
node_cache -->|"uses backend"| node_cache_backends
node_pipeline -->|"emits event"| node_audit
node_catalog -->|"introspects schema"| node_engine
node_eval -.->|"evaluates queries"| node_pipeline

click node_cli "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/cli/app.py"
click node_gateway "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/api/gateway.py"
click node_pipeline "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/orchestrator/pipeline.py"
click node_screen "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/screening/screener.py"
click node_catalog "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/catalog/schema.py"
click node_metrics "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/catalog/metrics.py"
click node_llm "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/llm/providers.py"
click node_validator "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/validator/ast_validator.py"
click node_executor "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/db/executor.py"
click node_engine "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/db/engine.py"
click node_verifier "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/verifier/auditor.py"
click node_guard "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/guard/renderer.py"
click node_cache "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/cache/manager.py"
click node_cache_backends "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/cache/backends.py"
click node_audit "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/audit/logger.py"
click node_config "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/config.py"
click node_eval "https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/eval/runner.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_cli,node_gateway toneBlue
class node_pipeline,node_llm,node_validator,node_eval,node_postgres toneAmber
class node_catalog,node_metrics,node_executor,node_engine toneMint
class node_screen,node_verifier,node_guard,node_cache,node_cache_backends,node_audit,node_config toneRose
class node_user,node_llm_service toneIndigo
```

## Components

### User interfaces

- [CLI](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/cli/app.py): `sentinelsql/cli/app.py`
- [REST gateway](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/api/gateway.py): `sentinelsql/api/gateway.py`

### Trusted query control

- [Query pipeline](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/orchestrator/pipeline.py): `sentinelsql/orchestrator/pipeline.py`
- [LLM provider](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/llm/providers.py): `sentinelsql/llm/providers.py`
- [AST validator](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/validator/ast_validator.py): `sentinelsql/validator/ast_validator.py`
- [Evaluation runner](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/eval/runner.py): `sentinelsql/eval/runner.py`

### Catalog and database

- [Schema catalog](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/catalog/schema.py): `sentinelsql/catalog/schema.py`
- [Metrics catalog](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/catalog/metrics.py): `sentinelsql/catalog/metrics.py`
- [Query executor](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/db/executor.py): `sentinelsql/db/executor.py`
- [Read-only engine](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/db/engine.py): `sentinelsql/db/engine.py`

### Security and operations

- [Input screening](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/screening/screener.py): `sentinelsql/screening/screener.py`
- [Result verifier](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/verifier/auditor.py): `sentinelsql/verifier/auditor.py`
- [Result guard](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/guard/renderer.py): `sentinelsql/guard/renderer.py`
- [Two-tier cache](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/cache/manager.py): `sentinelsql/cache/manager.py`
- [Cache backends](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/cache/backends.py): `sentinelsql/cache/backends.py`
- [Audit logger](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/audit/logger.py): `sentinelsql/audit/logger.py`
- [Settings](https://github.com/sarthakdeshmukh34887-ui/sentinelsql/blob/main/sentinelsql/config.py): `sentinelsql/config.py`

### Other components

- **Analyst**
- **External LLM**
- **PostgreSQL**

## Connections

- Analyst → CLI: asks via (evidence: `README.md`)
- Analyst → REST gateway: asks via (evidence: `README.md`)
- CLI → Query pipeline: submits query
- CLI → REST gateway: starts server (evidence: `sentinelsql/cli/app.py`)
- REST gateway → Query pipeline: routes query
- Query pipeline → Input screening: screens input
- Query pipeline → Schema catalog: builds snapshot
- Schema catalog → Metrics catalog: includes metrics (evidence: `sentinelsql/catalog/schema.py`)
- Query pipeline → LLM provider: requests draft
- LLM provider → External LLM: generates draft
- Query pipeline → AST validator: validates draft
- Query pipeline → Query executor: executes plan (evidence: `sentinelsql/orchestrator/pipeline.py`)
- Query executor → Read-only engine: opens transaction (evidence: `sentinelsql/db/executor.py`)
- Read-only engine → PostgreSQL: queries read-only (evidence: `sentinelsql/db/engine.py`)
- Query pipeline → Result verifier: verifies results (evidence: `sentinelsql/orchestrator/pipeline.py`)
- Query pipeline → Result guard: guards output
- Query pipeline → Two-tier cache: checks caches
- Two-tier cache → Cache backends: uses backend (evidence: `sentinelsql/cache/manager.py`)
- Query pipeline → Audit logger: emits event (evidence: `sentinelsql/orchestrator/pipeline.py`)
- Schema catalog → Read-only engine: introspects schema (evidence: `sentinelsql/catalog/schema.py`)
- Evaluation runner → Query pipeline: evaluates queries
