# qiskit/qiskit-tutorials architecture

> Architecture diagram of the GitHub repository qiskit/qiskit-tutorials, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/qiskit/qiskit-tutorials
- Repository: https://github.com/qiskit/qiskit-tutorials

## Overview

##### Project Type and Purpose
- This is an educational “documentation‐as‐code” project: a collection of Jupyter notebooks (tutorials) built into HTML documentation via Sphinx.
- Purpose: Teach users how to use Qiskit (quantum programming SDK) through hands-on notebooks, automated testing of notebooks, and CI/CD to publish tutorials.

##### File‐Structure Analysis
- Top-level:
- `.github/` → GitHub issue/PR templates, contributing rules
- `azure-pipelines.yml` → Azure DevOps CI config
- `tox.ini`, `requirements-dev.txt`, `constraints.txt` → Local/test environment orchestration
- `conf.py`, `index.rst`, `_static/` → Sphinx documentation source
- `tutorials/` → Jupyter notebooks grouped by topic (algorithms, circuits, advanced)
- `start_here.ipynb` → Entry-point tutorial
- Build tooling: Tox drives environment setup and “docs” build, nbsphinx converts `.ipynb` to RST/HTML, Sphinx renders site.

##### README Insights
- Mentions Sphinx, Tox, three-minute cell execution limit, no live IBMQ calls, strict header rules.
- Deployment: After PR, docs are hosted via Qiskit’s Sphinx infrastructure (e.g., on GitHub Pages or ReadTheDocs).

a. Main Components
1. Tutorial Content Repository (Git)
2. CI/CD Orchestration (GitHub Actions / Azure Pipelines)
3. Build/Test Environment (Tox + Python Virtualenvs)
4. Documentation Generator (nbsphinx + Sphinx)
5. Artifact Storage / Hosting (ReadTheDocs / GitHub Pages / S3)
6. External Dependencies (PyPI packages: qiskit-terra, qiskit-aer, etc.; IBM Quantum backends—not used at build)
b. Relationships and Interactions
- Code push → CI/CD triggers → Tox creates env → executes notebooks (nbsphinx) → Sphinx builds HTML → CI publishes artifacts to hosting.
- README, RST, conf.py feed Sphinx’s master document tree.
- Requirements files govern environment in Tox and CI.
c. Architectural Patterns
- “Docs as Code”: treat tutorials as source code, versioned and tested.
- Pipeline as Code: CI/CD defined in YAML (`azure-pipelines.yml`, `.mergify.yml`).
- Modular content: notebooks grouped by domain, nbsphinx extension handles conversion.
d. Key Technologies
- Python, Jupyter Notebooks, Sphinx, nbsphinx, Tox, GitHub Actions / Azure Pipelines, nbsphinx-thumbnail, ReadTheDocs/GitHub Pages.

