# nitr098/surgery-phase-explorer architecture

> Architecture diagram of the GitHub repository nitr098/surgery-phase-explorer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nitr098/surgery-phase-explorer
- Repository: https://github.com/nitr098/surgery-phase-explorer

## Overview

Surgery Phase Explorer loads surgical phase annotations into a shared representation, then supports dataset inventory, timeline inspection, boundary-frame review, interactive playback, and annotation-convention reports. The main workflow is dataset selection → loader → normalized annotations → an inspection or analysis result. The README documents all three dataset formats and the major tools. Source excerpts show loader and visualization behavior; some CLI-to-library wiring is supported only by the SOURCE INDEX, so unsampled implementation details are not expanded.

Main entry points: [`phase_atlas/datasets.py`](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/datasets.py) (Dataset registry), [`phase_atlas/schema.py`](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/schema.py) (Annotation model), [`phase_atlas/timeline.py`](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/timeline.py) (Timeline ribbons), [`phase_atlas/montage.py`](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/montage.py) (Boundary strips)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Dataset access"]
  node_registry["Dataset registry<br/>[datasets.py]"]
  node_cholec_loader["Cholec80 loader<br/>[cholec80.py]"]
  node_cataract_loader["Cataract-1K loader<br/>[cataract1k.py]"]
  node_ci_loader["CI in-house loader<br/>[ci_inhouse.py]"]
  node_list_cli["Dataset inventory<br/>[list_videos.py]"]
end

subgraph group_model["Annotation model"]
  node_schema["Annotation model<br/>[schema.py]"]
  node_colors["Label colors<br/>[colors.py]"]
end

subgraph group_inspect["Visual inspection"]
  node_timeline_cli["Timeline command<br/>[plot_timelines.py]"]
  node_timeline["Timeline ribbons<br/>[timeline.py]"]
  node_boundary_cli["Boundary export"]
  node_montage["Boundary strips<br/>[montage.py]"]
  node_play_cli["Player command<br/>[play.py]"]
  node_player["Interactive player<br/>[player.py]"]
  node_figures["Figures and strips"]
end

subgraph group_report["Convention analysis"]
  node_report_cli["Report command"]
  node_analysis["Convention report<br/>[analysis.py]"]
  node_report_output["Report and matrix"]
end

node_user(("Analyst"))
node_dataset_files[("Dataset files")]

node_user -->|"lists videos"| node_list_cli
node_user -->|"plots timelines"| node_timeline_cli
node_user -->|"exports boundaries"| node_boundary_cli
node_user -->|"plays video"| node_play_cli
node_user -->|"requests report"| node_report_cli
node_list_cli -->|"loads datasets"| node_registry
node_timeline_cli -->|"loads dataset"| node_registry
node_boundary_cli -->|"loads dataset"| node_registry
node_play_cli -->|"gets video"| node_registry
node_report_cli -->|"loads dataset"| node_registry
node_registry -->|"reads config and data"| node_dataset_files
node_registry -->|"dispatches"| node_cholec_loader
node_registry -->|"dispatches"| node_cataract_loader
node_registry -->|"dispatches"| node_ci_loader
node_cholec_loader -->|"builds annotations"| node_schema
node_cataract_loader -->|"builds annotations"| node_schema
node_ci_loader -->|"builds annotations"| node_schema
node_timeline -->|"plots spans"| node_schema
node_montage -->|"reads transitions"| node_schema
node_player -->|"renders annotation"| node_schema
node_analysis -->|"computes conventions"| node_schema
node_timeline -->|"gets label colors"| node_colors
node_montage -->|"gets label colors"| node_colors
node_player -->|"gets label colors"| node_colors
node_analysis -->|"gets label colors"| node_colors
node_timeline_cli -->|"renders"| node_timeline
node_boundary_cli -->|"exports strips"| node_montage
node_play_cli -->|"runs player"| node_player
node_report_cli -->|"writes report"| node_analysis
node_timeline -->|"writes ribbons"| node_figures
node_montage -->|"writes strips"| node_figures
node_analysis -->|"writes report and matrix"| node_report_output

