Skip to content

Development

For contributors: how Skopia is put together, where the code lives, how to run the tests, how a release is cut, and how to work on this documentation. Set up the environment first as in Install.

Architecture

h5ad → DataAdaptor → REST (/api/*) → React hooks → Zustand store → deck.gl
  • Backend: Python, FastAPI, AnnData and Scanpy. It holds each loaded dataset in memory and runs the analyses. While it runs, the interactive API documentation is at http://localhost:8000/docs; see also REST API and Python API.
  • Frontend: React and TypeScript, built with Vite, drawing cells with deck.gl and keeping state in a Zustand store. In development the Vite server on port 5173 forwards /api requests to the backend on port 8000.

The rules that keep the backend manageable:

  • backend/skopia/adaptor.py is the only code that owns AnnData. It reads and writes .obs, .obsm, .uns and .layers. Analysis modules (diffexp.py, ligrec.py, cnv.py, layer_scale.py, spatial_autocorr.py and others) are pure: they take arrays or a throwaway AnnData and return dicts. The adaptor pulls the matrix out, calls the module and writes the result back.
  • Routes are thin. Each route in backend/skopia/api/routes.py resolves the dataset slot, calls the adaptor and maps exceptions: ValueError to 400, KeyError to 404, no data loaded to 503.
  • Long-running work runs as a background task (task_manager.py). The adaptor's prepare_<thing>() validates input synchronously, so bad input is a 400 instead of a failed task, and returns a compute function with no side effects and an apply function that writes into the live AnnData. The route answers 202 with a task id that the frontend polls.
  • Heavy imports are function-local (squidpy, igraph, leidenalg, pySingleCellNet), so importing the adaptor stays fast. Optional dependencies follow pyscn.py: never imported at module scope, an availability() report, and a ValueError with install instructions that the UI can show.
  • Every .uns key Skopia writes starts with skopia_. What Skopia writes to AnnData lists them.
  • Every mutating operation is recorded in the analysis record, and needs an entry in the code generator so the notebook export can reproduce it (Analysis record and notebook export).

The backend reloads on code changes

pixi run backend runs uvicorn with --reload. Saving a file under backend/ restarts the backend and discards every loaded dataset and its session work. Export anything you want to keep before you edit backend code.

Project structure

skopia/
├── backend/
│   ├── skopia/
│   │   ├── main.py            # FastAPI app; loads SKOPIA_DATA_PATH or the toy dataset at startup
│   │   ├── adaptor.py         # DataAdaptor: the only owner of AnnData
│   │   ├── api/routes.py      # REST endpoints
│   │   ├── task_manager.py    # cancellable background jobs
│   │   ├── config.yaml        # shipped defaults (see Configure defaults)
│   │   ├── codegen.py         # analysis record → notebook code
│   │   ├── diffexp.py, cnv.py, ligrec.py, localize.py, …   # pure analysis modules
│   │   ├── pyscn.py           # PySingleCellNet adapter (optional dependency)
│   │   ├── convert_seurat.R   # .rds → .h5ad through SeuratDisk
│   │   └── data/              # bundled toy datasets, gene tables, gene-set bundles and their build scripts
│   ├── tests/                 # pytest suite
│   ├── benchmarks/            # benchmark harnesses (CNV)
│   └── pyproject.toml         # the Python package
├── frontend/
│   ├── src/
│   │   ├── App.tsx            # the window: header menus, panels, center tabs
│   │   ├── store.ts           # Zustand state, one entry per loaded dataset
│   │   ├── components/        # panels, dialogs, plots (ScatterPlot.tsx, ScanpyModal.tsx, …)
│   │   ├── hooks/useData.ts   # data fetching and backend actions
│   │   └── lib/               # pure helpers, most with a vitest *.test.ts beside them
│   ├── package.json
│   └── vite.config.ts         # dev server and the /api proxy
├── docs/                      # this site (and working notes kept out of it)
├── mkdocs.yml                 # site configuration and navigation
├── scripts/release.py         # version check and release preparation
├── pixi.toml, pixi.lock       # environments and tasks
├── CHANGELOG.md
└── README.md

Run the tests

There is no lint step; the test suites and the TypeScript compiler are the checks.

Backend, from backend/:

pixi run -e dev pytest
pixi run -e dev pytest tests/test_layer_scale.py -q    # one file

The dev environment adds pytest and httpx to the default one. Tests that need PySingleCellNet are skipped there; the pyscn environment includes the dev tools, so pixi run -e pyscn pytest runs them too.

Frontend, from frontend/:

pixi run npx vitest run        # unit tests
pixi run npx tsc --noEmit      # typecheck

Conventions for backend tests: there is no conftest.py, and each test file is self-contained, building its AnnData with module-level factory functions (seeded, sparse float32). Construct the adaptor as DataAdaptor("x.h5ad", adata=ad) to skip disk I/O. Assert on both the returned dict and the resulting AnnData state. A test for an optional dependency must pass with the package absent; gate only what needs it with pytest.mark.skipif.

Pytest calls the adaptor directly, so it cannot catch a request model that rejects what the browser sends, or a value that fails JSON serialization. Check new features in the browser as well.

Changelog entries

Add a bullet under ## [Unreleased] in CHANGELOG.md for each change a user would notice, with the menu path in parentheses. Lead it with **Fixed: …** for a fix or **Breaking: …** for a breaking change (see Versioning and releases); a feature or change has neither. The release script reads these leads.

Cut a release

Maintainers only. A release is prepared locally and published by pushing its tag.

  1. On a clean main, run:

    pixi run release 0.8.0
    

    The script refuses unless you are on main with no uncommitted changes, the version is newer than the current one, and the tag does not exist yet. It then:

    • moves the changelog's Unreleased section under the new version and date, and warns when the version does not fit the entries (fixes only in a minor release, a feature in a patch, a skipped number);
    • runs the backend suite (pytest in the dev environment), vitest and tsc --noEmit;
    • writes the version into the five files that state it (backend/skopia/__init__.py, backend/pyproject.toml, pixi.toml, frontend/package.json, frontend/package-lock.json);
    • commits release: v0.8.0 and creates the annotated tag v0.8.0.

    Nothing leaves the machine. To undo: git tag -d v0.8.0 && git reset --hard HEAD~1. --skip-tests skips the test run when you have run the suites yourself.

  2. Publish:

    git push origin main v0.8.0
    

    Pushing the tag runs .github/workflows/release.yml, which checks that the tag names the version in the files and creates the GitHub release from that version's changelog section. Pushing a tag is publishing; do it only when you mean to release.

pixi run version prints the current version and fails if the five files disagree.

Working on these docs

The site is built with MkDocs Material. Its pages are Markdown files under docs/, and mkdocs.yml holds the configuration and the navigation. The docs pixi environment has only what the site needs, not the scientific stack:

pixi run -e docs docs          # preview with live reload at http://127.0.0.1:8001
pixi run -e docs docs-build    # build into site/; fails on any broken link or warning

Writing pages. Pages can use the Material extensions enabled in mkdocs.yml: admonitions (!!! note, tip, warning, and the custom where box), collapsible blocks (??? note), content tabs (=== "macOS"), definition lists, keys (++ctrl+z++), footnotes and attribute lists. A snippet line --8<-- "FILE" includes a file from the repository root; the Changelog page is built that way from CHANGELOG.md. The project's style: plain and specific, American spelling in prose, UI labels in bold exactly as the app shows them, menu paths as Analyze → Cells → PCA, AnnData keys and file names in code, and every number stated with the condition that produced it.

A new page needs a line in the nav section of mkdocs.yml, or it is not in the site's navigation. docs/ also holds working notes (design specs, measurements, the roadmap) that exclude_docs keeps out of the site.

User guide pages share one layout, so readers know where to look:

  1. a title and one or two sentences on what the feature does and the question it answers;
  2. a Where to find it box (!!! where) with the menu path;
  3. then, as they apply: How it works (the idea and the method), Run it (numbered steps), Parameters (a table of parameter, default and effect), What it writes (a table of AnnData keys), Tips and pitfalls, and Related (links to other guide pages).

Long method explanations go in a collapsible ???+ info "Method details" block. Link other pages by relative path to the .md file, as in the navigation.

Screenshots go in docs/assets/screens/ as JPEG files.

Citations. A page that describes a method Skopia calls, adapts or reimplements cites it. Add the reference to docs/references.md with an anchor of the first author's surname and the year, <a id="surnameYEAR"></a> (lowercase ASCII, with a or b appended if needed), and link to it from the page, for example [Haghverdi et al. 2016](../../references.md#haghverdi2016).

Publishing. .github/workflows/docs.yml builds the site with mkdocs build --strict and publishes it to GitHub Pages (https://cahanlab.github.io/skopia/) on every push to main that touches docs/, mkdocs.yml or CHANGELOG.md. A pull request that touches them is built without publishing, so a broken link fails the check before merging. That workflow installs the theme with pip from docs/requirements.txt rather than through pixi; keep that file in step with the docs feature in pixi.toml. .readthedocs.yaml configures Read the Docs as an alternative host from the same mkdocs.yml.