# nazil-the-professor/hair-analysis-tool architecture

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

- Interactive diagram: https://gitdiagram.com/nazil-the-professor/hair-analysis-tool
- Repository: https://github.com/nazil-the-professor/hair-analysis-tool

## Overview

This is a Flask-based hair-analysis web app. Users open a page and upload an image for either hairline/coverage visualization or scalp-segmentation heatmap analysis; the app returns JSON results and generated imagery. The sampled code shows page routes, YOLO-based overlay processing, and a TensorFlow Lite segmentation path with density calculations. The README also describes batch processing, but the tree and excerpts do not establish an implementation path for it. The excerpt omits some route bodies and model initialization, so uncertain links are not asserted.

Main entry points: [`app.py`](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py) (Flask routes), [`templates/index.html`](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/index.html) (Home page), [`templates/upload_image.html`](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/upload_image.html) (Upload page), [`best.pt`](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/best.pt) (YOLO weights)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_routes["Flask routes<br/>[app.py]"]
  node_home["Home page<br/>[index.html]"]
  node_upload["Upload page<br/>[upload_image.html]"]
end

subgraph group_hairline["Hairline analysis"]
  node_hairline["Hairline detection<br/>[app.py]"]
  node_yolo[("YOLO weights<br/>[best.pt]")]
  node_overlay["Overlay and metrics<br/>[app.py]"]
  node_cvg["Coverage view<br/>[cvg.html]"]
end

subgraph group_heatmap["Scalp heatmaps"]
  node_segment["Hair segmentation<br/>[app.py]"]
  node_tflite[("Segmentation model")]
  node_density["Density calculation<br/>[app.py]"]
  node_heatmaps["Heatmap generation<br/>[app.py]"]
  node_heatview["Heatmap view<br/>[heatmap_image.html]"]
end

node_user(("Image user"))

node_user -->|"uploads image"| node_routes
node_routes -->|"renders"| node_home
node_routes -->|"renders"| node_upload
node_routes -.->|"dispatches"| node_hairline
node_hairline -.->|"uses weights"| node_yolo
node_hairline -->|"generates overlay"| node_overlay
node_routes -.->|"renders"| node_cvg
node_routes -->|"dispatches"| node_segment
node_segment -->|"loads model"| node_tflite
node_routes -->|"requests heatmaps"| node_heatmaps
node_heatmaps -->|"calculates density"| node_density
node_routes -.->|"renders"| node_heatview

click node_routes "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py"
click node_home "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/index.html"
click node_upload "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/upload_image.html"
click node_hairline "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py"
click node_yolo "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/best.pt"
click node_overlay "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py"
click node_cvg "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/cvg.html"
click node_segment "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py"
click node_tflite "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/selfie_multiclass_256x256.tflite"
click node_density "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py"
click node_heatmaps "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py"
click node_heatview "https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/heatmap_image.html"

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_routes,node_home,node_upload,node_user toneBlue
class node_hairline,node_yolo,node_overlay,node_cvg toneAmber
class node_segment,node_tflite,node_density,node_heatmaps,node_heatview toneMint
```

## Components

### Web interface

- [Flask routes](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py): `app.py`
- [Home page](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/index.html): `templates/index.html`
- [Upload page](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/upload_image.html): `templates/upload_image.html`

### Hairline analysis

- [Hairline detection](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py): `app.py`
- [YOLO weights](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/best.pt): `best.pt`
- [Overlay and metrics](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py): `app.py`
- [Coverage view](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/cvg.html): `templates/cvg.html`

### Scalp heatmaps

- [Hair segmentation](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py): `app.py`
- [Segmentation model](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/selfie_multiclass_256x256.tflite): `selfie_multiclass_256x256.tflite`
- [Density calculation](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py): `app.py`
- [Heatmap generation](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/app.py): `app.py`
- [Heatmap view](https://github.com/nazil-the-professor/hair-analysis-tool/blob/main/templates/heatmap_image.html): `templates/heatmap_image.html`

### Other components

- **Image user**

## Connections

- Image user → Flask routes: uploads image (evidence: `app.py`)
- Flask routes → Home page: renders (evidence: `app.py`)
- Flask routes → Upload page: renders (evidence: `app.py`)
- Flask routes → Hairline detection: dispatches (evidence: `app.py`)
- Hairline detection → YOLO weights: uses weights
- Hairline detection → Overlay and metrics: generates overlay (evidence: `app.py`)
- Flask routes → Coverage view: renders
- Flask routes → Hair segmentation: dispatches (evidence: `app.py`)
- Hair segmentation → Segmentation model: loads model (evidence: `app.py`)
- Flask routes → Heatmap generation: requests heatmaps (evidence: `app.py`)
- Heatmap generation → Density calculation: calculates density (evidence: `app.py`)
- Flask routes → Heatmap view: renders
