# dhanush342/knee-osteoporosis-classification architecture

> Architecture diagram of the GitHub repository dhanush342/knee-osteoporosis-classification, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhanush342/knee-osteoporosis-classification
- Repository: https://github.com/dhanush342/knee-osteoporosis-classification

## Overview

1. **Repo shape**
   - This repository is a **hybrid AI application**: a **React/TypeScript frontend** for the osteoporosis risk assessment platform, plus a **Python ML stack** for knee X-ray classification and model training/evaluation.
   - The README emphasizes a **ResNet-50 transfer-learning classifier** for **binary prediction**: normal vs osteoporotic knees.

2. **Frontend application boundary**
   - The browser app lives primarily under `src/` and is built with **Vite + React + TypeScript**.
   - `src/main.tsx` and `src/App.tsx` are the top-level entry points, with global styling in `src/index.css` and `src/styles/globals.css`.
   - `build/` contains the compiled production bundle, so it is an output artifact rather than source architecture.

3. **User-facing workflow modules**
   - The main frontend features are split into focused components: `AssessmentForm`, `RiskCalculator`, `XrayUpload`, `AIAnalysis`, `AIResults`, `Results`, `Dashboard`, `RecentScans`, and `History`.
   - This suggests a flow where a user enters clinical context, optionally uploads an X-ray, receives a computed risk/classification result, and can review historical assessments or scans.

4. **UI system and design layer**
   - `src/components/ui/` contains a large reusable component library: buttons, dialogs, forms, tables, tabs, sliders, dropdowns, sheets, tooltips, charts, and more.
   - This is the shared presentation layer used by the feature components above, likely based on a shadcn/Radix-style design system.
   - `src/components/figma/ImageWithFallback.tsx` indicates a helper for resilient image rendering in the UI.

5. **Guidance and content layer**
   - `src/guidelines/Guidelines.md`, `src/components/MicrocopyGuide.tsx`, `src/components/UIFlowGuide.tsx`, `src/components/ProjectGuides.tsx`, and `src/Attributions.md` show that the frontend includes not just product UI, but also embedded guidance/documentation content.
   - These files suggest the app includes educational or onboarding content alongside the medical workflow.

6. **Backend API boundary**
   - The Python backend appears to be centered around `app_fastapi.py` and `run_api.py`, which likely expose inference and/or orchestration endpoints via **FastAPI**.
   - `API_README.md` indicates the API is treated as a distinct surface from the frontend, with the frontend consuming backend responses rather than doing all ML work locally.

7. **ML inference and training stack**
   - The core model pipeline is in `train_model.py`, `enhanced_trainer.py`, and `full_update_knee_classification.py`, which together suggest multiple training or retraining paths for the ResNet-50 classifier.
   - `feature_extractor.py` and `model_utils.py` look like shared ML utilities used across training and inference for preprocessing, feature handling, model loading, or prediction post-processing.
   - The README’s tech stack points to **TensorFlow/Keras** and **OpenCV** as the main ML/runtime dependencies.

8. **Accuracy and evaluation subsystem**
   - `accuracy_analysis/` is a separate analysis package with its own README, scripts, requirements, generated CSV results, and a text report.
   - This is an offline evaluation boundary: it likely consumes model outputs or test predictions and produces accuracy metrics, confusion matrix-style summaries, and human-readable reports.
   - The presence of `simple_accuracy.py`, `accuracy_analyzer.py`, and `example_usage.py` suggests the repo separates **model training** from **evaluation/reporting**.

9. **Data and history**
   - `patienthistory.csv` is the most visible persisted data artifact in the root, implying the app may store or replay prior assessments.
   - That makes historical review part of the system architecture, not just a transient one-off inference flow.

10. **Project/runtime/tooling boundaries**
   - Frontend tooling: `package.json`, `package-lock.json`, `vite.config.ts`, `tailwind.config.js`, and `postcss.config.js`.
   - Backend/ML tooling: `requirements.txt`, `enhanced_requirements.txt`, and the scripts under the repo root and `accuracy_analysis/`.
   - This repo is therefore split across two runtimes: **Node.js for the UI build/development workflow** and **Python for ML/API execution**.

