# horserider2146/quantum-circuit-dbms architecture

> Architecture diagram of the GitHub repository horserider2146/quantum-circuit-dbms, 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/horserider2146/quantum-circuit-dbms
- Repository: https://github.com/horserider2146/quantum-circuit-dbms

## Overview

1. **Overall shape**
   This repository is a local, Python-based DBMS stack with three main layers: a **SQLite data store**, a **FastAPI backend**, and a **Streamlit dashboard**. The system is centered on quantum circuit experiment records and is designed around CRUD, search, analytics, and comparison workflows.

2. **Data layer**
   The core persistence model is a **normalized SQLite database** with **five tables** linked by `circuit_id`: `circuits`, `qubits`, `gates`, `results`, and `noise_models`. `circuits` is the primary business entity; the other tables store hardware, circuit composition, execution outcomes, and noise characteristics. This makes the database the authoritative source of truth and forces most read/write flows to join across related tables.

3. **Backend service boundary**
   `backend/main.py` is the main application service and appears to contain the complete REST API surface. It exposes circuit CRUD, search, statistics, metadata lookup, bulk operations, filter presets, audit/data-quality endpoints, and quantum-specific analytics/recommendation endpoints. `backend/models.py` holds the Pydantic schemas that define request/response contracts between the API and clients.

4. **API as the integration contract**
   The architecture is API-first for the dashboard path: the frontend does not need direct database access when using `frontend/dashboard_api.py`. Instead, Streamlit calls the FastAPI service over HTTP, authenticated with an `X-API-Key` header. This creates a clean boundary between presentation and data access and makes the backend the only component that should encode business rules.

5. **Frontend composition**
   There are two Streamlit entry points in `frontend/`. `dashboard_api.py` is the API-driven dashboard used for the current course requirements and operational workflows. `dashboard.py` is an older/direct-DB dashboard that likely talks to SQLite without the backend in the loop. Architecturally, that means the repo contains both a **service-mediated UI path** and a **legacy direct-database UI path**.

6. **Main data flows**
   The primary runtime flow is: **SQLite DB → FastAPI endpoints → Streamlit UI** for reads, searches, comparisons, and stats. Write flows go the same way in reverse: **Streamlit forms or API clients → FastAPI validation/business logic → SQLite updates**. The backend also likely performs joins across the five tables when returning a “full circuit” detail view.

7. **Data ingestion and database creation**
   The repository is built around an offline ETL-style ingestion process. `scripts/load_excel_to_sqlite.py` and the setup instructions indicate the source data begins as an Excel workbook and is loaded into SQLite. `scripts/generate_synthetic_db.py` suggests an alternate path for producing sample data, which is useful for demos or when the real dataset is unavailable.

8. **Operational and validation scripts**
   `scripts/validate_project_requirements.py` is a repo-specific quality gate, likely used to verify that the project meets assignment constraints. `sql/sample_queries.sql` provides ad hoc SQL examples for direct database exploration. These are support artifacts around the core app, not runtime dependencies.

9. **Documentation and contract artifacts**
   The `docs/` directory contains architecture and integration artifacts: `API_DOCUMENTATION.md`, `ER_DIAGRAM.md`, and `postman_collection.json`. Together these define the service contract, the relational shape of the data, and a testable request collection for the API. For diagramming, these docs are important because they reflect the intended boundaries and database relationships more clearly than the code tree alone.

10. **Deployment/runtime model**
    The repo runs as two local Python processes: **Uvicorn serving FastAPI** on port 8000 and **Streamlit serving the dashboard** on port 8501. The backend requires an API key, and the frontend is configured with `API_BASE_URL` to point at the backend. This is a single-machine, developer-friendly deployment rather than a distributed production architecture.

11. **External dependencies that matter**
    The stack depends on **SQLite**, **FastAPI/Pydantic**, **Streamlit**, **pandas**, **openpyxl**, and **Uvicorn**. These choices shape the architecture: SQLite keeps persistence embedded and file-based, FastAPI provides typed HTTP boundaries, and Streamlit provides a rapid interactive UI without a separate frontend build system.

