# akbar3776/phantom-worlds-prototype architecture

> Architecture diagram of the GitHub repository akbar3776/phantom-worlds-prototype, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akbar3776/phantom-worlds-prototype
- Repository: https://github.com/akbar3776/phantom-worlds-prototype

## Overview

Phantom Worlds is an astronomy research application combining SPHEREx/Gaia data preparation, spectral ML, time-series source analysis, artifact screening, proof reporting, and a web/API interface. The documented primary path runs from archive data and preprocessing through analysis to UI/API results; training and proof generation are additional product workflows. Edges are limited to relationships shown in the README or sampled source references; several internal API routes and unsampled modules are only described at subsystem level.

Main entry points: [`phantom_worlds/api.py`](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/api.py) (FastAPI service), [`phantom_worlds/contracts.py`](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/contracts.py) (Hour-0 contracts), [`phantom_worlds/tier_b_detectors.py`](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_b_detectors.py) (Tier B detectors), [`phantom_worlds/fits_cutout.py`](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/fits_cutout.py) (FITS cutouts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_acquisition["Archive acquisition"]
  node_fits["FITS cutouts<br/>[fits_cutout.py]"]
  node_contracts[("Hour-0 contracts<br/>[contracts.py]")]
  node_dataset["Spectral dataset<br/>[real_ml_data.py]"]
  node_catalog["ML catalog"]
end

subgraph group_science["Science analysis"]
  node_tier_a["Tier A metrics<br/>[tier_a_metrics.py]"]
  node_tier_b_engine["PSF deblending<br/>[tier_b_engine.py]"]
  node_detectors["Tier B detectors"]
  node_sso["Solar system ephemeris<br/>[sso.py]"]
  node_proof["Proof evaluation<br/>[tier_b_proof.py]"]
end

subgraph group_ml["Spectral ML"]
  node_training["Model training<br/>[train.py]"]
  node_pipeline["Spectral inference<br/>[ml_pipeline.py]"]
  node_checkpoint[("Trained checkpoint")]
end

subgraph group_delivery["Product delivery"]
  node_api["FastAPI service<br/>[api.py]"]
  node_viewer["Time-series viewer<br/>[viewer.js]"]
  node_fallback["Offline fallback<br/>[fallback_data.js]"]
end

node_astronomer(("Astronomer"))
node_archives[("Astronomy archives")]
node_user(("Web/API user"))

node_archives -->|"provides data"| node_acquisition
node_acquisition -->|"finds frames"| node_fits
node_fits -->|"builds cutouts"| node_contracts
node_fits -->|"extracts cubes"| node_dataset
node_dataset -->|"supplies spectra"| node_training
node_training -->|"trains model"| node_pipeline
node_training -->|"exports checkpoint"| node_checkpoint
node_checkpoint -->|"loads at startup"| node_api
node_contracts -->|"provides contracts"| node_tier_a
node_contracts -->|"provides contracts"| node_tier_b_engine
node_fits -->|"reads cutouts"| node_tier_b_engine
node_tier_b_engine -->|"prepares scenes"| node_detectors
node_contracts -->|"loads contracts"| node_detectors
node_pipeline -->|"classifies candidates"| node_detectors
node_sso -->|"serves ephemeris"| node_api
node_tier_a -->|"serves metrics"| node_api
node_detectors -->|"serves searches"| node_api
node_proof -->|"serves proof"| node_api
node_api -->|"computes metrics"| node_tier_a
node_api -->|"serves interface"| node_viewer
node_api -->|"serves fallback"| node_fallback
node_user -->|"requests analysis"| node_api
node_user -->|"uses viewer"| node_viewer
node_catalog -->|"builds catalog"| node_dataset
node_proof -->|"reads contracts"| node_contracts
node_proof -->|"evaluates detections"| node_detectors

click node_acquisition "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds_dataset_kit/scripts/download_real_spherex_gaia.py"
click node_fits "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/fits_cutout.py"
click node_contracts "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/contracts.py"
click node_dataset "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/real_ml_data.py"
click node_catalog "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds_dataset_kit/scripts/build_ml_catalog.py"
click node_tier_a "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_a_metrics.py"
click node_tier_b_engine "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_b_engine.py"
click node_detectors "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_b_detectors.py"
click node_sso "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/sso.py"
click node_proof "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_b_proof.py"
click node_training "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/ml/train.py"
click node_pipeline "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/ml_pipeline.py"
click node_checkpoint "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/ml/spectral_discovery_pipeline.pkl.gz"
click node_api "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/api.py"
click node_viewer "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/static/viewer.js"
click node_fallback "https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/static/fallback_data.js"

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_acquisition,node_fits,node_contracts,node_dataset,node_catalog,node_user toneBlue
class node_tier_a,node_tier_b_engine,node_detectors,node_sso,node_proof,node_archives toneAmber
class node_training,node_pipeline,node_checkpoint toneMint
class node_api,node_viewer,node_fallback toneRose
class node_astronomer toneIndigo
```

## Components

### Data preparation

- [Archive acquisition](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds_dataset_kit/scripts/download_real_spherex_gaia.py): `phantom_worlds_dataset_kit/scripts/download_real_spherex_gaia.py`
- [FITS cutouts](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/fits_cutout.py): `phantom_worlds/fits_cutout.py`
- [Hour-0 contracts](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/contracts.py): `phantom_worlds/contracts.py`
- [Spectral dataset](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/real_ml_data.py): `phantom_worlds/real_ml_data.py`
- [ML catalog](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds_dataset_kit/scripts/build_ml_catalog.py): `phantom_worlds_dataset_kit/scripts/build_ml_catalog.py`

### Science analysis

- [Tier A metrics](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_a_metrics.py): `phantom_worlds/tier_a_metrics.py`
- [PSF deblending](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_b_engine.py): `phantom_worlds/tier_b_engine.py`
- [Tier B detectors](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_b_detectors.py): `phantom_worlds/tier_b_detectors.py`
- [Solar system ephemeris](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/sso.py): `phantom_worlds/sso.py`
- [Proof evaluation](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/tier_b_proof.py): `phantom_worlds/tier_b_proof.py`

### Spectral ML

- [Model training](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/ml/train.py): `ml/train.py`
- [Spectral inference](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/ml_pipeline.py): `phantom_worlds/ml_pipeline.py`
- [Trained checkpoint](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/ml/spectral_discovery_pipeline.pkl.gz): `ml/spectral_discovery_pipeline.pkl.gz`

### Product delivery

- [FastAPI service](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/api.py): `phantom_worlds/api.py`
- [Time-series viewer](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/static/viewer.js): `phantom_worlds/static/viewer.js`
- [Offline fallback](https://github.com/akbar3776/phantom-worlds-prototype/blob/main/phantom_worlds/static/fallback_data.js): `phantom_worlds/static/fallback_data.js`

### Other components

- **Astronomer**
- **Astronomy archives**
- **Web/API user**

## Connections

- Astronomy archives → Archive acquisition: provides data (evidence: `README.md`)
- Archive acquisition → FITS cutouts: finds frames (evidence: `README.md`)
- FITS cutouts → Hour-0 contracts: builds cutouts (evidence: `README.md`)
- FITS cutouts → Spectral dataset: extracts cubes (evidence: `README.md`)
- Spectral dataset → Model training: supplies spectra (evidence: `README.md`)
- Model training → Spectral inference: trains model (evidence: `ml/train.py`)
- Model training → Trained checkpoint: exports checkpoint (evidence: `README.md`)
- Trained checkpoint → FastAPI service: loads at startup (evidence: `README.md`)
- Hour-0 contracts → Tier A metrics: provides contracts (evidence: `phantom_worlds/tier_a_metrics.py`)
- Hour-0 contracts → PSF deblending: provides contracts (evidence: `phantom_worlds/tier_b_engine.py`)
- FITS cutouts → PSF deblending: reads cutouts (evidence: `phantom_worlds/tier_b_engine.py`)
- PSF deblending → Tier B detectors: prepares scenes (evidence: `phantom_worlds/tier_b_detectors.py`)
- Hour-0 contracts → Tier B detectors: loads contracts (evidence: `phantom_worlds/tier_b_detectors.py`)
- Spectral inference → Tier B detectors: classifies candidates (evidence: `phantom_worlds/tier_b_detectors.py`)
- Solar system ephemeris → FastAPI service: serves ephemeris (evidence: `phantom_worlds/api.py`)
- Tier A metrics → FastAPI service: serves metrics (evidence: `phantom_worlds/api.py`)
- Tier B detectors → FastAPI service: serves searches (evidence: `phantom_worlds/api.py`)
- Proof evaluation → FastAPI service: serves proof (evidence: `phantom_worlds/api.py`)
- FastAPI service → Tier A metrics: computes metrics (evidence: `phantom_worlds/api.py`)
- FastAPI service → Time-series viewer: serves interface (evidence: `README.md`)
- FastAPI service → Offline fallback: serves fallback (evidence: `README.md`)
- Web/API user → FastAPI service: requests analysis (evidence: `README.md`)
- Web/API user → Time-series viewer: uses viewer (evidence: `README.md`)
- ML catalog → Spectral dataset: builds catalog (evidence: `phantom_worlds_dataset_kit/scripts/build_ml_catalog.py`)
- Proof evaluation → Hour-0 contracts: reads contracts (evidence: `phantom_worlds/tier_b_proof.py`)
- Proof evaluation → Tier B detectors: evaluates detections (evidence: `phantom_worlds/tier_b_proof.py`)