11. **How the data flows through the system**
   - Typical flow: user interaction in the React app → request to the FastAPI backend → ML preprocessing/model inference in Python → classification/risk output returned to the UI → results/history shown in the dashboard.
   - Separate offline flow: dataset/model outputs → accuracy analysis scripts → CSV/report artifacts used to validate or compare model performance.

12. **What to draw in an architecture diagram**
   - Draw two major domains: **frontend client** and **Python ML/API backend**.
   - Inside the frontend, group the assessment, upload, results, dashboard, and history components around a shared UI library.
   - Inside the backend, group API entrypoints, model utilities, feature extraction, training scripts, and evaluation tooling, with `accuracy_analysis/` as a separate offline analysis branch.

Main entry points: [`src/App.tsx`](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/App.tsx) (App shell), [`app_fastapi.py`](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/app_fastapi.py) (API entry), [`src/components/ui/button.tsx`](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/ui/button.tsx) (UI kit), [`model_utils.py`](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/model_utils.py) (Model utils)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend client"]
  node_src_main["Entry<br/>[main.tsx]"]
  node_src_app["App shell<br/>react shell<br/>[App.tsx]"]
  node_assessment_form["Assessment<br/>clinical form<br/>[AssessmentForm.tsx]"]
  node_risk_calculator["Risk calc<br/>decision logic<br/>[RiskCalculator.tsx]"]
  node_xray_upload["X-ray upload<br/>file intake<br/>[XrayUpload.tsx]"]
  node_ai_analysis["AI analysis<br/>inference UI<br/>[AIAnalysis.tsx]"]
  node_ai_results["AI results<br/>results view<br/>[AIResults.tsx]"]
  node_results_view["Results<br/>summary view<br/>[Results.tsx]"]
  node_dashboard["Dashboard<br/>overview UI<br/>[Dashboard.tsx]"]
  node_recent_scans["Recent scans<br/>history panel<br/>[RecentScans.tsx]"]
  node_history_view["History<br/>record view<br/>[History.tsx]"]
  node_ui_kit["UI kit<br/>design system<br/>[button.tsx]"]
  node_figma_helper["Image helper<br/>ui helper"]
  node_guides["Guides<br/>content layer<br/>[ProjectGuides.tsx]"]
  node_guidelines["Guidelines<br/>documentation<br/>[Guidelines.md]"]
end

subgraph group_backend["Python ML/API"]
  node_api_entry["API entry<br/>fastapi app<br/>[app_fastapi.py]"]
  node_api_runner["API runner<br/>server start<br/>[run_api.py]"]
  node_model_utils["Model utils<br/>ml utilities<br/>[model_utils.py]"]
  node_feature_extractor["Features<br/>ml preprocessing"]
  node_trainer["Trainer<br/>training pipeline<br/>[train_model.py]"]
  node_enhanced_trainer["Enhanced train<br/>training pipeline"]
  node_full_update["Full update<br/>retraining pipeline"]
end

subgraph group_analysis["Accuracy analysis"]
  node_accuracy_engine["Accuracy engine<br/>evaluation"]
  node_accuracy_pkg["Analysis pkg<br/>evaluation package"]
  node_accuracy_report["Report<br/>analysis artifact"]
end

node_patient_history[("Patient history<br/>data artifact<br/>[patienthistory.csv]")]

node_src_main -->|"mounts"| node_src_app
node_src_app -->|"uses"| node_assessment_form
node_src_app -->|"uses"| node_xray_upload
node_src_app -->|"uses"| node_ai_analysis
node_src_app -->|"uses"| node_results_view
node_src_app -->|"uses"| node_dashboard
node_src_app -->|"uses"| node_history_view
node_assessment_form -->|"feeds"| node_risk_calculator
node_xray_upload -->|"feeds"| node_ai_analysis
node_ai_analysis -->|"outputs"| node_ai_results
node_ai_results -->|"summarizes"| node_results_view
node_dashboard -->|"contains"| node_recent_scans
node_dashboard -->|"links"| node_history_view
node_assessment_form -->|"uses"| node_ui_kit
node_xray_upload -->|"uses"| node_ui_kit
node_ai_results -->|"uses"| node_ui_kit
node_figma_helper -->|"supports"| node_ui_kit
node_guides -->|"documents"| node_guidelines
node_api_runner -->|"starts"| node_api_entry
node_api_entry -->|"invokes"| node_model_utils
node_api_entry -->|"invokes"| node_feature_extractor
node_trainer -->|"reuses"| node_model_utils
node_enhanced_trainer -->|"reuses"| node_model_utils
node_full_update -->|"uses"| node_feature_extractor
node_full_update -->|"uses"| node_model_utils
node_accuracy_engine -->|"packages"| node_accuracy_pkg
node_accuracy_engine -->|"produces"| node_accuracy_report
node_src_app -->|"calls"| node_api_entry
node_api_entry -->|"reads/writes"| node_patient_history

