# rohannimje/cosmolyze architecture

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

- Interactive diagram: https://gitdiagram.com/rohannimje/cosmolyze
- Repository: https://github.com/rohannimje/cosmolyze

## Overview

Cosmolyze is a dermatological analysis and cosmetic-product assessment platform. The principal workflow captures a facial image, obtains a first-stage visual analysis and follow-up questions, then combines the report, answers, and budget into a clinical recommendation. Separate capabilities audit ingredient formulas, resolve product packshots, persist scan history and streaks, and manage saved products. The excerpts show route ownership and persistence interactions; client-side details and several advertised subsystems are documented in the README but their implementation was not sampled.

Main entry points: [`server.js`](https://github.com/rohannimje/cosmolyze/blob/main/server.js) (Express API), [`routes/scan.js`](https://github.com/rohannimje/cosmolyze/blob/main/routes/scan.js) (Scan history), [`routes/shelf.js`](https://github.com/rohannimje/cosmolyze/blob/main/routes/shelf.js) (Digital shelf), [`prompts.js`](https://github.com/rohannimje/cosmolyze/blob/main/prompts.js) (Clinical prompts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_web_client["Capture and UI<br/>[index.html]"]
end

subgraph group_diagnostics["Clinical intelligence"]
  node_face_analysis["Face analysis<br/>[ai.js]"]
  node_clinical_synthesis["Clinical synthesis<br/>[ai.js]"]
  node_formula_audit["Formula audit<br/>[ai.js]"]
  node_ingredient_search["Ingredient search<br/>[ai.js]"]
  node_ai_prompts["Clinical prompts<br/>[prompts.js]"]
  node_ai_providers["AI providers"]
end

subgraph group_catalog["Product intelligence"]
  node_packshot_lookup["Packshot lookup<br/>[scan.js]"]
  node_image_sources["Image sources"]
  node_product_cache[("Packshot cache<br/>[CachedProduct.js]")]
  node_shelf_routes["Digital shelf<br/>[shelf.js]"]
  node_shelf_store[("Saved products<br/>[DigitalShelf.js]")]
end

subgraph group_identity["Identity and records"]
  node_auth_routes["Account routes<br/>[auth.js]"]
  node_auth_middleware["JWT protection<br/>[auth.js]"]
  node_user_store[("User records<br/>[User.js]")]
  node_scan_records["Scan history<br/>[scan.js]"]
  node_scan_store[("Scan records<br/>[ScanResult.js]")]
  node_clinical_profile[("Clinical profiles<br/>[ClinicalProfile.js]")]
end

subgraph group_platform["API platform"]
  node_api["Express API<br/>[server.js]"]
  node_mongo[("MongoDB")]
end

node_patient(("Patient"))

node_patient -->|"uses"| node_web_client
node_web_client -->|"requests"| node_api
node_api -->|"mounts"| node_auth_routes
node_api -->|"mounts"| node_scan_records
node_api -->|"mounts"| node_face_analysis
node_api -->|"mounts"| node_shelf_routes
node_api -->|"connects"| node_mongo
node_auth_routes -->|"reads and creates"| node_user_store
node_scan_records -->|"protects routes"| node_auth_middleware
node_shelf_routes -->|"protects routes"| node_auth_middleware
node_scan_records -->|"saves and queries"| node_scan_store
node_scan_records -->|"updates streak"| node_user_store
node_shelf_routes -->|"reads and writes"| node_shelf_store
node_face_analysis -->|"uses prompts"| node_ai_prompts
node_clinical_synthesis -->|"uses prompts"| node_ai_prompts
node_formula_audit -->|"uses prompts"| node_ai_prompts
node_ingredient_search -->|"uses prompts"| node_ai_prompts
node_face_analysis -->|"calls models"| node_ai_providers
node_clinical_synthesis -->|"calls models"| node_ai_providers
node_formula_audit -->|"calls models"| node_ai_providers
node_ingredient_search -->|"queries library"| node_ai_providers
node_packshot_lookup -->|"reads and caches"| node_product_cache
node_packshot_lookup -->|"searches images"| node_image_sources
node_scan_records -->|"persists records"| node_mongo
node_shelf_routes -->|"persists shelf"| node_mongo
node_clinical_profile -->|"stores profiles"| node_mongo
node_product_cache -->|"stores TTL cache"| node_mongo

click node_web_client "https://github.com/rohannimje/cosmolyze/blob/main/index.html"
click node_api "https://github.com/rohannimje/cosmolyze/blob/main/server.js"
click node_auth_routes "https://github.com/rohannimje/cosmolyze/blob/main/routes/auth.js"
click node_auth_middleware "https://github.com/rohannimje/cosmolyze/blob/main/middleware/auth.js"
click node_user_store "https://github.com/rohannimje/cosmolyze/blob/main/models/User.js"
click node_face_analysis "https://github.com/rohannimje/cosmolyze/blob/main/routes/ai.js"
click node_clinical_synthesis "https://github.com/rohannimje/cosmolyze/blob/main/routes/ai.js"
click node_formula_audit "https://github.com/rohannimje/cosmolyze/blob/main/routes/ai.js"
click node_ingredient_search "https://github.com/rohannimje/cosmolyze/blob/main/routes/ai.js"
click node_ai_prompts "https://github.com/rohannimje/cosmolyze/blob/main/prompts.js"
click node_scan_records "https://github.com/rohannimje/cosmolyze/blob/main/routes/scan.js"
click node_scan_store "https://github.com/rohannimje/cosmolyze/blob/main/models/ScanResult.js"
click node_clinical_profile "https://github.com/rohannimje/cosmolyze/blob/main/models/ClinicalProfile.js"
click node_packshot_lookup "https://github.com/rohannimje/cosmolyze/blob/main/routes/scan.js"
click node_product_cache "https://github.com/rohannimje/cosmolyze/blob/main/models/CachedProduct.js"
click node_shelf_routes "https://github.com/rohannimje/cosmolyze/blob/main/routes/shelf.js"
click node_shelf_store "https://github.com/rohannimje/cosmolyze/blob/main/models/DigitalShelf.js"

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_client toneBlue
class node_face_analysis,node_clinical_synthesis,node_formula_audit,node_ingredient_search,node_ai_prompts,node_ai_providers toneAmber
class node_packshot_lookup,node_image_sources,node_product_cache,node_shelf_routes,node_shelf_store toneMint
class node_auth_routes,node_auth_middleware,node_user_store,node_scan_records,node_scan_store,node_clinical_profile toneRose
class node_api,node_mongo,node_patient toneIndigo
```

## Components

### User experience

- [Capture and UI](https://github.com/rohannimje/cosmolyze/blob/main/index.html): `index.html`

### Clinical intelligence

- [Face analysis](https://github.com/rohannimje/cosmolyze/blob/main/routes/ai.js): `routes/ai.js`
- [Clinical synthesis](https://github.com/rohannimje/cosmolyze/blob/main/routes/ai.js): `routes/ai.js`
- [Formula audit](https://github.com/rohannimje/cosmolyze/blob/main/routes/ai.js): `routes/ai.js`
- [Ingredient search](https://github.com/rohannimje/cosmolyze/blob/main/routes/ai.js): `routes/ai.js`
- [Clinical prompts](https://github.com/rohannimje/cosmolyze/blob/main/prompts.js): `prompts.js`
- **AI providers**

### Product intelligence

- [Packshot lookup](https://github.com/rohannimje/cosmolyze/blob/main/routes/scan.js): `routes/scan.js`
- **Image sources**
- [Packshot cache](https://github.com/rohannimje/cosmolyze/blob/main/models/CachedProduct.js): `models/CachedProduct.js`
- [Digital shelf](https://github.com/rohannimje/cosmolyze/blob/main/routes/shelf.js): `routes/shelf.js`
- [Saved products](https://github.com/rohannimje/cosmolyze/blob/main/models/DigitalShelf.js): `models/DigitalShelf.js`

### Identity and records

- [Account routes](https://github.com/rohannimje/cosmolyze/blob/main/routes/auth.js): `routes/auth.js`
- [JWT protection](https://github.com/rohannimje/cosmolyze/blob/main/middleware/auth.js): `middleware/auth.js`
- [User records](https://github.com/rohannimje/cosmolyze/blob/main/models/User.js): `models/User.js`
- [Scan history](https://github.com/rohannimje/cosmolyze/blob/main/routes/scan.js): `routes/scan.js`
- [Scan records](https://github.com/rohannimje/cosmolyze/blob/main/models/ScanResult.js): `models/ScanResult.js`
- [Clinical profiles](https://github.com/rohannimje/cosmolyze/blob/main/models/ClinicalProfile.js): `models/ClinicalProfile.js`

### API platform

- [Express API](https://github.com/rohannimje/cosmolyze/blob/main/server.js): `server.js`
- **MongoDB**

### Other components

- **Patient**

## Connections

- Patient → Capture and UI: uses (evidence: `README.md`)
- Capture and UI → Express API: requests (evidence: `README.md`)
- Express API → Account routes: mounts (evidence: `server.js`)
- Express API → Scan history: mounts (evidence: `server.js`)
- Express API → Face analysis: mounts (evidence: `server.js`)
- Express API → Digital shelf: mounts (evidence: `server.js`)
- Express API → MongoDB: connects (evidence: `server.js`)
- Account routes → User records: reads and creates (evidence: `routes/auth.js`)
- Scan history → JWT protection: protects routes (evidence: `routes/scan.js`)
- Digital shelf → JWT protection: protects routes (evidence: `routes/shelf.js`)
- Scan history → Scan records: saves and queries (evidence: `routes/scan.js`)
- Scan history → User records: updates streak (evidence: `routes/scan.js`)
- Digital shelf → Saved products: reads and writes (evidence: `routes/shelf.js`)
- Face analysis → Clinical prompts: uses prompts (evidence: `routes/ai.js`)
- Clinical synthesis → Clinical prompts: uses prompts (evidence: `routes/ai.js`)
- Formula audit → Clinical prompts: uses prompts (evidence: `routes/ai.js`)
- Ingredient search → Clinical prompts: uses prompts (evidence: `routes/ai.js`)
- Face analysis → AI providers: calls models (evidence: `README.md`)
- Clinical synthesis → AI providers: calls models (evidence: `README.md`)
- Formula audit → AI providers: calls models (evidence: `README.md`)
- Ingredient search → AI providers: queries library (evidence: `routes/ai.js`)
- Packshot lookup → Packshot cache: reads and caches (evidence: `routes/scan.js`)
- Packshot lookup → Image sources: searches images (evidence: `routes/scan.js`)
- Scan history → MongoDB: persists records (evidence: `README.md`)
- Digital shelf → MongoDB: persists shelf (evidence: `README.md`)
- Clinical profiles → MongoDB: stores profiles (evidence: `README.md`)
- Packshot cache → MongoDB: stores TTL cache (evidence: `README.md`)
