# benkraoudaamine0/pca_from_scratch architecture

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

- Interactive diagram: https://gitdiagram.com/benkraoudaamine0/pca_from_scratch
- Repository: https://github.com/benkraoudaamine0/pca_from_scratch

## Overview

This is a browser-based PCA analysis application. Users upload a CSV, choose normalization and a component-selection method, and receive PCA results to explore through plots and matrix views; the backend also exposes an AI interpretation endpoint. The graph follows the documented workflow and the sampled API, PCA, schema, and frontend code. Some rendering and interpretation wiring is only partially excerpted, so those relationships are omitted where the available evidence does not establish them.

Main entry points: [`backend/main.py`](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/main.py) (Analysis endpoints), [`frontend/script.js`](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js) (Upload and dashboard), [`frontend/index.html`](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/index.html) (Analysis interface), [`backend/shema/models.py`](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/shema/models.py) (Response schemas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser interface"]
  node_web_ui["Analysis interface<br/>[index.html]"]
  node_browser_logic["Upload and dashboard<br/>[script.js]"]
  node_scree["Scree plots<br/>[script.js]"]
  node_factor_views["Factor visualizations<br/>[script.js]"]
  node_matrix_metrics["Matrices and metrics<br/>[script.js]"]
end

subgraph group_api["Analysis API"]
  node_api_routes["Analysis endpoints<br/>[main.py]"]
  node_file_prep["Data preparation<br/>[main.py]"]
  node_response_models["Response schemas<br/>[models.py]"]
end

subgraph group_pca["PCA computation"]
  node_pca_engine["PCA engine<br/>[logic.py]"]
end

subgraph group_integration["Interpretation integration"]
  node_gemini{{"Gemini service"}}
end

node_user(("Analyst"))

node_user -->|"uses"| node_web_ui
node_web_ui -->|"hosts"| node_browser_logic
node_browser_logic -->|"posts analysis"| node_api_routes
node_api_routes -->|"reads upload"| node_file_prep
node_api_routes -->|"runs PCA"| node_pca_engine
node_api_routes -->|"validates response"| node_response_models
node_api_routes -->|"returns results"| node_browser_logic
node_browser_logic -->|"renders plots"| node_scree
node_browser_logic -->|"renders views"| node_factor_views
node_browser_logic -->|"renders tables"| node_matrix_metrics
node_api_routes -->|"requests interpretation"| node_gemini

click node_web_ui "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/index.html"
click node_browser_logic "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js"
click node_scree "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js"
click node_factor_views "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js"
click node_matrix_metrics "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js"
click node_api_routes "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/main.py"
click node_file_prep "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/main.py"
click node_response_models "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/shema/models.py"
click node_pca_engine "https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/core/logic.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_web_ui,node_browser_logic,node_scree,node_factor_views,node_matrix_metrics toneBlue
class node_api_routes,node_file_prep,node_response_models toneAmber
class node_pca_engine toneMint
class node_gemini toneRose
class node_user toneIndigo
```

## Components

### Browser interface

- [Analysis interface](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/index.html): `frontend/index.html`
- [Upload and dashboard](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js): `frontend/script.js`
- [Scree plots](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js): `frontend/script.js`
- [Factor visualizations](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js): `frontend/script.js`
- [Matrices and metrics](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/frontend/script.js): `frontend/script.js`

### Analysis API

- [Analysis endpoints](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/main.py): `backend/main.py`
- [Data preparation](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/main.py): `backend/main.py`
- [Response schemas](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/shema/models.py): `backend/shema/models.py`

### PCA computation

- [PCA engine](https://github.com/benkraoudaamine0/pca_from_scratch/blob/main/backend/core/logic.py): `backend/core/logic.py`

### Interpretation integration

- **Gemini service**

### Other components

- **Analyst**

## Connections

- Analyst → Analysis interface: uses (evidence: `README.md`)
- Analysis interface → Upload and dashboard: hosts (evidence: `README.md`)
- Upload and dashboard → Analysis endpoints: posts analysis (evidence: `frontend/script.js`)
- Analysis endpoints → Data preparation: reads upload (evidence: `backend/main.py`)
- Analysis endpoints → PCA engine: runs PCA (evidence: `backend/main.py`)
- Analysis endpoints → Response schemas: validates response (evidence: `backend/main.py`)
- Analysis endpoints → Upload and dashboard: returns results (evidence: `frontend/script.js`)
- Upload and dashboard → Scree plots: renders plots (evidence: `README.md`)
- Upload and dashboard → Factor visualizations: renders views (evidence: `frontend/script.js`)
- Upload and dashboard → Matrices and metrics: renders tables (evidence: `frontend/script.js`)
- Analysis endpoints → Gemini service: requests interpretation (evidence: `backend/main.py`)
