# bluesky/bluesky-queueserver-api architecture

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

- Interactive diagram: https://gitdiagram.com/bluesky/bluesky-queueserver-api
- Repository: https://github.com/bluesky/bluesky-queueserver-api

## Overview

##### Project type and purpose
- This is a Python client‐library (“bluesky-queueserver-api”) that exposes a high-level API for interacting with a Bluesky Queue Server.
- The README calls it a “Python API for Bluesky Queue Server,” intended to let user code submit and control experiments in a remote or local queue server via multiple transport layers.

##### File structure
Top-level:
- blueky_queueserver_api/
– api_base.py, api_threads.py, api_async.py, api_docstrings.py
– comm_base.py, comm_threads.py, comm_async.py
– http/aio.py
– zmq/aio.py
– console_monitor.py
- tests/ under bluesky_queueserver_api/tests
- docs/ (Sphinx conf, .rst files)
- CI and lint config (.github/workflows, flake8, isort, pre-commit)
- packaging (setup.py, pyproject.toml, requirements*.txt)

Architectural clues:
– “api_*.py” modules define the public client interface
– “comm_*.py” modules define communication abstraction and implementations
– Under “http/” and “zmq/” are the asynchronous I/O specific transport implementations
– “api_threads.py” & “comm_threads.py” provide threaded‐mode transport
– “api_async.py” & “comm_async.py” provide asyncio‐based transport

##### README for additional insights
- The docs/ folder contains usage and API‐reference pages—good hints at core classes and modules.

##### Components and relationships
a. Main components
1. User code / Client application
2. API layer (api_base, api_threads, api_async)
3. Communication layer (comm_base, comm_threads, comm_async)
4. Transport implementations:
- Threaded transport (in-process)
- AsyncIO transport (in-process)
- HTTP transport (using aiohttp in http/aio.py)
- ZMQ transport (using zmq/aio.py)
5. Bluesky Queue Server (external service)

b. Relationships & interactions
- API layer calls into Communication layer
- Communication layer chooses a transport implementation
- Transport implementation sends/receives messages to/from the Queue Server
- Optionally, console_monitor monitors or logs queue server state

c. Architectural patterns & principles
- Layered architecture: clear separation of API vs. transport
- Dependency inversion: API layer depends on comm_base abstractions
- Strategy pattern: multiple transport strategies (threads, async, HTTP, ZMQ)
- Extensibility: new transports can plug into comm_base

d. Key technologies & libraries
- Python’s threading and asyncio libraries
- ZeroMQ (pyzmq) for zmq/aio.py
- aiohttp for HTTP transport
- Sphinx for docs, pytest for tests, versioneer for versioning

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client Code"]:::client

    %% API Layer
    subgraph "API Layer"
        direction TB
        ApiBase["ApiBase"]:::api
        ApiAsync["ApiAsync"]:::api
        ApiThreads["ApiThreads"]:::api
        ApiDoc["ApiDocstrings"]:::api
        ApiBase -->|extends| ApiAsync
        ApiBase -->|extends| ApiThreads
        ApiBase -->|uses| ApiDoc
    end

    %% Communication Layer
    subgraph "Communication Layer"
        direction TB
        CommBase["CommBase"]:::comm
        CommAsync["CommAsync"]:::comm
        CommThreads["CommThreads"]:::comm
        CommBase -->|implements| CommAsync
        CommBase -->|implements| CommThreads
    end

    %% Transport Implementations
    subgraph "Transport Layer"
        direction TB
        HTTP["HTTP (aio)"]:::transport
        ZMQ["ZMQ (aio)"]:::transport
    end

    %% Utilities
    subgraph "Utilities"
        direction TB
        Defaults["_defaults"]:::util
        Version["_version"]:::util
        Console["ConsoleMonitor"]:::util
        Items["Data Models (item)"]:::util
    end

    %% External Service
    QueueServer["Bluesky Queue Server"]:::external

    %% Relationships
    Client -->|uses API| ApiBase
    ApiBase -->|calls Comm| CommBase
    CommBase -->|selects transport| HTTP
    CommBase -->|selects transport| ZMQ
    HTTP -->|HTTP REST| QueueServer
    ZMQ -->|ZMQ message| QueueServer
    QueueServer -->|monitored by| Console

    %% Click Events
    click ApiBase "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/api_base.py"
    click ApiAsync "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/api_async.py"
    click ApiThreads "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/api_threads.py"
    click ApiDoc "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/api_docstrings.py"
    click CommBase "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/comm_base.py"
    click CommAsync "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/comm_async.py"
    click CommThreads "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/comm_threads.py"
    click HTTP "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/http/aio.py"
    click ZMQ "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/zmq/aio.py"
    click Defaults "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/_defaults.py"
    click Version "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/_version.py"
    click Console "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/console_monitor.py"
    click Items "https://github.com/bluesky/bluesky-queueserver-api/blob/main/bluesky_queueserver_api/item.py"

    %% Styles
    classDef client fill:#f0f0f0,stroke:#333,stroke-width:1px;
    classDef api fill:#cce5ff,stroke:#0066cc,stroke-width:1px;
    classDef comm fill:#d4edda,stroke:#28a745,stroke-width:1px;
    classDef transport fill:#ffe5b4,stroke:#ff8c00,stroke-width:1px;
    classDef util fill:#e2e3e5,stroke:#6c757d,stroke-width:1px;
    classDef external fill:#f8f9fa,stroke:#6c757d,stroke-width:1px,stroke-dasharray: 5 5;
```
