How horserider2146/quantum-circuit-dbms works
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: main.py FastAPI app · dashboard_api.py API dashboard · dashboard.py Legacy dashboard · load_excel_to_sqlite.py Excel loader
Components 17
Data store
SQLite schema and persisted experiment records
- SQLite DB · Authoritative local database for circuit experiments
- Circuits · Primary circuit experiment records
- Qubits · Circuit hardware and qubit metadata
- Gates · Circuit composition and gate sequence data
- Results · Execution outcomes and measurement results
- Noise models · Noise characteristics linked to circuits
Backend service
FastAPI application and request/response models
- FastAPI app · Main HTTP service with CRUD, search, stats, and analytics endpoints
backend/main.py - API models · Request and response contracts for the backend
backend/models.py
Frontends
Streamlit entry points for API-driven and legacy access
- API dashboard · Primary dashboard path using the backend over HTTP
frontend/dashboard_api.py - Legacy dashboard · Older direct-database dashboard path
frontend/dashboard.py
Tooling
Offline import, generation, validation, and SQL exploration
- Excel loader · Imports workbook data into SQLite
scripts/load_excel_to_sqlite.py - Synthetic DB · Builds sample or demo database content
scripts/generate_synthetic_db.py - Requirements check · Verifies project-specific assignment constraints
scripts/validate_project_requirements.py - Sample queries · Ad hoc queries for direct database exploration
sql/sample_queries.sql
Docs
Architecture and API contract artifacts
- API docs · Endpoint and usage reference for the service
docs/API_DOCUMENTATION.md - ER diagram · Relational structure and table relationships
docs/ER_DIAGRAM.md - Postman coll. · Executable API request set for testing
docs/postman_collection.json
Connections 20
- 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