click node_src_main "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/main.tsx"
click node_src_app "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/App.tsx"
click node_assessment_form "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/AssessmentForm.tsx"
click node_risk_calculator "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/RiskCalculator.tsx"
click node_xray_upload "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/XrayUpload.tsx"
click node_ai_analysis "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/AIAnalysis.tsx"
click node_ai_results "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/AIResults.tsx"
click node_results_view "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/Results.tsx"
click node_dashboard "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/Dashboard.tsx"
click node_recent_scans "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/RecentScans.tsx"
click node_history_view "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/History.tsx"
click node_ui_kit "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/ui/button.tsx"
click node_figma_helper "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/figma/ImageWithFallback.tsx"
click node_guides "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/ProjectGuides.tsx"
click node_guidelines "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/guidelines/Guidelines.md"
click node_api_entry "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/app_fastapi.py"
click node_api_runner "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/run_api.py"
click node_model_utils "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/model_utils.py"
click node_feature_extractor "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/feature_extractor.py"
click node_trainer "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/train_model.py"
click node_enhanced_trainer "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/enhanced_trainer.py"
click node_full_update "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/full_update_knee_classification.py"
click node_accuracy_engine "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/accuracy_analysis/accuracy_analyzer.py"
click node_accuracy_pkg "https://github.com/dhanush342/knee-osteoporosis-classification/tree/main/accuracy_analysis/accuracy_analysis"
click node_accuracy_report "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/accuracy_analysis/accuracy_report.txt"
click node_patient_history "https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/patienthistory.csv"

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_src_main,node_src_app,node_assessment_form,node_risk_calculator,node_xray_upload,node_ai_analysis,node_ai_results,node_results_view,node_dashboard,node_recent_scans,node_history_view,node_ui_kit,node_figma_helper,node_guides,node_guidelines toneBlue
class node_api_entry,node_api_runner,node_model_utils,node_feature_extractor,node_trainer,node_enhanced_trainer,node_full_update toneAmber
class node_accuracy_engine,node_accuracy_pkg,node_accuracy_report toneMint
class node_patient_history toneNeutral
```

## Components

### Frontend client

React/TypeScript app for assessment, X-ray upload, results, dashboard, and history.

- [Entry](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/main.tsx): react entry · Bootstraps the browser app. · `src/main.tsx`
- [App shell](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/App.tsx): react shell · Top-level UI composition and workflow routing. · `src/App.tsx`
- [Assessment](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/AssessmentForm.tsx): clinical form · Collects patient context for risk assessment. · `src/components/AssessmentForm.tsx`
- [Risk calc](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/RiskCalculator.tsx): decision logic · Computes risk output from submitted inputs. · `src/components/RiskCalculator.tsx`
- [X-ray upload](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/XrayUpload.tsx): file intake · Handles knee image upload for analysis. · `src/components/XrayUpload.tsx`
- [AI analysis](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/AIAnalysis.tsx): inference UI · Coordinates model analysis workflow in the UI. · `src/components/AIAnalysis.tsx`
- [AI results](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/AIResults.tsx): results view · Shows classifier output and interpretation. · `src/components/AIResults.tsx`
- [Results](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/Results.tsx): summary view · Presents overall assessment outcome. · `src/components/Results.tsx`
- [Dashboard](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/Dashboard.tsx): overview UI · Main overview for assessments and scans. · `src/components/Dashboard.tsx`
- [Recent scans](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/RecentScans.tsx): history panel · Shows recently processed scans. · `RecentScans.tsx`
- [History](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/History.tsx): record view · Displays prior patient assessments and scans. · `History.tsx`
- [UI kit](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/ui/button.tsx): design system · Reusable buttons, dialogs, forms, tables, tabs, sliders, and other shared controls. · `src/components/ui/button.tsx`
- [Image helper](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/figma/ImageWithFallback.tsx): ui helper · Fallback image rendering helper for resilient image display. · `src/components/figma/ImageWithFallback.tsx`
- [Guides](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/components/ProjectGuides.tsx): content layer · Embedded product guidance and onboarding content. · `src/components/ProjectGuides.tsx`
- [Guidelines](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/src/guidelines/Guidelines.md): documentation · Written guidance for app usage and experience. · `src/guidelines/Guidelines.md`

### Python ML/API

FastAPI surface plus model training, inference, and shared ML utilities.

- [API entry](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/app_fastapi.py): fastapi app · FastAPI application for inference and orchestration. · `app_fastapi.py`
- [API runner](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/run_api.py): server start · Launch script for the Python API surface. · `run_api.py`
- [Model utils](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/model_utils.py): ml utilities · Shared loading, preprocessing, and prediction helpers. · `model_utils.py`
- [Features](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/feature_extractor.py): ml preprocessing · Feature extraction and image processing support. · `feature_extractor.py`
- [Trainer](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/train_model.py): training pipeline · Main training workflow for the classifier. · `train_model.py`
- [Enhanced train](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/enhanced_trainer.py): training pipeline · Extended training path with additional handling. · `enhanced_trainer.py`
- [Full update](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/full_update_knee_classification.py): retraining pipeline · End-to-end classification update script. · `full_update_knee_classification.py`

### Accuracy analysis

Offline evaluation and reporting for model performance.

- [Accuracy engine](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/accuracy_analysis/accuracy_analyzer.py): evaluation · Offline analysis and metrics computation. · `accuracy_analysis/accuracy_analyzer.py`
- [Analysis pkg](https://github.com/dhanush342/knee-osteoporosis-classification/tree/main/accuracy_analysis/accuracy_analysis): evaluation package · Supporting package for accuracy analysis workflows. · `accuracy_analysis/accuracy_analysis`
- [Report](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/accuracy_analysis/accuracy_report.txt): analysis artifact · Generated metrics output and summary report. · `accuracy_analysis/accuracy_report.txt`

### Other components

- [Patient history](https://github.com/dhanush342/knee-osteoporosis-classification/blob/main/patienthistory.csv): data artifact · Persisted history used for prior scans and assessments. · `patienthistory.csv`

## Connections

- Entry → App shell: mounts · Entry point renders the app shell.
- App shell → Assessment: uses · App composes the clinical assessment flow.
- App shell → X-ray upload: uses · App exposes X-ray intake.
- App shell → AI analysis: uses · App includes AI workflow views.
- App shell → Results: uses · App shows the final summary state.
- App shell → Dashboard: uses · App surfaces overview screens.
- App shell → History: uses · App links to historical records.
- Assessment → Risk calc: feeds · Clinical inputs are converted into risk output.
- X-ray upload → AI analysis: feeds · Uploaded images enter the inference flow.
- AI analysis → AI results: outputs · Inference state is rendered as results.
- AI results → Results: summarizes · AI output contributes to the overall result view.
- Dashboard → Recent scans: contains · Dashboard includes recent scan history.
- Dashboard → History: links · Dashboard connects to prior assessments.
- Assessment → UI kit: uses · Feature screens share common UI primitives.
- X-ray upload → UI kit: uses · Upload flow relies on shared controls.
- AI results → UI kit: uses · Results use the shared design system.
- Image helper → UI kit: supports · Fallback image helper plugs into the UI system.
- Guides → Guidelines: documents · Embedded guidance is backed by written guidelines.
- API runner → API entry: starts · Runner launches the FastAPI application.
- API entry → Model utils: invokes · API delegates to shared model helpers.
- API entry → Features: invokes · API uses preprocessing and feature extraction.
- Trainer → Model utils: reuses · Training shares model utilities.
- Enhanced train → Model utils: reuses · Enhanced training shares utilities.
- Full update → Features: uses · Retraining pipeline uses preprocessing support.
- Full update → Model utils: uses · Retraining pipeline uses model helpers.
- Accuracy engine → Analysis pkg: packages · Analyzer is supported by the analysis package.
- Accuracy engine → Report: produces · Offline evaluation writes reports and metrics.
- App shell → API entry: calls · Frontend sends assessment and inference requests to the backend.
- API entry → Patient history: reads/writes · Backend interacts with stored patient history.
