# rajat1606-dev/spandana2 architecture

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

- Interactive diagram: https://gitdiagram.com/rajat1606-dev/spandana2
- Repository: https://github.com/rajat1606-dev/spandana2

## Overview

SPANDANA is a research-oriented LVH screening workspace: users load a 12-lead ECG, inspect waveform and voltage-rule results, request backend Perceptron/CNN screening, then compare models and review research metrics. The browser decodes uploads and calculates Sokolow–Lyon/Cornell locally; AI inference is backend-only. A separate PTB-XL training and evaluation workflow produces the models and comparison metrics. Connections to unsampled views and training stages are included only where the README or source index supports them.

Main entry points: [`src/app/page.tsx`](https://github.com/rajat1606-dev/spandana2/blob/main/src/app/page.tsx) (Workspace shell), [`backend/app/api/routes.py`](https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/api/routes.py) (FastAPI routes), [`src/store/analyses.ts`](https://github.com/rajat1606-dev/spandana2/blob/main/src/store/analyses.ts) (Analysis state), [`backend/models/metrics.json`](https://github.com/rajat1606-dev/spandana2/blob/main/backend/models/metrics.json) (Evaluation metrics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Screening workspace"]
  node_shell["Workspace shell<br/>[page.tsx]"]
  node_upload["ECG upload<br/>[UploadView.tsx]"]
  node_visual["Signal visualization"]
  node_criteria_view["Criteria analysis<br/>[CriteriaView.tsx]"]
  node_screen_view["AI screening<br/>[ScreeningView.tsx]"]
  node_comparison["Model comparison<br/>[ComparisonView.tsx]"]
  node_reports["Analysis reports<br/>[ReportsView.tsx]"]
  node_research_view["Research information<br/>[ResearchView.tsx]"]
end

subgraph group_ecg["ECG processing"]
  node_parser["ECG file decoders<br/>[parsers.ts]"]
  node_criteria["Voltage criteria<br/>[criteria.ts]"]
  node_store["Analysis state<br/>[analyses.ts]"]
end

subgraph group_service["Screening API"]
  node_api["FastAPI routes<br/>[routes.py]"]
  node_decoder["Backend ECG decoder<br/>[ecg_io.py]"]
  node_screening["Prediction service<br/>[screening.py]"]
  node_status["Model status<br/>[model_status.py]"]
end

subgraph group_research["Model research"]
  node_predict["Inference pipeline<br/>[predict_ecg.py]"]
  node_cnn["CNN architecture<br/>[cnn_model.py]"]
  node_train["CNN training<br/>[train_cnn.py]"]
  node_research_pipeline["PTB-XL pipeline"]
  node_evaluation["Model evaluation<br/>[evaluate_all.py]"]
  node_metrics["Evaluation metrics<br/>[metrics.json]"]
end

node_clinician(("Research user"))

node_clinician -->|"uses"| node_shell
node_shell -->|"routes to"| node_upload
node_shell -->|"routes to"| node_visual
node_shell -->|"routes to"| node_criteria_view
node_shell -->|"routes to"| node_screen_view
node_shell -->|"routes to"| node_comparison
node_shell -->|"routes to"| node_reports
node_shell -->|"routes to"| node_research_view
node_upload -->|"decodes files"| node_parser
node_parser -->|"parsed ECG"| node_store
node_store -->|"computes criteria"| node_criteria
node_criteria_view -.->|"shows results"| node_criteria
node_screen_view -.->|"requests screening"| node_api
node_api -->|"decodes uploads"| node_decoder
node_api -->|"runs screening"| node_screening
node_api -->|"checks artifacts"| node_status
node_screening -.->|"gets predictions"| node_predict
node_predict -->|"uses model"| node_cnn
node_train -->|"trains model"| node_cnn
node_research_pipeline -.->|"prepares training"| node_train
node_research_pipeline -.->|"evaluates methods"| node_evaluation
node_evaluation -->|"writes metrics"| node_metrics
node_comparison -.->|"presents metrics"| node_metrics
node_reports -.->|"reports analyses"| node_store
node_research_view -.->|"shows evidence"| node_metrics

click node_shell "https://github.com/rajat1606-dev/spandana2/blob/main/src/app/page.tsx"
click node_upload "https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/UploadView.tsx"
click node_visual "https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/VisualizationView.tsx"
click node_criteria_view "https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/CriteriaView.tsx"
click node_screen_view "https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/ScreeningView.tsx"
click node_comparison "https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/ComparisonView.tsx"
click node_reports "https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/ReportsView.tsx"
click node_research_view "https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/ResearchView.tsx"
click node_parser "https://github.com/rajat1606-dev/spandana2/blob/main/src/lib/ecg/parsers.ts"
click node_criteria "https://github.com/rajat1606-dev/spandana2/blob/main/src/lib/ecg/criteria.ts"
click node_store "https://github.com/rajat1606-dev/spandana2/blob/main/src/store/analyses.ts"
click node_api "https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/api/routes.py"
click node_decoder "https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/services/ecg_io.py"
click node_screening "https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/services/screening.py"
click node_status "https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/services/model_status.py"
click node_predict "https://github.com/rajat1606-dev/spandana2/blob/main/training/predict_ecg.py"
click node_cnn "https://github.com/rajat1606-dev/spandana2/blob/main/training/cnn_model.py"
click node_train "https://github.com/rajat1606-dev/spandana2/blob/main/training/train_cnn.py"
click node_research_pipeline "https://github.com/rajat1606-dev/spandana2/tree/main/training"
click node_evaluation "https://github.com/rajat1606-dev/spandana2/blob/main/training/evaluate_all.py"
click node_metrics "https://github.com/rajat1606-dev/spandana2/blob/main/backend/models/metrics.json"

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_shell,node_upload,node_visual,node_criteria_view,node_screen_view,node_comparison,node_reports,node_research_view,node_clinician toneBlue
class node_parser,node_criteria,node_store toneAmber
class node_api,node_decoder,node_screening,node_status toneMint
class node_predict,node_cnn,node_train,node_research_pipeline,node_evaluation,node_metrics toneRose
```

## Components

### Screening workspace

- [Workspace shell](https://github.com/rajat1606-dev/spandana2/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [ECG upload](https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/UploadView.tsx): `src/components/views/UploadView.tsx`
- [Signal visualization](https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/VisualizationView.tsx): `src/components/views/VisualizationView.tsx`
- [Criteria analysis](https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/CriteriaView.tsx): `src/components/views/CriteriaView.tsx`
- [AI screening](https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/ScreeningView.tsx): `src/components/views/ScreeningView.tsx`
- [Model comparison](https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/ComparisonView.tsx): `src/components/views/ComparisonView.tsx`
- [Analysis reports](https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/ReportsView.tsx): `src/components/views/ReportsView.tsx`
- [Research information](https://github.com/rajat1606-dev/spandana2/blob/main/src/components/views/ResearchView.tsx): `src/components/views/ResearchView.tsx`

### ECG processing

- [ECG file decoders](https://github.com/rajat1606-dev/spandana2/blob/main/src/lib/ecg/parsers.ts): `src/lib/ecg/parsers.ts`
- [Voltage criteria](https://github.com/rajat1606-dev/spandana2/blob/main/src/lib/ecg/criteria.ts): `src/lib/ecg/criteria.ts`
- [Analysis state](https://github.com/rajat1606-dev/spandana2/blob/main/src/store/analyses.ts): `src/store/analyses.ts`

### Screening API

- [FastAPI routes](https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Backend ECG decoder](https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/services/ecg_io.py): `backend/app/services/ecg_io.py`
- [Prediction service](https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/services/screening.py): `backend/app/services/screening.py`
- [Model status](https://github.com/rajat1606-dev/spandana2/blob/main/backend/app/services/model_status.py): `backend/app/services/model_status.py`

### Model research

- [Inference pipeline](https://github.com/rajat1606-dev/spandana2/blob/main/training/predict_ecg.py): `training/predict_ecg.py`
- [CNN architecture](https://github.com/rajat1606-dev/spandana2/blob/main/training/cnn_model.py): `training/cnn_model.py`
- [CNN training](https://github.com/rajat1606-dev/spandana2/blob/main/training/train_cnn.py): `training/train_cnn.py`
- [PTB-XL pipeline](https://github.com/rajat1606-dev/spandana2/tree/main/training): `training`
- [Model evaluation](https://github.com/rajat1606-dev/spandana2/blob/main/training/evaluate_all.py): `training/evaluate_all.py`
- [Evaluation metrics](https://github.com/rajat1606-dev/spandana2/blob/main/backend/models/metrics.json): `backend/models/metrics.json`

### Other components

- **Research user**

## Connections

- Research user → Workspace shell: uses
- Workspace shell → ECG upload: routes to (evidence: `src/app/page.tsx`)
- Workspace shell → Signal visualization: routes to (evidence: `src/app/page.tsx`)
- Workspace shell → Criteria analysis: routes to (evidence: `src/app/page.tsx`)
- Workspace shell → AI screening: routes to (evidence: `src/app/page.tsx`)
- Workspace shell → Model comparison: routes to (evidence: `src/app/page.tsx`)
- Workspace shell → Analysis reports: routes to (evidence: `src/app/page.tsx`)
- Workspace shell → Research information: routes to (evidence: `src/app/page.tsx`)
- ECG upload → ECG file decoders: decodes files
- ECG file decoders → Analysis state: parsed ECG
- Analysis state → Voltage criteria: computes criteria (evidence: `src/store/analyses.ts`)
- Criteria analysis → Voltage criteria: shows results
- AI screening → FastAPI routes: requests screening
- FastAPI routes → Backend ECG decoder: decodes uploads (evidence: `backend/app/api/routes.py`)
- FastAPI routes → Prediction service: runs screening (evidence: `backend/app/api/routes.py`)
- FastAPI routes → Model status: checks artifacts (evidence: `backend/app/api/routes.py`)
- Prediction service → Inference pipeline: gets predictions
- Inference pipeline → CNN architecture: uses model (evidence: `training/predict_ecg.py`)
- CNN training → CNN architecture: trains model (evidence: `training/train_cnn.py`)
- PTB-XL pipeline → CNN training: prepares training (evidence: `training/train_cnn.py`)
- PTB-XL pipeline → Model evaluation: evaluates methods (evidence: `training/evaluate_all.py`)
- Model evaluation → Evaluation metrics: writes metrics
- Model comparison → Evaluation metrics: presents metrics
- Analysis reports → Analysis state: reports analyses
- Research information → Evaluation metrics: shows evidence
