# thekarak/varuna architecture

> Architecture diagram of the GitHub repository thekarak/varuna, 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/thekarak/varuna
- Repository: https://github.com/thekarak/varuna

## Overview

V.A.R.U.N.A. is a maritime oil-spill forensics platform. Its principal workflow accepts a SAR scene and detection parameters through the API, asynchronously enhances and segments the imagery, estimates spill age and volume, hindcasts drift, and correlates the likely discharge window with AIS tracks to score suspect vessels. Results support a tactical GIS dashboard and forensic case-file generation. The sampled code confirms orchestration and several stage calls; other product capabilities and presentation links are retained where documented in the README, with evidence limits reflected in the graph.

Main entry points: [`backend/app/workers/tasks.py`](https://github.com/thekarak/varuna/blob/main/backend/app/workers/tasks.py) (Pipeline worker), [`backend/app/main.py`](https://github.com/thekarak/varuna/blob/main/backend/app/main.py) (Analysis API), [`ml_pipeline/super_resolution/esrgan_inference.py`](https://github.com/thekarak/varuna/blob/main/ml_pipeline/super_resolution/esrgan_inference.py) (Image enhancement), [`ml_pipeline/segmentation/unet_inference.py`](https://github.com/thekarak/varuna/blob/main/ml_pipeline/segmentation/unet_inference.py) (Slick segmentation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["API orchestration"]
  node_api["Analysis API<br/>[main.py]"]
  node_pipeline["Pipeline worker<br/>[tasks.py]"]
end

subgraph group_analysis["Forensic analysis"]
  node_enhance["Image enhancement"]
  node_segment["Slick segmentation<br/>[unet_inference.py]"]
  node_classifier["Oil classifier"]
  node_lookalike["Lookalike training"]
  node_drift["Drift hindcast"]
end

subgraph group_attribution["Vessel attribution"]
  node_ais["AIS correlation scoring<br/>[ais_service.py]"]
  node_telemetry[("AIS trajectory store<br/>[db_models.py]")]
  node_casefile["Forensic case file<br/>[tasks.py]"]
end

subgraph group_presentation["Operations interface"]
  node_dashboard["Tactical GIS dashboard<br/>[DashboardApp.jsx]"]
  node_globe["3D mission globe<br/>[Globe.jsx]"]
  node_client["Forensic API client<br/>[forensicApi.js]"]
  node_login["Login interface<br/>[LoginApp.jsx]"]
end

node_authority(("Maritime analyst"))
node_sar["SAR scene"]
node_metocean["Metocean feeds"]

node_authority -->|"submits analysis"| node_api
node_api -->|"dispatches task"| node_pipeline
node_sar -.->|"supplies scene"| node_enhance
node_pipeline -->|"calls"| node_enhance
node_enhance -->|"upscaled image"| node_segment
node_segment -.->|"classifies oil"| node_classifier
node_pipeline -->|"calls"| node_drift
node_drift -->|"fetches forcing"| node_metocean
node_pipeline -->|"queries and scores"| node_ais
node_ais -->|"queries trajectories"| node_telemetry
node_pipeline -.->|"generates evidence"| node_casefile
node_pipeline -.->|"provides forensic results"| node_dashboard
node_client -.->|"requests analysis"| node_api
node_dashboard -.->|"links mission view"| node_globe

click node_api "https://github.com/thekarak/varuna/blob/main/backend/app/main.py"
click node_pipeline "https://github.com/thekarak/varuna/blob/main/backend/app/workers/tasks.py"
click node_enhance "https://github.com/thekarak/varuna/blob/main/ml_pipeline/super_resolution/esrgan_inference.py"
click node_segment "https://github.com/thekarak/varuna/blob/main/ml_pipeline/segmentation/unet_inference.py"
click node_classifier "https://github.com/thekarak/varuna/blob/main/ml_pipeline/segmentation/train_oil_classifier.py"
click node_lookalike "https://github.com/thekarak/varuna/blob/main/ml_pipeline/segmentation/train_lookalike_stage2.py"
click node_drift "https://github.com/thekarak/varuna/blob/main/ml_pipeline/drift_engine/lagrangian_simulator.py"
click node_ais "https://github.com/thekarak/varuna/blob/main/backend/app/services/ais_service.py"
click node_telemetry "https://github.com/thekarak/varuna/blob/main/backend/app/models/db_models.py"
click node_casefile "https://github.com/thekarak/varuna/blob/main/backend/app/workers/tasks.py"
click node_dashboard "https://github.com/thekarak/varuna/blob/main/frontend/components/DashboardApp.jsx"
click node_globe "https://github.com/thekarak/varuna/blob/main/frontend/components/Globe.jsx"
click node_client "https://github.com/thekarak/varuna/blob/main/frontend/services/forensicApi.js"
click node_login "https://github.com/thekarak/varuna/blob/main/frontend/components/LoginApp.jsx"

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_api,node_pipeline toneBlue
class node_enhance,node_segment,node_classifier,node_lookalike,node_drift toneAmber
class node_ais,node_telemetry,node_casefile toneMint
class node_dashboard,node_globe,node_client,node_login toneRose
class node_authority,node_sar,node_metocean toneIndigo
```

## Components

### API orchestration

- [Analysis API](https://github.com/thekarak/varuna/blob/main/backend/app/main.py): `backend/app/main.py`
- [Pipeline worker](https://github.com/thekarak/varuna/blob/main/backend/app/workers/tasks.py): `backend/app/workers/tasks.py`

### Forensic analysis

- [Image enhancement](https://github.com/thekarak/varuna/blob/main/ml_pipeline/super_resolution/esrgan_inference.py): `ml_pipeline/super_resolution/esrgan_inference.py`
- [Slick segmentation](https://github.com/thekarak/varuna/blob/main/ml_pipeline/segmentation/unet_inference.py): `ml_pipeline/segmentation/unet_inference.py`
- [Oil classifier](https://github.com/thekarak/varuna/blob/main/ml_pipeline/segmentation/train_oil_classifier.py): `ml_pipeline/segmentation/train_oil_classifier.py`
- [Lookalike training](https://github.com/thekarak/varuna/blob/main/ml_pipeline/segmentation/train_lookalike_stage2.py): `ml_pipeline/segmentation/train_lookalike_stage2.py`
- [Drift hindcast](https://github.com/thekarak/varuna/blob/main/ml_pipeline/drift_engine/lagrangian_simulator.py): `ml_pipeline/drift_engine/lagrangian_simulator.py`

### Vessel attribution

- [AIS correlation scoring](https://github.com/thekarak/varuna/blob/main/backend/app/services/ais_service.py): `backend/app/services/ais_service.py`
- [AIS trajectory store](https://github.com/thekarak/varuna/blob/main/backend/app/models/db_models.py): `backend/app/models/db_models.py`
- [Forensic case file](https://github.com/thekarak/varuna/blob/main/backend/app/workers/tasks.py): `backend/app/workers/tasks.py`

### Operations interface

- [Tactical GIS dashboard](https://github.com/thekarak/varuna/blob/main/frontend/components/DashboardApp.jsx): `frontend/components/DashboardApp.jsx`
- [3D mission globe](https://github.com/thekarak/varuna/blob/main/frontend/components/Globe.jsx): `frontend/components/Globe.jsx`
- [Forensic API client](https://github.com/thekarak/varuna/blob/main/frontend/services/forensicApi.js): `frontend/services/forensicApi.js`
- [Login interface](https://github.com/thekarak/varuna/blob/main/frontend/components/LoginApp.jsx): `frontend/components/LoginApp.jsx`

### Other components

- **Maritime analyst**
- **SAR scene**
- **Metocean feeds**

## Connections

- Maritime analyst → Analysis API: submits analysis (evidence: `backend/app/main.py`)
- Analysis API → Pipeline worker: dispatches task (evidence: `backend/app/main.py`)
- SAR scene → Image enhancement: supplies scene
- Pipeline worker → Image enhancement: calls (evidence: `backend/app/workers/tasks.py`)
- Image enhancement → Slick segmentation: upscaled image (evidence: `backend/app/workers/tasks.py`)
- Slick segmentation → Oil classifier: classifies oil (evidence: `ml_pipeline/segmentation/unet_inference.py`)
- Pipeline worker → Drift hindcast: calls (evidence: `backend/app/workers/tasks.py`)
- Drift hindcast → Metocean feeds: fetches forcing (evidence: `ml_pipeline/drift_engine/lagrangian_simulator.py`)
- Pipeline worker → AIS correlation scoring: queries and scores (evidence: `backend/app/workers/tasks.py`)
- AIS correlation scoring → AIS trajectory store: queries trajectories (evidence: `backend/app/services/ais_service.py`)
- Pipeline worker → Forensic case file: generates evidence (evidence: `backend/app/workers/tasks.py`)
- Pipeline worker → Tactical GIS dashboard: provides forensic results
- Forensic API client → Analysis API: requests analysis
- Tactical GIS dashboard → 3D mission globe: links mission view