##### Detailed Component Breakdown
- Source Control
- .github/ → Contributor guidelines, templates
- Tutorials/*.ipynb → Domain notebooks
- conf.py, index.rst → Sphinx config
- CI/CD
- azure-pipelines.yml / GitHub Actions steps
- Tox env creation & execution
- Build & Test
- Install deps from requirements-dev.txt & constraints.txt
- nbsphinx renders notebooks to RST
- Sphinx builds HTML under `_build/html`
- Deployment
- Push HTML to hosting (e.g., ReadTheDocs webhook or GitHub Pages branch)
- External Dependencies
- Qiskit packages (terra, aer) fetched from PyPI
- IBM Quantum API (shown as “Not invoked during CI build”)

Putting It All Together
- Branching into two parallel flows in CI: (1) Notebook execution tests, (2) Lint + static checks.
- Merge flows into “Sphinx Build” node.
- Constraints (3-min cell timeout, no IBMQ calls).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraphs
    subgraph "Source Control" 
        direction TB
        GitRepo["Git Repository"]:::repo
        Tutorials["/tutorials/"]:::repo
        StartNotebook["start_here.ipynb"]:::repo
        GitHubTemplates["/.github/ISSUE_TEMPLATE/"]:::repo
        PRTemplate["/.github/PULL_REQUEST_TEMPLATE.md"]:::repo
        Mergify["/.mergify.yml"]:::repo
        AzurePipelines["azure-pipelines.yml"]:::repo
    end

    subgraph "CI/CD Pipeline" 
        direction TB
        CI["CI/CD Orchestration"]:::ci
        Lint["Lint & Static Checks"]:::build
        NotebookTests["Notebook Execution Tests"]:::build
    end

    subgraph "Build & Test Environment"
        direction TB
        Tox["Tox"]:::build
        DevReq["requirements-dev.txt"]:::build
        Constraints["constraints.txt"]:::build
    end

    subgraph "Documentation Generator"
        direction TB
        NbSphinx["nbsphinx"]:::docs
        Sphinx["Sphinx"]:::docs
        Conf["conf.py"]:::docs
        Index["index.rst"]:::docs
        StaticAssets["/_static/"]:::docs
    end

    subgraph "External Dependencies"
        direction TB
        PyPI["PyPI Packages"]:::ext
        IBMQ["IBM Quantum Backends\n(Not invoked)"]:::ext
    end

    subgraph "Hosting"
        direction TB
        Hosting["ReadTheDocs / GitHub Pages"]:::host
    end

    %% Flows
    GitRepo -->|"git push"| CI
    CI -->|runs| Lint
    CI -->|runs| NotebookTests
    NotebookTests -->|"tox -e docs"| Tox
    Lint -->|"tox -e lint"| Tox
    Tox -->|installs deps| DevReq
    Tox -->|applies constraints| Constraints
    Tox -->|executes notebooks| NbSphinx
    NbSphinx -->|converts to RST| Sphinx
    Conf -->|configures| Sphinx
    Index -->|master doc| Sphinx
    StaticAssets -->|assets| Sphinx
    PyPI -->|provides packages| Tox
    IBMQ -.->|blocked| NotebookTests
    Sphinx -->|builds HTML| Hosting

    %% Constraints annotation
    NotebookTests:::note
    classDef note fill:#F5F5F5,stroke:#444,stroke-dasharray: 5 5
    NotebookTests:::note
    click Tutorials "https://github.com/qiskit/qiskit-tutorials/tree/master//tutorials/"
    click StartNotebook "https://github.com/qiskit/qiskit-tutorials/blob/master//start_here.ipynb"
    click GitHubTemplates "https://github.com/qiskit/qiskit-tutorials/tree/master//.github/ISSUE_TEMPLATE/"
    click PRTemplate "https://github.com/qiskit/qiskit-tutorials/blob/master//.github/PULL_REQUEST_TEMPLATE.md"
    click Mergify "https://github.com/qiskit/qiskit-tutorials/blob/master//.mergify.yml"
    click AzurePipelines "https://github.com/qiskit/qiskit-tutorials/blob/master//azure-pipelines.yml"
    click DevReq "https://github.com/qiskit/qiskit-tutorials/blob/master//requirements-dev.txt"
    click Constraints "https://github.com/qiskit/qiskit-tutorials/blob/master//constraints.txt"
    click Conf "https://github.com/qiskit/qiskit-tutorials/blob/master//conf.py"
    click Index "https://github.com/qiskit/qiskit-tutorials/blob/master//index.rst"
    click StaticAssets "https://github.com/qiskit/qiskit-tutorials/tree/master//_static/"

    %% Styles
    classDef repo fill:#3498DB,stroke:#333,stroke-width:1px
    classDef ci fill:#2980B9,stroke:#333,stroke-width:1px
    classDef build fill:#2ECC71,stroke:#333,stroke-width:1px
    classDef docs fill:#E67E22,stroke:#333,stroke-width:1px
    classDef host fill:#9B59B6,stroke:#333,stroke-width:1px
    classDef ext fill:#95A5A6,stroke:#333,stroke-width:1px
```