click node_registry "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/datasets.py"
click node_cholec_loader "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/loaders/cholec80.py"
click node_cataract_loader "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/loaders/cataract1k.py"
click node_ci_loader "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/loaders/ci_inhouse.py"
click node_schema "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/schema.py"
click node_colors "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/colors.py"
click node_list_cli "https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/list_videos.py"
click node_timeline_cli "https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/plot_timelines.py"
click node_timeline "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/timeline.py"
click node_boundary_cli "https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/export_boundaries.py"
click node_montage "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/montage.py"
click node_play_cli "https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/play.py"
click node_player "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/player.py"
click node_report_cli "https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/report_conventions.py"
click node_analysis "https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/analysis.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_registry,node_cholec_loader,node_cataract_loader,node_ci_loader,node_list_cli toneBlue
class node_schema,node_colors,node_dataset_files toneAmber
class node_timeline_cli,node_timeline,node_boundary_cli,node_montage,node_play_cli,node_player,node_figures toneMint
class node_report_cli,node_analysis,node_report_output toneRose
class node_user toneIndigo
```

## Components

### Dataset access

- [Dataset registry](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/datasets.py): `phase_atlas/datasets.py`
- [Cholec80 loader](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/loaders/cholec80.py): `phase_atlas/loaders/cholec80.py`
- [Cataract-1K loader](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/loaders/cataract1k.py): `phase_atlas/loaders/cataract1k.py`
- [CI in-house loader](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/loaders/ci_inhouse.py): `phase_atlas/loaders/ci_inhouse.py`
- [Dataset inventory](https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/list_videos.py): `scripts/list_videos.py`

### Annotation model

- [Annotation model](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/schema.py): `phase_atlas/schema.py`
- [Label colors](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/colors.py): `phase_atlas/colors.py`

### Visual inspection

- [Timeline command](https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/plot_timelines.py): `scripts/plot_timelines.py`
- [Timeline ribbons](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/timeline.py): `phase_atlas/timeline.py`
- [Boundary export](https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/export_boundaries.py): `scripts/export_boundaries.py`
- [Boundary strips](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/montage.py): `phase_atlas/montage.py`
- [Player command](https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/play.py): `scripts/play.py`
- [Interactive player](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/player.py): `phase_atlas/player.py`
- **Figures and strips**

### Convention analysis

- [Report command](https://github.com/nitr098/surgery-phase-explorer/blob/main/scripts/report_conventions.py): `scripts/report_conventions.py`
- [Convention report](https://github.com/nitr098/surgery-phase-explorer/blob/main/phase_atlas/analysis.py): `phase_atlas/analysis.py`
- **Report and matrix**

### Other components

- **Analyst**
- **Dataset files**

## Connections

- Analyst → Dataset inventory: lists videos (evidence: `README.md`)
- Analyst → Timeline command: plots timelines (evidence: `README.md`)
- Analyst → Boundary export: exports boundaries (evidence: `README.md`)
- Analyst → Player command: plays video (evidence: `README.md`)
- Analyst → Report command: requests report (evidence: `README.md`)
- Dataset inventory → Dataset registry: loads datasets (evidence: `scripts/list_videos.py`)
- Timeline command → Dataset registry: loads dataset (evidence: `scripts/plot_timelines.py`)
- Boundary export → Dataset registry: loads dataset (evidence: `scripts/export_boundaries.py`)
- Player command → Dataset registry: gets video (evidence: `scripts/play.py`)
- Report command → Dataset registry: loads dataset (evidence: `scripts/report_conventions.py`)
- Dataset registry → Dataset files: reads config and data (evidence: `phase_atlas/datasets.py`)
- Dataset registry → Cholec80 loader: dispatches (evidence: `phase_atlas/datasets.py`)
- Dataset registry → Cataract-1K loader: dispatches (evidence: `phase_atlas/datasets.py`)
- Dataset registry → CI in-house loader: dispatches (evidence: `phase_atlas/datasets.py`)
- Cholec80 loader → Annotation model: builds annotations (evidence: `phase_atlas/loaders/cholec80.py`)
- Cataract-1K loader → Annotation model: builds annotations (evidence: `phase_atlas/loaders/cataract1k.py`)
- CI in-house loader → Annotation model: builds annotations (evidence: `phase_atlas/loaders/ci_inhouse.py`)
- Timeline ribbons → Annotation model: plots spans (evidence: `phase_atlas/timeline.py`)
- Boundary strips → Annotation model: reads transitions (evidence: `phase_atlas/montage.py`)
- Interactive player → Annotation model: renders annotation (evidence: `phase_atlas/player.py`)
- Convention report → Annotation model: computes conventions (evidence: `phase_atlas/analysis.py`)
- Timeline ribbons → Label colors: gets label colors (evidence: `phase_atlas/timeline.py`)
- Boundary strips → Label colors: gets label colors (evidence: `phase_atlas/montage.py`)
- Interactive player → Label colors: gets label colors (evidence: `phase_atlas/player.py`)
- Convention report → Label colors: gets label colors (evidence: `phase_atlas/analysis.py`)
- Timeline command → Timeline ribbons: renders (evidence: `scripts/plot_timelines.py`)
- Boundary export → Boundary strips: exports strips (evidence: `scripts/export_boundaries.py`)
- Player command → Interactive player: runs player (evidence: `scripts/play.py`)
- Report command → Convention report: writes report (evidence: `scripts/report_conventions.py`)
- Timeline ribbons → Figures and strips: writes ribbons (evidence: `README.md`)
- Boundary strips → Figures and strips: writes strips (evidence: `README.md`)
- Convention report → Report and matrix: writes report and matrix (evidence: `phase_atlas/analysis.py`)
