# segretoo/ingredientfit architecture

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

- Interactive diagram: https://gitdiagram.com/segretoo/ingredientfit
- Repository: https://github.com/segretoo/ingredientfit

## Overview

IngredientFit is an AI-assisted serum curation service: a user describes a skin concern, selects a key ingredient and budget, and receives a transparent, formula-scored TOP 3. The chat route classifies concerns and applies safety and skin-profile adjustments; the recommendation route computes scores and uses AI only to explain them. Separate product discovery, skin diagnosis, accounts, favorites, history, and mobile experiences support the main flow. Evidence is limited to the excerpts, SOURCE INDEX references, and README; unsampled subsystem links are included only where documented.

Main entry points: [`components/chat/ChatWindow.tsx`](https://github.com/segretoo/ingredientfit/blob/main/components/chat/ChatWindow.tsx) (Chat interface), [`app/api/chat/route.ts`](https://github.com/segretoo/ingredientfit/blob/main/app/api/chat/route.ts) (Concern classification), [`app/api/recommend/route.ts`](https://github.com/segretoo/ingredientfit/blob/main/app/api/recommend/route.ts) (TOP 3 endpoint), [`components/Header.tsx`](https://github.com/segretoo/ingredientfit/blob/main/components/Header.tsx) (Shared navigation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experiences"]
  node_web["Web pages<br/>[page.tsx]"]
  node_mobile["Mobile pages<br/>[page.tsx]"]
  node_chatui["Chat interface<br/>[ChatWindow.tsx]"]
  node_header["Shared navigation<br/>[Header.tsx]"]
end

subgraph group_recommendation["Recommendation engine"]
  node_chatapi["Concern classification<br/>[route.ts]"]
  node_gemini_analyzer["Concern analyzer<br/>[analyzer.ts]"]
  node_ingredients["Ingredient categories<br/>[ingredients.ts]"]
  node_safety["Safety adjustment<br/>[safety.ts]"]
  node_recommendapi["TOP 3 endpoint<br/>[route.ts]"]
  node_budgets["Budget parsing<br/>[budgets.ts]"]
  node_scoring["Score calculator<br/>[calculator.ts]"]
  node_reasoning["Result explanations<br/>[reasoning.ts]"]
end

subgraph group_account["Accounts and profile"]
  node_skinrules["Skin preference rules<br/>[skinProfile.ts]"]
  node_skinquiz["Skin diagnosis"]
  node_localstate[("Local state<br/>[useLocalStorage.ts]")]
  node_favorites["Favorites<br/>[favorites.ts]"]
  node_accountactions["Account actions<br/>[favorites.ts]"]
  node_history["Recommendation history"]
  node_auth["Session lookup<br/>[getUser.ts]"]
  node_supabase[("Supabase services<br/>[server.ts]")]
  node_profileactions["Skin profile actions<br/>[skinProfile.ts]"]
end

subgraph group_catalog["Product discovery"]
  node_products[("Product catalog<br/>[products.ts]")]
  node_productbrowse["Product browsing"]
end

node_user(("Visitor"))

node_user -->|"browses"| node_web
node_user -->|"browses"| node_mobile
node_web -.->|"opens chat"| node_chatui
node_mobile -->|"opens chat"| node_chatui
node_chatui -->|"POSTs concern"| node_chatapi
node_chatapi -->|"classifies"| node_gemini_analyzer
node_chatapi -->|"gets category"| node_ingredients
node_chatapi -->|"adjusts safely"| node_safety
node_chatapi -->|"applies profile"| node_skinrules
node_chatui -->|"POSTs choices"| node_recommendapi
node_recommendapi -->|"gets ingredient"| node_ingredients
node_recommendapi -->|"validates budget"| node_budgets
node_recommendapi -->|"calculates TOP 3"| node_scoring
node_scoring -->|"scores catalog"| node_products
node_recommendapi -->|"adds explanations"| node_reasoning
node_chatui -->|"saves results"| node_history
node_user -.->|"searches products"| node_productbrowse
node_user -.->|"takes diagnosis"| node_skinquiz
node_chatui -->|"stores chat state"| node_localstate
node_header -->|"receives user"| node_auth
node_auth -->|"reads session"| node_supabase
node_header -.->|"syncs favorites"| node_accountactions
node_header -->|"syncs profile"| node_profileactions
node_header -->|"syncs local data"| node_localstate
node_user -.->|"manages favorites"| node_favorites
node_user -.->|"views history"| node_history
node_user -.->|"manages account"| node_accountactions
node_profileactions -.->|"persists profile"| node_supabase

click node_web "https://github.com/segretoo/ingredientfit/blob/main/app/page.tsx"
click node_mobile "https://github.com/segretoo/ingredientfit/blob/main/app/mobile/page.tsx"
click node_chatui "https://github.com/segretoo/ingredientfit/blob/main/components/chat/ChatWindow.tsx"
click node_chatapi "https://github.com/segretoo/ingredientfit/blob/main/app/api/chat/route.ts"
click node_gemini_analyzer "https://github.com/segretoo/ingredientfit/blob/main/lib/gemini/analyzer.ts"
click node_ingredients "https://github.com/segretoo/ingredientfit/blob/main/lib/ingredients.ts"
click node_safety "https://github.com/segretoo/ingredientfit/blob/main/lib/safety.ts"
click node_skinrules "https://github.com/segretoo/ingredientfit/blob/main/lib/skinProfile.ts"
click node_recommendapi "https://github.com/segretoo/ingredientfit/blob/main/app/api/recommend/route.ts"
click node_budgets "https://github.com/segretoo/ingredientfit/blob/main/lib/budgets.ts"
click node_scoring "https://github.com/segretoo/ingredientfit/blob/main/lib/scoring/calculator.ts"
click node_products "https://github.com/segretoo/ingredientfit/blob/main/lib/products.ts"
click node_reasoning "https://github.com/segretoo/ingredientfit/blob/main/lib/gemini/reasoning.ts"
click node_productbrowse "https://github.com/segretoo/ingredientfit/blob/main/components/ProductsContent.tsx"
click node_skinquiz "https://github.com/segretoo/ingredientfit/blob/main/components/SkinProfileContent.tsx"
click node_localstate "https://github.com/segretoo/ingredientfit/blob/main/lib/useLocalStorage.ts"
click node_favorites "https://github.com/segretoo/ingredientfit/blob/main/lib/favorites.ts"
click node_accountactions "https://github.com/segretoo/ingredientfit/blob/main/app/actions/favorites.ts"
click node_history "https://github.com/segretoo/ingredientfit/blob/main/app/actions/recommendationHistory.ts"
click node_auth "https://github.com/segretoo/ingredientfit/blob/main/lib/auth/getUser.ts"
click node_supabase "https://github.com/segretoo/ingredientfit/blob/main/lib/supabase/server.ts"
click node_header "https://github.com/segretoo/ingredientfit/blob/main/components/Header.tsx"
click node_profileactions "https://github.com/segretoo/ingredientfit/blob/main/app/actions/skinProfile.ts"

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,node_mobile,node_chatui,node_header toneBlue
class node_chatapi,node_gemini_analyzer,node_ingredients,node_safety,node_recommendapi,node_budgets,node_scoring,node_reasoning toneAmber
class node_skinrules,node_skinquiz,node_localstate,node_favorites,node_accountactions,node_history,node_auth,node_supabase,node_profileactions toneMint
class node_products,node_productbrowse toneRose
class node_user toneIndigo
```

## Components

### User experiences

- [Web pages](https://github.com/segretoo/ingredientfit/blob/main/app/page.tsx): `app/page.tsx`
- [Mobile pages](https://github.com/segretoo/ingredientfit/blob/main/app/mobile/page.tsx): `app/mobile/page.tsx`
- [Chat interface](https://github.com/segretoo/ingredientfit/blob/main/components/chat/ChatWindow.tsx): `components/chat/ChatWindow.tsx`
- [Shared navigation](https://github.com/segretoo/ingredientfit/blob/main/components/Header.tsx): `components/Header.tsx`

### Recommendation engine

- [Concern classification](https://github.com/segretoo/ingredientfit/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Concern analyzer](https://github.com/segretoo/ingredientfit/blob/main/lib/gemini/analyzer.ts): `lib/gemini/analyzer.ts`
- [Ingredient categories](https://github.com/segretoo/ingredientfit/blob/main/lib/ingredients.ts): `lib/ingredients.ts`
- [Safety adjustment](https://github.com/segretoo/ingredientfit/blob/main/lib/safety.ts): `lib/safety.ts`
- [TOP 3 endpoint](https://github.com/segretoo/ingredientfit/blob/main/app/api/recommend/route.ts): `app/api/recommend/route.ts`
- [Budget parsing](https://github.com/segretoo/ingredientfit/blob/main/lib/budgets.ts): `lib/budgets.ts`
- [Score calculator](https://github.com/segretoo/ingredientfit/blob/main/lib/scoring/calculator.ts): `lib/scoring/calculator.ts`
- [Result explanations](https://github.com/segretoo/ingredientfit/blob/main/lib/gemini/reasoning.ts): `lib/gemini/reasoning.ts`

### Accounts and profile

- [Skin preference rules](https://github.com/segretoo/ingredientfit/blob/main/lib/skinProfile.ts): `lib/skinProfile.ts`
- [Skin diagnosis](https://github.com/segretoo/ingredientfit/blob/main/components/SkinProfileContent.tsx): `components/SkinProfileContent.tsx`
- [Local state](https://github.com/segretoo/ingredientfit/blob/main/lib/useLocalStorage.ts): `lib/useLocalStorage.ts`
- [Favorites](https://github.com/segretoo/ingredientfit/blob/main/lib/favorites.ts): `lib/favorites.ts`
- [Account actions](https://github.com/segretoo/ingredientfit/blob/main/app/actions/favorites.ts): `app/actions/favorites.ts`
- [Recommendation history](https://github.com/segretoo/ingredientfit/blob/main/app/actions/recommendationHistory.ts): `app/actions/recommendationHistory.ts`
- [Session lookup](https://github.com/segretoo/ingredientfit/blob/main/lib/auth/getUser.ts): `lib/auth/getUser.ts`
- [Supabase services](https://github.com/segretoo/ingredientfit/blob/main/lib/supabase/server.ts): `lib/supabase/server.ts`
- [Skin profile actions](https://github.com/segretoo/ingredientfit/blob/main/app/actions/skinProfile.ts): `app/actions/skinProfile.ts`

### Product discovery

- [Product catalog](https://github.com/segretoo/ingredientfit/blob/main/lib/products.ts): `lib/products.ts`
- [Product browsing](https://github.com/segretoo/ingredientfit/blob/main/components/ProductsContent.tsx): `components/ProductsContent.tsx`

### Other components

- **Visitor**

## Connections

- Visitor → Web pages: browses (evidence: `app/page.tsx`)
- Visitor → Mobile pages: browses (evidence: `app/mobile/page.tsx`)
- Web pages → Chat interface: opens chat
- Mobile pages → Chat interface: opens chat
- Chat interface → Concern classification: POSTs concern
- Concern classification → Concern analyzer: classifies (evidence: `app/api/chat/route.ts`)
- Concern classification → Ingredient categories: gets category (evidence: `app/api/chat/route.ts`)
- Concern classification → Safety adjustment: adjusts safely (evidence: `app/api/chat/route.ts`)
- Concern classification → Skin preference rules: applies profile (evidence: `app/api/chat/route.ts`)
- Chat interface → TOP 3 endpoint: POSTs choices
- TOP 3 endpoint → Ingredient categories: gets ingredient (evidence: `app/api/recommend/route.ts`)
- TOP 3 endpoint → Budget parsing: validates budget (evidence: `app/api/recommend/route.ts`)
- TOP 3 endpoint → Score calculator: calculates TOP 3 (evidence: `app/api/recommend/route.ts`)
- Score calculator → Product catalog: scores catalog
- TOP 3 endpoint → Result explanations: adds explanations (evidence: `app/api/recommend/route.ts`)
- Chat interface → Recommendation history: saves results (evidence: `components/chat/ChatWindow.tsx`)
- Visitor → Product browsing: searches products
- Visitor → Skin diagnosis: takes diagnosis
- Chat interface → Local state: stores chat state (evidence: `components/chat/ChatWindow.tsx`)
- Shared navigation → Session lookup: receives user (evidence: `components/Header.tsx`)
- Session lookup → Supabase services: reads session (evidence: `lib/auth/getUser.ts`)
- Shared navigation → Account actions: syncs favorites (evidence: `components/Header.tsx`)
- Shared navigation → Skin profile actions: syncs profile
- Shared navigation → Local state: syncs local data
- Visitor → Favorites: manages favorites
- Visitor → Recommendation history: views history
- Visitor → Account actions: manages account
- Skin profile actions → Supabase services: persists profile
