# mohammedaakib/hair_growth_analysis architecture

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

- Interactive diagram: https://gitdiagram.com/mohammedaakib/hair_growth_analysis
- Repository: https://github.com/mohammedaakib/hair_growth_analysis

## Overview

Hair AI Pro is a web application for account access and longitudinal hair-growth analysis. A user registers or logs in, submits an initial image, then submits later images for comparison; the API returns a report and exposes image and history endpoints. The analysis graph detects and crops the head, stores the crop, compares it with the previous image using a vision model, and assembles a report. Face verification, user records, history, and image storage are supporting capabilities. Source excerpts show the main wiring; unsampled template behavior and some storage helper implementations remain unverified.

Main entry points: [`main.py`](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/main.py) (FastAPI app), [`graph/flow.py`](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/flow.py) (Analysis graph), [`utils/s3_storage.py`](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/utils/s3_storage.py) (Image storage), [`auth/routes.py`](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/auth/routes.py) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and UI"]
  node_api["FastAPI app<br/>[main.py]"]
  node_web["Web pages<br/>[dashboard.html]"]
end

subgraph group_identity["Identity"]
  node_accounts["Auth routes<br/>[routes.py]"]
  node_face["Face verification<br/>[face_verify.py]"]
end

subgraph group_analysis["Hair analysis"]
  node_hairgraph["Analysis graph<br/>[flow.py]"]
  node_detection["Head detection<br/>[nodes.py]"]
  node_cropping["Crop and upload<br/>[nodes.py]"]
  node_comparison["Hair comparison<br/>[nodes.py]"]
  node_report["Report generation<br/>[nodes.py]"]
  node_state["Graph state<br/>[state.py]"]
end

subgraph group_storage["Data and storage"]
  node_dbclient["Supabase client<br/>[database.py]"]
  node_s3["Image storage<br/>[s3_storage.py]"]
end

node_user(("User"))
node_supabase[("Supabase service")]
node_objectstore[("Supabase S3 storage")]
node_vision["Groq vision model"]

node_user -->|"submits images"| node_api
node_user -->|"authenticates"| node_accounts
node_api -->|"serves pages"| node_web
node_api -->|"invokes analysis"| node_hairgraph
node_api -->|"mounts routes"| node_accounts
node_api -->|"queries users"| node_dbclient
node_api -->|"saves face"| node_face
node_api -->|"gets latest image"| node_s3
node_api -->|"reads history"| node_supabase
node_accounts -->|"queries users"| node_dbclient
node_accounts -->|"verifies face"| node_face
node_accounts -->|"resolves face URL"| node_s3
node_dbclient -->|"creates client"| node_supabase
node_hairgraph -->|"types state"| node_state
node_hairgraph -->|"dispatches"| node_detection
node_hairgraph -->|"dispatches"| node_cropping
node_hairgraph -->|"dispatches"| node_comparison
node_hairgraph -->|"dispatches"| node_report
node_detection -->|"continues on detection"| node_cropping
node_cropping -->|"then runs"| node_comparison
node_comparison -->|"then generates"| node_report
node_cropping -->|"uploads crop"| node_s3
node_comparison -->|"downloads images"| node_s3
node_comparison -->|"sends image comparison"| node_vision
node_face -->|"stores face data"| node_s3
node_s3 -->|"transfers objects"| node_objectstore

click node_api "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/main.py"
click node_web "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/templates/dashboard.html"
click node_accounts "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/auth/routes.py"
click node_face "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/auth/face_verify.py"
click node_hairgraph "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/flow.py"
click node_detection "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/nodes.py"
click node_cropping "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/nodes.py"
click node_comparison "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/nodes.py"
click node_report "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/nodes.py"
click node_state "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/state.py"
click node_dbclient "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/auth/database.py"
click node_s3 "https://github.com/mohammedaakib/hair_growth_analysis/blob/main/utils/s3_storage.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_api,node_web,node_user toneBlue
class node_accounts,node_face,node_supabase,node_objectstore toneAmber
class node_hairgraph,node_detection,node_cropping,node_comparison,node_report,node_state toneMint
class node_dbclient,node_s3 toneRose
class node_vision toneIndigo
```

## Components

### API and UI

- [FastAPI app](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/main.py): `main.py`
- [Web pages](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/templates/dashboard.html): `templates/dashboard.html`

### Identity

- [Auth routes](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/auth/routes.py): `auth/routes.py`
- [Face verification](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/auth/face_verify.py): `auth/face_verify.py`

### Hair analysis

- [Analysis graph](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/flow.py): `graph/flow.py`
- [Head detection](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/nodes.py): `graph/nodes.py`
- [Crop and upload](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/nodes.py): `graph/nodes.py`
- [Hair comparison](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/nodes.py): `graph/nodes.py`
- [Report generation](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/nodes.py): `graph/nodes.py`
- [Graph state](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/graph/state.py): `graph/state.py`

### Data and storage

- [Supabase client](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/auth/database.py): `auth/database.py`
- [Image storage](https://github.com/mohammedaakib/hair_growth_analysis/blob/main/utils/s3_storage.py): `utils/s3_storage.py`

### Other components

- **User**
- **Supabase service**
- **Supabase S3 storage**
- **Groq vision model**

## Connections

- User → FastAPI app: submits images (evidence: `main.py`)
- User → Auth routes: authenticates (evidence: `auth/routes.py`)
- FastAPI app → Web pages: serves pages (evidence: `main.py`)
- FastAPI app → Analysis graph: invokes analysis (evidence: `main.py`)
- FastAPI app → Auth routes: mounts routes (evidence: `main.py`)
- FastAPI app → Supabase client: queries users (evidence: `main.py`)
- FastAPI app → Face verification: saves face (evidence: `main.py`)
- FastAPI app → Image storage: gets latest image (evidence: `main.py`)
- FastAPI app → Supabase service: reads history (evidence: `main.py`)
- Auth routes → Supabase client: queries users (evidence: `auth/routes.py`)
- Auth routes → Face verification: verifies face (evidence: `auth/routes.py`)
- Auth routes → Image storage: resolves face URL (evidence: `auth/routes.py`)
- Supabase client → Supabase service: creates client (evidence: `auth/database.py`)
- Analysis graph → Graph state: types state (evidence: `graph/flow.py`)
- Analysis graph → Head detection: dispatches (evidence: `graph/flow.py`)
- Analysis graph → Crop and upload: dispatches (evidence: `graph/flow.py`)
- Analysis graph → Hair comparison: dispatches (evidence: `graph/flow.py`)
- Analysis graph → Report generation: dispatches (evidence: `graph/flow.py`)
- Head detection → Crop and upload: continues on detection (evidence: `graph/flow.py`)
- Crop and upload → Hair comparison: then runs (evidence: `graph/flow.py`)
- Hair comparison → Report generation: then generates (evidence: `graph/flow.py`)
- Crop and upload → Image storage: uploads crop (evidence: `graph/nodes.py`)
- Hair comparison → Image storage: downloads images (evidence: `graph/nodes.py`)
- Hair comparison → Groq vision model: sends image comparison (evidence: `graph/nodes.py`)
- Face verification → Image storage: stores face data (evidence: `auth/face_verify.py`)
- Image storage → Supabase S3 storage: transfers objects (evidence: `utils/s3_storage.py`)
