# yeonseong-lee/rallylens architecture

> Architecture diagram of the GitHub repository yeonseong-lee/rallylens, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yeonseong-lee/rallylens
- Repository: https://github.com/yeonseong-lee/rallylens

## Overview

RallyLens analyzes badminton videos through two implementations: a working Python CLI and a browser-based technical preview. The CLI workflow downloads or accepts video, detects players and shuttle, calibrates the court, then produces visualizations and metrics or an optional Gemini report. The web app accepts local or direct video, runs analysis in a worker, supports corrections, and presents exportable results. The README documents these capabilities; several web and Python subsystem connections are therefore documented rather than verified from full source excerpts.

Main entry points: [`src/rallylens/cli.py`](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/cli.py) (CLI commands), [`src/rallylens/pipeline/orchestrator.py`](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/pipeline/orchestrator.py) (Run orchestrator), [`web/src/App.tsx`](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/App.tsx) (Analysis interface), [`web/src/components/Results.tsx`](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/components/Results.tsx) (Results and exports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Python CLI"]
  node_cli_entry["CLI commands<br/>[cli.py]"]
  node_orchestrator["Run orchestrator<br/>[orchestrator.py]"]
  node_downloader["Video downloader<br/>[downloader.py]"]
  node_video_domain["Video metadata<br/>[video.py]"]
  node_artifact_io["Artifact I/O<br/>[io.py]"]
end

subgraph group_vision["Video Analysis"]
  node_player_detect["Player tracking<br/>[detect_track.py]"]
  node_shuttle_track["Shuttle tracking<br/>[shuttle_tracker.py]"]
  node_court_pipeline["Court calibration<br/>[court.py]"]
  node_court_detect["Automatic court detector<br/>[court_detector.py]"]
  node_court_picker["Manual court picker<br/>[court_picker.py]"]
end

subgraph group_outputs["Metrics and Reports"]
  node_visualization["Video and court views<br/>[overlay.py]"]
  node_viz_helpers["Visualization helpers<br/>[_utils.py]"]
  node_python_metrics["Match metrics<br/>[metrics.py]"]
  node_python_report["LLM report generation<br/>[report.py]"]
end

subgraph group_webui["Browser App"]
  node_web_app["Analysis interface<br/>[App.tsx]"]
  node_video_source["Video input validation<br/>[video-source.ts]"]
  node_worker_client["Worker client<br/>[worker-client.ts]"]
  node_editors["Court and identity editors<br/>[CourtEditor.tsx]"]
  node_web_results["Results and exports<br/>[Results.tsx]"]
end

subgraph group_webengine["Browser Analysis"]
  node_engine["Analysis worker<br/>[engine.worker.ts]"]
  node_model_cache["Verified model cache<br/>[model-cache.ts]"]
  node_web_vision["Player inference and tracking<br/>[vision.ts]"]
  node_web_metrics["Browser metrics<br/>[metrics.ts]"]
  node_overlay_render["Overlay rendering<br/>[render-overlay.ts]"]
  node_web_report["Optional report<br/>[report.ts]"]
end

node_python_user(("CLI user"))
node_vertex["Vertex AI Gemini"]
node_web_user(("Browser user"))

node_python_user -->|"runs commands"| node_cli_entry
node_cli_entry -->|"starts run"| node_orchestrator
node_cli_entry -->|"downloads video"| node_downloader
node_downloader -.->|"fetches source"| node_vertex
node_downloader -->|"returns metadata"| node_video_domain
node_orchestrator -->|"downloads input"| node_downloader
node_orchestrator -->|"tracks players"| node_player_detect
node_orchestrator -->|"tracks shuttle"| node_shuttle_track
node_orchestrator -->|"calibrates court"| node_court_pipeline
node_orchestrator -->|"uses artifacts"| node_artifact_io
node_court_pipeline -->|"detects corners"| node_court_detect
node_court_pipeline -->|"offers manual picking"| node_court_picker
node_cli_entry -->|"creates visualizations"| node_visualization
node_visualization -->|"uses rendering helpers"| node_viz_helpers
node_cli_entry -->|"computes metrics"| node_python_metrics
node_cli_entry -->|"runs report command"| node_python_report
node_python_report -.->|"requests analysis"| node_vertex
node_web_user -->|"uses app"| node_web_app
node_web_app -->|"validates input"| node_video_source
node_web_app -->|"starts analysis"| node_worker_client
node_worker_client -->|"dispatches commands"| node_engine
node_web_app -->|"presents corrections"| node_editors
node_web_app -->|"shows results"| node_web_results
node_engine -->|"loads verified models"| node_model_cache
node_engine -->|"runs player tracking"| node_web_vision
node_engine -->|"computes metrics"| node_web_metrics
node_web_results -->|"recomputes metrics"| node_web_metrics
node_web_results -->|"exports overlay"| node_overlay_render
node_web_results -->|"requests report"| node_web_report

click node_cli_entry "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/cli.py"
click node_orchestrator "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/pipeline/orchestrator.py"
click node_downloader "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/ingest/downloader.py"
click node_video_domain "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/domain/video.py"
click node_artifact_io "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/pipeline/io.py"
click node_player_detect "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/vision/detect_track.py"
click node_shuttle_track "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/vision/shuttle_tracker.py"
click node_court_pipeline "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/pipeline/court.py"
click node_court_detect "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/vision/court_detector.py"
click node_court_picker "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/vision/court_picker.py"
click node_visualization "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/viz/overlay.py"
click node_viz_helpers "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/viz/_utils.py"
click node_python_metrics "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/analysis/metrics.py"
click node_python_report "https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/llm/report.py"
click node_web_app "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/App.tsx"
click node_video_source "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/services/video-source.ts"
click node_worker_client "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/services/worker-client.ts"
click node_editors "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/components/CourtEditor.tsx"
click node_web_results "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/components/Results.tsx"
click node_engine "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/worker/engine.worker.ts"
click node_model_cache "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/worker/model-cache.ts"
click node_web_vision "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/worker/vision.ts"
click node_web_metrics "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/analysis/metrics.ts"
click node_overlay_render "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/services/render-overlay.ts"
click node_web_report "https://github.com/yeonseong-lee/rallylens/blob/main/web/src/services/report.ts"

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_cli_entry,node_orchestrator,node_downloader,node_video_domain,node_artifact_io,node_python_user,node_web_user toneBlue
class node_player_detect,node_shuttle_track,node_court_pipeline,node_court_detect,node_court_picker toneAmber
class node_visualization,node_viz_helpers,node_python_metrics,node_python_report toneMint
class node_web_app,node_video_source,node_worker_client,node_editors,node_web_results toneRose
class node_engine,node_model_cache,node_web_vision,node_web_metrics,node_overlay_render,node_web_report,node_vertex toneIndigo
```

## Components

### Python CLI

- [CLI commands](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/cli.py): `src/rallylens/cli.py`
- [Run orchestrator](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/pipeline/orchestrator.py): `src/rallylens/pipeline/orchestrator.py`
- [Video downloader](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/ingest/downloader.py): `src/rallylens/ingest/downloader.py`
- [Video metadata](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/domain/video.py): `src/rallylens/domain/video.py`
- [Artifact I/O](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/pipeline/io.py): `src/rallylens/pipeline/io.py`

### Video Analysis

- [Player tracking](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/vision/detect_track.py): `src/rallylens/vision/detect_track.py`
- [Shuttle tracking](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/vision/shuttle_tracker.py): `src/rallylens/vision/shuttle_tracker.py`
- [Court calibration](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/pipeline/court.py): `src/rallylens/pipeline/court.py`
- [Automatic court detector](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/vision/court_detector.py): `src/rallylens/vision/court_detector.py`
- [Manual court picker](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/vision/court_picker.py): `src/rallylens/vision/court_picker.py`

### Metrics and Reports

- [Video and court views](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/viz/overlay.py): `src/rallylens/viz/overlay.py`
- [Visualization helpers](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/viz/_utils.py): `src/rallylens/viz/_utils.py`
- [Match metrics](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/analysis/metrics.py): `src/rallylens/analysis/metrics.py`
- [LLM report generation](https://github.com/yeonseong-lee/rallylens/blob/main/src/rallylens/llm/report.py): `src/rallylens/llm/report.py`

### Browser App

- [Analysis interface](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [Video input validation](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/services/video-source.ts): `web/src/services/video-source.ts`
- [Worker client](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/services/worker-client.ts): `web/src/services/worker-client.ts`
- [Court and identity editors](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/components/CourtEditor.tsx): `web/src/components/CourtEditor.tsx`
- [Results and exports](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/components/Results.tsx): `web/src/components/Results.tsx`

### Browser Analysis

- [Analysis worker](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/worker/engine.worker.ts): `web/src/worker/engine.worker.ts`
- [Verified model cache](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/worker/model-cache.ts): `web/src/worker/model-cache.ts`
- [Player inference and tracking](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/worker/vision.ts): `web/src/worker/vision.ts`
- [Browser metrics](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/analysis/metrics.ts): `web/src/analysis/metrics.ts`
- [Overlay rendering](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/services/render-overlay.ts): `web/src/services/render-overlay.ts`
- [Optional report](https://github.com/yeonseong-lee/rallylens/blob/main/web/src/services/report.ts): `web/src/services/report.ts`

### Other components

- **CLI user**
- **Vertex AI Gemini**
- **Browser user**

## Connections

- CLI user → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → Run orchestrator: starts run (evidence: `src/rallylens/cli.py`)
- CLI commands → Video downloader: downloads video (evidence: `src/rallylens/cli.py`)
- Video downloader → Vertex AI Gemini: fetches source
- Video downloader → Video metadata: returns metadata (evidence: `src/rallylens/ingest/downloader.py`)
- Run orchestrator → Video downloader: downloads input (evidence: `src/rallylens/pipeline/orchestrator.py`)
- Run orchestrator → Player tracking: tracks players (evidence: `src/rallylens/pipeline/orchestrator.py`)
- Run orchestrator → Shuttle tracking: tracks shuttle (evidence: `src/rallylens/pipeline/orchestrator.py`)
- Run orchestrator → Court calibration: calibrates court (evidence: `src/rallylens/pipeline/orchestrator.py`)
- Run orchestrator → Artifact I/O: uses artifacts (evidence: `src/rallylens/pipeline/orchestrator.py`)
- Court calibration → Automatic court detector: detects corners (evidence: `src/rallylens/pipeline/court.py`)
- Court calibration → Manual court picker: offers manual picking (evidence: `src/rallylens/pipeline/court.py`)
- CLI commands → Video and court views: creates visualizations (evidence: `README.md`)
- Video and court views → Visualization helpers: uses rendering helpers (evidence: `src/rallylens/viz/overlay.py`)
- CLI commands → Match metrics: computes metrics (evidence: `README.md`)
- CLI commands → LLM report generation: runs report command (evidence: `README.md`)
- LLM report generation → Vertex AI Gemini: requests analysis (evidence: `README.md`)
- Browser user → Analysis interface: uses app (evidence: `README.md`)
- Analysis interface → Video input validation: validates input (evidence: `web/src/App.tsx`)
- Analysis interface → Worker client: starts analysis (evidence: `web/src/App.tsx`)
- Worker client → Analysis worker: dispatches commands (evidence: `web/src/services/worker-client.ts`)
- Analysis interface → Court and identity editors: presents corrections (evidence: `web/src/App.tsx`)
- Analysis interface → Results and exports: shows results (evidence: `web/src/App.tsx`)
- Analysis worker → Verified model cache: loads verified models (evidence: `web/src/worker/engine.worker.ts`)
- Analysis worker → Player inference and tracking: runs player tracking (evidence: `web/src/worker/engine.worker.ts`)
- Analysis worker → Browser metrics: computes metrics (evidence: `web/src/worker/engine.worker.ts`)
- Results and exports → Browser metrics: recomputes metrics (evidence: `web/src/components/Results.tsx`)
- Results and exports → Overlay rendering: exports overlay (evidence: `web/src/components/Results.tsx`)
- Results and exports → Optional report: requests report (evidence: `web/src/components/Results.tsx`)
