# nafisa17/napari-parallel architecture

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

- Interactive diagram: https://gitdiagram.com/nafisa17/napari-parallel
- Repository: https://github.com/nafisa17/napari-parallel

## Overview

##### Project type and purpose
- This is a napari plugin (a Python “open-source tool” style project) named **napari-parallel**.
- Purpose: provide a GUI widget inside Napari to generate and execute image-processing pipelines in parallel across multiple machines, leveraging the napari-assistant code-generation engine and the Dask distributed library.

##### File structure
- Top level: packaging & metadata files (LICENSE, README.md, pyproject.toml, setup.cfg, tox.ini, napari-plugin manifest `napari.yaml`).
- `src/napari_parallel/`: the plugin’s Python package.
- `_widget.py` – Napari plugin widget definition and GUI callbacks
- `_reader.py` / `_writer.py` – I/O abstraction for image loading/saving
- `_sample_data.py` – helper to fetch or generate demo images
- `_tests/` – pytest suite for each module
- Build artifacts under `dist/` and egg-info indicate a standard Python packaging workflow.

##### README insights
- Confirms use of **napari-assistant** (code-generation for building pipelines) and **Dask** (distributed compute).
- Installation via pip, tests via tox.

##### Main components and their interactions
a. Napari Application (Host)
- Loads plugin via `napari.yaml` entry point
- Hosts the canvas / image viewer
b. Plugin UI Widget (`_widget.py`)
- Presents parameter form to user
- Invokes napari-assistant to generate processing code
- Triggers submission to Dask
c. Code Generation Engine (napari-assistant)
- Returns an executable Python function or pipeline definition
d. Dask Distributed Cluster
- Scheduler (central coordinator)
- Workers (one or more compute nodes)
- Communication via TCP – tasks, data grids
e. I/O Modules
- `_reader.py`: load image tiles or volumes from disk/URL into memory
- `_writer.py`: write back processed results
- `_sample_data.py`: embed demo data for quick tests
f. Test Harness (tox / pytest) – not in runtime but important for CI

##### Architectural patterns & design principles
- **Plugin Architecture**: decouples Napari host from processing logic
- **Command Pattern**: generated pipeline functions executed as Dask tasks
- **Distributed Dataflow**: Dask schedules tasks and manages dependencies
- **Separation of Concerns**: UI vs. I/O vs. compute

a. Components
- Napari Host (GUI)
- Plugin Widget
- Code Gen Engine
- Dask Scheduler & Workers
- Reader/Writer Modules
- Sample Data Module
b. Relationships / Data Flow
1. User interacts with Plugin Widget in Napari
2. Widget calls napari-assistant engine → returns pipeline code
3. Widget imports `_reader` & `_writer` to form tasks
4. Widget submits pipeline to Dask Scheduler
5. Scheduler dispatches tasks to Workers
6. Workers call Reader → transform → Writer
7. Results streamed back to Napari Viewer
c. Technology labels
- Python, napari SDK, napari-assistant, Dask Distributed, pytest, tox
d. Design choices
- Plugin registration via `napari.yaml`
- Distributed compute pattern

##### Final advice
- Plugin’s entry point in Napari, then branch to code-generation and distributed execution.
- CI/test pipeline separately (optional), or annotate that `tox.ini`/`_tests` ensure quality but do not run at runtime.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Napari Host Layer
    subgraph "Napari Host (UI Layer)"
        direction TB
        NapariHost["Napari Application"]:::frontend
        EntryPoint["Plugin Entry Point\n(napari.yaml)"]:::frontend
    end

    %% Plugin Package
    subgraph "napari_parallel Package" 
        direction TB
        Widget["Plugin UI Widget\n(_widget.py)"]:::plugin
        subgraph "I/O Services"
            direction TB
            Reader["Reader Module\n(_reader.py)"]:::io
            Writer["Writer Module\n(_writer.py)"]:::io
            SampleData["Sample Data Helper\n(_sample_data.py)"]:::io
        end
    end

    %% External Engine
    CodeGen["Code Generation Engine\n(napari-assistant)"]:::external

    %% Dask Cluster
    subgraph "Dask Distributed Cluster" 
        direction TB
        Scheduler["Dask Scheduler"]:::compute
        Worker["Dask Worker"]:::compute
    end

    %% Packaging & Tests
    subgraph "Packaging & CI"
        direction TB
        Packaging["Packaging & Metadata"]:::metadata
        SetupCFG["setup.cfg"]:::metadata
        Pyproject["pyproject.toml"]:::metadata
        LICENSE["LICENSE"]:::metadata
        README["README.md"]:::metadata
        MANIFEST["MANIFEST.in"]:::metadata
        Tox["tox.ini"]:::metadata
        subgraph "Test Harness (pytest)"
            direction TB
            TestSuite["_tests/"]:::metadata
            TestReader["test_reader.py"]:::metadata
            TestWriter["test_writer.py"]:::metadata
            TestSample["test_sample_data.py"]:::metadata
            TestWidget["test_widget.py"]:::metadata
        end
    end

    %% Flow Connections
    NapariHost -->|loads via| EntryPoint
    EntryPoint -->|activates| Widget
    Widget -->|"generate pipeline"| CodeGen
    Widget -->|"import tasks"| Reader
    Widget -->|"import tasks"| Writer
    Widget -->|"import demo data"| SampleData
    Widget -->|"submit pipeline"| Scheduler
    Scheduler -->|"dispatch tasks"| Worker
    Worker -->|"load data"| Reader
    Worker -->|"process"| Widget
    Worker -->|"save results"| Writer
    Worker -->|results| NapariHost

    %% Click Events
    click EntryPoint "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/napari.yaml"
    click SetupCFG "https://github.com/nafisa17/napari-parallel/blob/main/setup.cfg"
    click Widget "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/_widget.py"
    click Reader "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/_reader.py"
    click Writer "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/_writer.py"
    click SampleData "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/_sample_data.py"
    click TestSuite "https://github.com/nafisa17/napari-parallel/tree/main/src/napari_parallel/_tests/"
    click TestReader "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/_tests/test_reader.py"
    click TestWriter "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/_tests/test_writer.py"
    click TestSample "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/_tests/test_sample_data.py"
    click TestWidget "https://github.com/nafisa17/napari-parallel/blob/main/src/napari_parallel/_tests/test_widget.py"
    click Packaging "https://github.com/nafisa17/napari-parallel/blob/main/pyproject.toml"
    click Pyproject "https://github.com/nafisa17/napari-parallel/blob/main/pyproject.toml"
    click LICENSE "https://github.com/nafisa17/napari-parallel/tree/main/LICENSE"
    click README "https://github.com/nafisa17/napari-parallel/blob/main/README.md"
    click MANIFEST "https://github.com/nafisa17/napari-parallel/blob/main/MANIFEST.in"
    click Tox "https://github.com/nafisa17/napari-parallel/blob/main/tox.ini"

    %% Styles
    classDef frontend fill:#f2f0fc,stroke:#4b4e6d,color:#333;
    classDef plugin fill:#e8f4fc,stroke:#3d8eb9,color:#333;
    classDef io fill:#e8fcf4,stroke:#3db98e,color:#333;
    classDef external fill:#fcf1e8,stroke:#e09b44,color:#333;
    classDef compute fill:#fce8f0,stroke:#d94b72,color:#333;
    classDef metadata fill:#f0fcf2,stroke:#6db94b,color:#333;
```