12. **Key architectural takeaway**
    The most important diagram boundary is between **presentation**, **application service**, and **database**. The backend owns schema-aware operations and validation; the dashboard is a client; the SQLite file is the persistent store; and the scripts are one-time or offline tooling for building and validating that store. The repo is therefore best understood as a compact, local DBMS application with an API layer wrapped around a normalized relational dataset.

Main entry points: [`backend/main.py`](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/backend/main.py) (FastAPI app), [`frontend/dashboard_api.py`](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/frontend/dashboard_api.py) (API dashboard), [`frontend/dashboard.py`](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/frontend/dashboard.py) (Legacy dashboard), [`scripts/load_excel_to_sqlite.py`](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/scripts/load_excel_to_sqlite.py) (Excel loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data store"]
  node_sqlite_db[("SQLite DB<br/>relational store")]
  node_circuits["Circuits<br/>core table"]
  node_qubits["Qubits<br/>table"]
  node_gates["Gates<br/>table"]
  node_results["Results<br/>table"]
  node_noise_models["Noise models<br/>table"]
end

subgraph group_service["Backend service"]
  node_backend_main["FastAPI app<br/>REST service<br/>[main.py]"]
  node_backend_models["API models<br/>Pydantic schemas<br/>[models.py]"]
end

subgraph group_ui["Frontends"]
  node_dashboard_api["API dashboard<br/>Streamlit UI<br/>[dashboard_api.py]"]
  node_dashboard_legacy["Legacy dashboard<br/>Streamlit UI<br/>[dashboard.py]"]
end

subgraph group_tooling["Tooling"]
  node_load_excel["Excel loader<br/>ETL script"]
  node_synthetic_db["Synthetic DB<br/>data generator"]
  node_validate_req["Requirements check<br/>validation script"]
  node_sample_sql["Sample queries<br/>SQL examples<br/>[sample_queries.sql]"]
end

subgraph group_docs["Docs"]
  node_api_docs["API docs<br/>documentation"]
  node_er_diagram["ER diagram<br/>schema doc<br/>[ER_DIAGRAM.md]"]
  node_postman["Postman coll.<br/>request collection"]
end

node_sqlite_db -->|"contains"| node_circuits
node_sqlite_db -->|"contains"| node_qubits
node_sqlite_db -->|"contains"| node_gates
node_sqlite_db -->|"contains"| node_results
node_sqlite_db -->|"contains"| node_noise_models
node_circuits -->|"joins"| node_qubits
node_circuits -->|"joins"| node_gates
node_circuits -->|"joins"| node_results
node_circuits -->|"joins"| node_noise_models
node_backend_main -->|"validates"| node_backend_models
node_backend_main -->|"reads/writes"| node_sqlite_db
node_dashboard_api -->|"calls"| node_backend_main
node_dashboard_legacy -.->|"queries"| node_sqlite_db
node_load_excel -->|"loads"| node_sqlite_db
node_synthetic_db -->|"generates"| node_sqlite_db
node_validate_req -.->|"checks"| node_backend_main
node_sample_sql -.->|"explores"| node_sqlite_db
node_api_docs -.->|"describes"| node_backend_main
node_er_diagram -.->|"describes"| node_sqlite_db
node_postman -.->|"tests"| node_backend_main

click node_backend_main "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/backend/main.py"
click node_backend_models "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/backend/models.py"
click node_dashboard_api "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/frontend/dashboard_api.py"
click node_dashboard_legacy "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/frontend/dashboard.py"
click node_load_excel "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/scripts/load_excel_to_sqlite.py"
click node_synthetic_db "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/scripts/generate_synthetic_db.py"
click node_validate_req "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/scripts/validate_project_requirements.py"
click node_sample_sql "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/sql/sample_queries.sql"
click node_api_docs "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/docs/API_DOCUMENTATION.md"
click node_er_diagram "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/docs/ER_DIAGRAM.md"
click node_postman "https://github.com/horserider2146/quantum-circuit-dbms/blob/main/docs/postman_collection.json"

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_sqlite_db,node_circuits,node_qubits,node_gates,node_results,node_noise_models toneBlue
class node_backend_main,node_backend_models toneAmber
class node_dashboard_api,node_dashboard_legacy toneMint
class node_load_excel,node_synthetic_db,node_validate_req,node_sample_sql toneRose
class node_api_docs,node_er_diagram,node_postman toneIndigo
```

## Components

### Data store

SQLite schema and persisted experiment records

- **SQLite DB**: relational store · Authoritative local database for circuit experiments
- **Circuits**: core table · Primary circuit experiment records
- **Qubits**: table · Circuit hardware and qubit metadata
- **Gates**: table · Circuit composition and gate sequence data
- **Results**: table · Execution outcomes and measurement results
- **Noise models**: table · Noise characteristics linked to circuits

### Backend service

FastAPI application and request/response models

- [FastAPI app](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/backend/main.py): REST service · Main HTTP service with CRUD, search, stats, and analytics endpoints · `backend/main.py`
- [API models](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/backend/models.py): Pydantic schemas · Request and response contracts for the backend · `backend/models.py`

### Frontends

Streamlit entry points for API-driven and legacy access

- [API dashboard](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/frontend/dashboard_api.py): Streamlit UI · Primary dashboard path using the backend over HTTP · `frontend/dashboard_api.py`
- [Legacy dashboard](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/frontend/dashboard.py): Streamlit UI · Older direct-database dashboard path · `frontend/dashboard.py`

### Tooling

Offline import, generation, validation, and SQL exploration

- [Excel loader](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/scripts/load_excel_to_sqlite.py): ETL script · Imports workbook data into SQLite · `scripts/load_excel_to_sqlite.py`
- [Synthetic DB](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/scripts/generate_synthetic_db.py): data generator · Builds sample or demo database content · `scripts/generate_synthetic_db.py`
- [Requirements check](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/scripts/validate_project_requirements.py): validation script · Verifies project-specific assignment constraints · `scripts/validate_project_requirements.py`
- [Sample queries](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/sql/sample_queries.sql): SQL examples · Ad hoc queries for direct database exploration · `sql/sample_queries.sql`

### Docs

Architecture and API contract artifacts

- [API docs](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/docs/API_DOCUMENTATION.md): documentation · Endpoint and usage reference for the service · `docs/API_DOCUMENTATION.md`
- [ER diagram](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/docs/ER_DIAGRAM.md): schema doc · Relational structure and table relationships · `docs/ER_DIAGRAM.md`
- [Postman coll.](https://github.com/horserider2146/quantum-circuit-dbms/blob/main/docs/postman_collection.json): request collection · Executable API request set for testing · `docs/postman_collection.json`

## Connections

- SQLite DB → Circuits: contains · Primary persisted entity
- SQLite DB → Qubits: contains · Normalized related table
- SQLite DB → Gates: contains · Normalized related table
- SQLite DB → Results: contains · Normalized related table
- SQLite DB → Noise models: contains · Normalized related table
- Circuits → Qubits: joins · Shared circuit_id relationship
- Circuits → Gates: joins · Shared circuit_id relationship
- Circuits → Results: joins · Shared circuit_id relationship
- Circuits → Noise models: joins · Shared circuit_id relationship
- FastAPI app → API models: validates · Uses schemas for API contracts
- FastAPI app → SQLite DB: reads/writes · Owns business logic and persistence access
- API dashboard → FastAPI app: calls · HTTP API integration via API key
- Legacy dashboard → SQLite DB: queries · Direct database access path
- Excel loader → SQLite DB: loads · ETL import into local database file
- Synthetic DB → SQLite DB: generates · Creates demo database content
- Requirements check → FastAPI app: checks · Validates repo-specific requirements
- Sample queries → SQLite DB: explores · Ad hoc direct SQL against the store
- API docs → FastAPI app: describes · Documents service surface and workflows
- ER diagram → SQLite DB: describes · Documents relational schema
- Postman coll. → FastAPI app: tests · Request collection for API verification
