How dhanush342/knee-osteoporosis-classification works
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: App.tsx App shell · app_fastapi.py API entry · button.tsx UI kit · model_utils.py Model utils
Components 26
Frontend client
React/TypeScript app for assessment, X-ray upload, results, dashboard, and history.
- Entry · Bootstraps the browser app.
src/main.tsx - App shell · Top-level UI composition and workflow routing.
src/App.tsx - Assessment · Collects patient context for risk assessment.
src/components/AssessmentForm.tsx - Risk calc · Computes risk output from submitted inputs.
src/components/RiskCalculator.tsx - X-ray upload · Handles knee image upload for analysis.
src/components/XrayUpload.tsx - AI analysis · Coordinates model analysis workflow in the UI.
src/components/AIAnalysis.tsx - AI results · Shows classifier output and interpretation.
src/components/AIResults.tsx - Results · Presents overall assessment outcome.
src/components/Results.tsx - Dashboard · Main overview for assessments and scans.
src/components/Dashboard.tsx - Recent scans · Shows recently processed scans.
RecentScans.tsx - History · Displays prior patient assessments and scans.
History.tsx - UI kit · Reusable buttons, dialogs, forms, tables, tabs, sliders, and other shared controls.
src/components/ui/button.tsx - Image helper · Fallback image rendering helper for resilient image display.
src/components/figma/ImageWithFallback.tsx - Guides · Embedded product guidance and onboarding content.
src/components/ProjectGuides.tsx - Guidelines · 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 · FastAPI application for inference and orchestration.
app_fastapi.py - API runner · Launch script for the Python API surface.
run_api.py - Model utils · Shared loading, preprocessing, and prediction helpers.
model_utils.py - Features · Feature extraction and image processing support.
feature_extractor.py - Trainer · Main training workflow for the classifier.
train_model.py - Enhanced train · Extended training path with additional handling.
enhanced_trainer.py - Full update · End-to-end classification update script.
full_update_knee_classification.py
Accuracy analysis
Offline evaluation and reporting for model performance.
- Accuracy engine · Offline analysis and metrics computation.
accuracy_analysis/accuracy_analyzer.py - Analysis pkg · Supporting package for accuracy analysis workflows.
accuracy_analysis/accuracy_analysis - Report · Generated metrics output and summary report.
accuracy_analysis/accuracy_report.txt
Other components
- Patient history · Persisted history used for prior scans and assessments.
patienthistory.csv
Connections 29
- 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.