# md-suhail07-code/label-lens architecture

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

- Interactive diagram: https://gitdiagram.com/md-suhail07-code/label-lens
- Repository: https://github.com/md-suhail07-code/label-lens

## Overview

Label-Lens is a personalized food-label safety app. Users create an account and health profile, scan a barcode or enter ingredients, review an ingredient-risk result and alternatives, and revisit scan history. The shown backend barcode path retrieves product data and asks Gemini to clean and analyze ingredients with health context; the README also describes OCR, regulatory grounding, and safer swaps. Those additional capabilities are preserved as documented features, but their implementation is not evident in the excerpts. Frontend-to-API links are therefore marked unverified where source was not shown.

Main entry points: [`Frontend/src/App.jsx`](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/App.jsx) (Application router), [`Backend/controllers/userController.js`](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/controllers/userController.js) (Account operations), [`Backend/controllers/ocrController.js`](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/controllers/ocrController.js) (Scan analysis), [`Backend/routes/userRoute.js`](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/routes/userRoute.js) (Account API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User experience"]
  node_app["Application router<br/>[App.jsx]"]
  node_scanner["Scanner workflow<br/>[Scanner.jsx]"]
  node_manual["Manual entry<br/>[ManualEntry.jsx]"]
  node_results["Analysis results<br/>[ResultsPage.jsx]"]
  node_history["Scan history<br/>[History.jsx]"]
  node_profilepage["Health profile<br/>[HealthProfile.jsx]"]
  node_scanui["Scanner controls<br/>[ScanModeToggle.jsx]"]
  node_overlay["Scanner overlay<br/>[ScannerOverlay.jsx]"]
end

subgraph group_identity["Accounts and profiles"]
  node_authpages["Account screens<br/>[Signup.jsx]"]
  node_verifyui["Email verification<br/>[EmailVerify.jsx]"]
  node_profilectx["Profile state"]
  node_userapi["Account API<br/>[userRoute.js]"]
  node_userctrl["Account operations<br/>[userController.js]"]
  node_auth["Authentication guard<br/>[isAuthenticated.js]"]
  node_verifyemail["Verification mailer<br/>[verifyEmail.js]"]
  node_otp["OTP mailer<br/>[sendOtp.js]"]
end

subgraph group_analysis["Product analysis"]
  node_ocrroute["Scan API<br/>[ocrRoute.js]"]
  node_ocr["Scan analysis<br/>[ocrController.js]"]
  node_ocrfeature["OCR reading<br/>[ocrController.js]"]
  node_server["HTTP server<br/>[server.js]"]
end

subgraph group_data["Persistence"]
  node_historyctx["History state"]
  node_userstore[("User records<br/>[userModel.js]")]
  node_sessions[("Login sessions<br/>[sessionModel.js]")]
  node_scanstore[("Scan records<br/>[historyModel.js]")]
  node_database[("MongoDB connection<br/>[db.js]")]
end

node_consumer(("Consumer"))
node_off["OpenFoodFacts"]
node_gemini["Gemini analysis"]

node_consumer -->|"uses"| node_app
node_app -->|"routes to"| node_scanner
node_app -->|"routes to"| node_manual
node_app -->|"routes to"| node_results
node_app -->|"routes to"| node_history
node_app -->|"routes to"| node_profilepage
node_app -->|"routes to"| node_authpages
node_app -->|"routes to"| node_verifyui
node_scanner -->|"renders"| node_scanui
node_scanner -->|"renders"| node_overlay
node_scanner -.->|"submits scan"| node_ocrroute
node_manual -.->|"submits ingredients"| node_ocrroute
node_ocrroute -.->|"dispatches"| node_ocr
node_ocr -->|"looks up products"| node_off
node_ocr -->|"requests analysis"| node_gemini
node_ocrfeature -.->|"documented OCR capability"| node_ocr
node_ocr -.->|"returns analysis"| node_results
node_profilepage -.->|"updates profile"| node_profilectx
node_history -.->|"reads scans"| node_historyctx
node_authpages -.->|"account requests"| node_userapi
node_verifyui -.->|"verifies email"| node_userapi
node_server -->|"mounts"| node_userapi
node_server -->|"mounts"| node_ocrroute
node_server -->|"connects"| node_database
node_userapi -->|"dispatches"| node_userctrl
node_userapi -->|"guards routes"| node_auth
node_userctrl -->|"reads and writes"| node_userstore
node_userctrl -->|"manages sessions"| node_sessions
node_userctrl -->|"sends verification"| node_verifyemail
node_userctrl -->|"sends OTP"| node_otp
node_auth -->|"loads user"| node_userstore

click node_app "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/App.jsx"
click node_scanner "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/Scanner.jsx"
click node_manual "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/ManualEntry.jsx"
click node_results "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/ResultsPage.jsx"
click node_history "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/History.jsx"
click node_profilepage "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/HealthProfile.jsx"
click node_scanui "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/components/scanner/ScanModeToggle.jsx"
click node_overlay "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/components/scanner/ScannerOverlay.jsx"
click node_authpages "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/Signup.jsx"
click node_verifyui "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/EmailVerify.jsx"
click node_profilectx "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/context/UserProfileContext.jsx"
click node_userapi "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/routes/userRoute.js"
click node_userctrl "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/controllers/userController.js"
click node_auth "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/middleware/isAuthenticated.js"
click node_verifyemail "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/mailer/verifyEmail.js"
click node_otp "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/mailer/sendOtp.js"
click node_ocrroute "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/routes/ocrRoute.js"
click node_ocr "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/controllers/ocrController.js"
click node_ocrfeature "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/controllers/ocrController.js"
click node_historyctx "https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/context/ScanHistoryContext.jsx"
click node_userstore "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/models/userModel.js"
click node_sessions "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/models/sessionModel.js"
click node_scanstore "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/models/historyModel.js"
click node_database "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/database/db.js"
click node_server "https://github.com/md-suhail07-code/label-lens/blob/main/Backend/server.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_app,node_scanner,node_manual,node_results,node_history,node_profilepage,node_scanui,node_overlay toneBlue
class node_authpages,node_verifyui,node_profilectx,node_userapi,node_userctrl,node_auth,node_verifyemail,node_otp toneAmber
class node_ocrroute,node_ocr,node_ocrfeature,node_server toneMint
class node_historyctx,node_userstore,node_sessions,node_scanstore,node_database toneRose
class node_consumer,node_off,node_gemini toneIndigo
```

## Components

### User experience

- [Application router](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/App.jsx): `Frontend/src/App.jsx`
- [Scanner workflow](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/Scanner.jsx): `Frontend/src/pages/Scanner.jsx`
- [Manual entry](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/ManualEntry.jsx): `Frontend/src/pages/ManualEntry.jsx`
- [Analysis results](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/ResultsPage.jsx): `Frontend/src/pages/ResultsPage.jsx`
- [Scan history](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/History.jsx): `Frontend/src/pages/History.jsx`
- [Health profile](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/HealthProfile.jsx): `Frontend/src/pages/HealthProfile.jsx`
- [Scanner controls](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/components/scanner/ScanModeToggle.jsx): `Frontend/src/components/scanner/ScanModeToggle.jsx`
- [Scanner overlay](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/components/scanner/ScannerOverlay.jsx): `Frontend/src/components/scanner/ScannerOverlay.jsx`

### Accounts and profiles

- [Account screens](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/Signup.jsx): `Frontend/src/pages/Signup.jsx`
- [Email verification](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/pages/EmailVerify.jsx): `Frontend/src/pages/EmailVerify.jsx`
- [Profile state](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/context/UserProfileContext.jsx): `Frontend/src/context/UserProfileContext.jsx`
- [Account API](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/routes/userRoute.js): `Backend/routes/userRoute.js`
- [Account operations](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/controllers/userController.js): `Backend/controllers/userController.js`
- [Authentication guard](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/middleware/isAuthenticated.js): `Backend/middleware/isAuthenticated.js`
- [Verification mailer](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/mailer/verifyEmail.js): `Backend/mailer/verifyEmail.js`
- [OTP mailer](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/mailer/sendOtp.js): `Backend/mailer/sendOtp.js`

### Product analysis

- [Scan API](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/routes/ocrRoute.js): `Backend/routes/ocrRoute.js`
- [Scan analysis](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/controllers/ocrController.js): `Backend/controllers/ocrController.js`
- [OCR reading](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/controllers/ocrController.js): `Backend/controllers/ocrController.js`
- [HTTP server](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/server.js): `Backend/server.js`

### Persistence

- [History state](https://github.com/md-suhail07-code/label-lens/blob/main/Frontend/src/context/ScanHistoryContext.jsx): `Frontend/src/context/ScanHistoryContext.jsx`
- [User records](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/models/userModel.js): `Backend/models/userModel.js`
- [Login sessions](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/models/sessionModel.js): `Backend/models/sessionModel.js`
- [Scan records](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/models/historyModel.js): `Backend/models/historyModel.js`
- [MongoDB connection](https://github.com/md-suhail07-code/label-lens/blob/main/Backend/database/db.js): `Backend/database/db.js`

### Other components

- **Consumer**
- **OpenFoodFacts**
- **Gemini analysis**

## Connections

- Consumer → Application router: uses (evidence: `Frontend/src/App.jsx`)
- Application router → Scanner workflow: routes to (evidence: `Frontend/src/App.jsx`)
- Application router → Manual entry: routes to (evidence: `Frontend/src/App.jsx`)
- Application router → Analysis results: routes to (evidence: `Frontend/src/App.jsx`)
- Application router → Scan history: routes to (evidence: `Frontend/src/App.jsx`)
- Application router → Health profile: routes to (evidence: `Frontend/src/App.jsx`)
- Application router → Account screens: routes to (evidence: `Frontend/src/App.jsx`)
- Application router → Email verification: routes to (evidence: `Frontend/src/App.jsx`)
- Scanner workflow → Scanner controls: renders (evidence: `Frontend/src/pages/Scanner.jsx`)
- Scanner workflow → Scanner overlay: renders (evidence: `Frontend/src/pages/Scanner.jsx`)
- Scanner workflow → Scan API: submits scan
- Manual entry → Scan API: submits ingredients
- Scan API → Scan analysis: dispatches (evidence: `Backend/routes/ocrRoute.js`)
- Scan analysis → OpenFoodFacts: looks up products (evidence: `Backend/controllers/ocrController.js`)
- Scan analysis → Gemini analysis: requests analysis (evidence: `Backend/controllers/ocrController.js`)
- OCR reading → Scan analysis: documented OCR capability (evidence: `README.md`)
- Scan analysis → Analysis results: returns analysis
- Health profile → Profile state: updates profile
- Scan history → History state: reads scans
- Account screens → Account API: account requests
- Email verification → Account API: verifies email
- HTTP server → Account API: mounts (evidence: `Backend/server.js`)
- HTTP server → Scan API: mounts (evidence: `Backend/server.js`)
- HTTP server → MongoDB connection: connects (evidence: `Backend/server.js`)
- Account API → Account operations: dispatches (evidence: `Backend/routes/userRoute.js`)
- Account API → Authentication guard: guards routes (evidence: `Backend/routes/userRoute.js`)
- Account operations → User records: reads and writes (evidence: `Backend/controllers/userController.js`)
- Account operations → Login sessions: manages sessions (evidence: `Backend/controllers/userController.js`)
- Account operations → Verification mailer: sends verification (evidence: `Backend/controllers/userController.js`)
- Account operations → OTP mailer: sends OTP (evidence: `Backend/controllers/userController.js`)
- Authentication guard → User records: loads user (evidence: `Backend/middleware/isAuthenticated.js`)
