# agenticfabriq/mnemiq architecture

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

- Interactive diagram: https://gitdiagram.com/agenticfabriq/mnemiq
- Repository: https://github.com/agenticfabriq/mnemiq

## Overview

mnemiq is a configurable, self-hosted text-to-SQL engine: a user asks a database question, and receives an answer or an explicit refusal with SQL and trace information. Its documented workflow builds schema and semantic knowledge, retrieves only authorized context, generates SQL, checks it deterministically, executes it under policy, and verifies the result. Configuration, identity and grants govern that flow; the repository also provides a workbench, MCP/API access, Superset integration, and an evaluation harness. The main pipeline is documented in the README; some subsystem links below rely on the SOURCE INDEX, so unsampled internals are not expanded.

Main entry points: [`src/mnemiq/runtime.py`](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/runtime.py) (Request runtime), [`src/mnemiq/generate/plan_query.py`](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/generate/plan_query.py) (SQL generation and decision), [`src/mnemiq/sql/policy.py`](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/sql/policy.py) (SQL policy checks), [`src/mnemiq/semantic/retrieval.py`](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/semantic/retrieval.py) (Scoped retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_knowledge["Schema knowledge"]
  node_enrichment["Schema enrichment<br/>[pipeline.py]"]
  node_semantic["Semantic contract<br/>[semantic.py]"]
  node_retrieval["Scoped retrieval<br/>[retrieval.py]"]
end

subgraph group_governance["Configuration and access"]
  node_config["Settings and profiles<br/>[config.py]"]
  node_identity["Identity and grants<br/>[identity_map.py]"]
  node_grant_rules["Authorization grants<br/>[grants.py]"]
end

subgraph group_answer["Question answering"]
  node_runtime["Request runtime<br/>[runtime.py]"]
  node_agent["Agent loop and modes<br/>[loop.py]"]
  node_generation["SQL generation and decision<br/>[plan_query.py]"]
  node_verification["Answer verification<br/>[verifier.py]"]
end

subgraph group_execution["SQL execution"]
  node_sql_guard["SQL policy checks<br/>[policy.py]"]
  node_sql_views["View validation<br/>[views.py]"]
  node_sql_scope["SQL scope and identifiers<br/>[scope.py]"]
  node_executor["Query execution<br/>[runner.py]"]
end

subgraph group_interfaces["Interfaces and evaluation"]
  node_server["HTTP and MCP service<br/>[app.py]"]
  node_workbench["Browser workbench<br/>[App.tsx]"]
  node_superset["Superset integration<br/>[client.py]"]
  node_superset_settings["Superset mode rules<br/>[settings.py]"]
  node_eval["Evaluation harness<br/>[engine.py]"]
end

node_user(("Questioner"))
node_database[("Source database")]
node_model(("Configured model"))

node_user -->|"asks"| node_workbench
node_workbench -.->|"sends question"| node_server
node_server -->|"dispatches"| node_runtime
node_config -->|"configures"| node_runtime
node_runtime -->|"resolves identity"| node_identity
node_identity -->|"provides grants"| node_grant_rules
node_enrichment -->|"profiles schema"| node_database
node_enrichment -->|"builds context"| node_semantic
node_runtime -->|"retrieves context"| node_retrieval
node_retrieval -->|"applies grants"| node_grant_rules
node_runtime -->|"runs"| node_agent
node_agent -.->|"plans SQL"| node_generation
node_generation -->|"proposes SQL"| node_model
node_generation -->|"checks proposal"| node_sql_guard
node_sql_guard -->|"checks views"| node_sql_views
node_sql_guard -->|"checks scope"| node_sql_scope
node_runtime -->|"executes approved SQL"| node_executor
node_executor -->|"runs query"| node_database
node_runtime -->|"verifies result"| node_verification
node_verification -->|"returns answer or deferral"| node_user
node_superset_settings -->|"constrains mode"| node_superset
node_superset -->|"queries via Superset"| node_database
node_eval -->|"measures answers"| node_agent
node_eval -->|"uses retrieval"| node_retrieval

click node_config "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/config.py"
click node_identity "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/auth/identity_map.py"
click node_grant_rules "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/authz/grants.py"
click node_enrichment "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/enrichment/pipeline.py"
click node_semantic "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/contract/semantic.py"
click node_retrieval "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/semantic/retrieval.py"
click node_runtime "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/runtime.py"
click node_agent "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/agent/loop.py"
click node_generation "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/generate/plan_query.py"
click node_sql_guard "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/sql/policy.py"
click node_sql_views "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/sql/views.py"
click node_sql_scope "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/sql/scope.py"
click node_executor "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/execute/runner.py"
click node_verification "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/verify/verifier.py"
click node_server "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/server/app.py"
click node_workbench "https://github.com/agenticfabriq/mnemiq/blob/main/workbench/src/App.tsx"
click node_superset "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/superset/client.py"
click node_superset_settings "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/superset/settings.py"
click node_eval "https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/eval/engine.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_enrichment,node_semantic,node_retrieval toneBlue
class node_config,node_identity,node_grant_rules,node_database toneAmber
class node_runtime,node_agent,node_generation,node_verification toneMint
class node_sql_guard,node_sql_views,node_sql_scope,node_executor toneRose
class node_server,node_workbench,node_superset,node_superset_settings,node_eval,node_user,node_model toneIndigo
```

## Components

### Schema knowledge

- [Schema enrichment](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/enrichment/pipeline.py): `src/mnemiq/enrichment/pipeline.py`
- [Semantic contract](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/contract/semantic.py): `src/mnemiq/contract/semantic.py`
- [Scoped retrieval](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/semantic/retrieval.py): `src/mnemiq/semantic/retrieval.py`

### Configuration and access

- [Settings and profiles](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/config.py): `src/mnemiq/config.py`
- [Identity and grants](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/auth/identity_map.py): `src/mnemiq/auth/identity_map.py`
- [Authorization grants](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/authz/grants.py): `src/mnemiq/authz/grants.py`

### Question answering

- [Request runtime](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/runtime.py): `src/mnemiq/runtime.py`
- [Agent loop and modes](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/agent/loop.py): `src/mnemiq/agent/loop.py`
- [SQL generation and decision](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/generate/plan_query.py): `src/mnemiq/generate/plan_query.py`
- [Answer verification](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/verify/verifier.py): `src/mnemiq/verify/verifier.py`

### SQL execution

- [SQL policy checks](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/sql/policy.py): `src/mnemiq/sql/policy.py`
- [View validation](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/sql/views.py): `src/mnemiq/sql/views.py`
- [SQL scope and identifiers](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/sql/scope.py): `src/mnemiq/sql/scope.py`
- [Query execution](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/execute/runner.py): `src/mnemiq/execute/runner.py`

### Interfaces and evaluation

- [HTTP and MCP service](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/server/app.py): `src/mnemiq/server/app.py`
- [Browser workbench](https://github.com/agenticfabriq/mnemiq/blob/main/workbench/src/App.tsx): `workbench/src/App.tsx`
- [Superset integration](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/superset/client.py): `src/mnemiq/superset/client.py`
- [Superset mode rules](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/superset/settings.py): `src/mnemiq/superset/settings.py`
- [Evaluation harness](https://github.com/agenticfabriq/mnemiq/blob/main/src/mnemiq/eval/engine.py): `src/mnemiq/eval/engine.py`

### Other components

- **Questioner**
- **Source database**
- **Configured model**

## Connections

- Questioner → Browser workbench: asks (evidence: `README.md`)
- Browser workbench → HTTP and MCP service: sends question
- HTTP and MCP service → Request runtime: dispatches (evidence: `src/mnemiq/server/app.py`)
- Settings and profiles → Request runtime: configures (evidence: `src/mnemiq/runtime.py`)
- Request runtime → Identity and grants: resolves identity (evidence: `src/mnemiq/runtime.py`)
- Identity and grants → Authorization grants: provides grants
- Schema enrichment → Source database: profiles schema (evidence: `src/mnemiq/enrichment/pipeline.py`)
- Schema enrichment → Semantic contract: builds context (evidence: `src/mnemiq/enrichment/pipeline.py`)
- Request runtime → Scoped retrieval: retrieves context (evidence: `src/mnemiq/runtime.py`)
- Scoped retrieval → Authorization grants: applies grants (evidence: `src/mnemiq/semantic/retrieval.py`)
- Request runtime → Agent loop and modes: runs (evidence: `src/mnemiq/runtime.py`)
- Agent loop and modes → SQL generation and decision: plans SQL
- SQL generation and decision → Configured model: proposes SQL (evidence: `README.md`)
- SQL generation and decision → SQL policy checks: checks proposal (evidence: `src/mnemiq/generate/plan_query.py`)
- SQL policy checks → View validation: checks views (evidence: `src/mnemiq/sql/policy.py`)
- SQL policy checks → SQL scope and identifiers: checks scope (evidence: `src/mnemiq/sql/policy.py`)
- Request runtime → Query execution: executes approved SQL (evidence: `src/mnemiq/runtime.py`)
- Query execution → Source database: runs query (evidence: `README.md`)
- Request runtime → Answer verification: verifies result (evidence: `src/mnemiq/runtime.py`)
- Answer verification → Questioner: returns answer or deferral (evidence: `README.md`)
- Superset mode rules → Superset integration: constrains mode (evidence: `src/mnemiq/superset/settings.py`)
- Superset integration → Source database: queries via Superset
- Evaluation harness → Agent loop and modes: measures answers (evidence: `src/mnemiq/eval/engine.py`)
- Evaluation harness → Scoped retrieval: uses retrieval (evidence: `src/mnemiq/eval/engine.py`)
