# arun7148/indian-food-rating architecture

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

- Interactive diagram: https://gitdiagram.com/arun7148/indian-food-rating
- Repository: https://github.com/arun7148/indian-food-rating

## Overview

NutriScore IN lets consumers search for or scan packaged foods, then view an A–E rating, nutrient details, ingredient red flags, and (for low grades) alternatives. The main screen coordinates lookup and display; the food service normalizes Open Food Facts data and falls back to local products, while scoring and red-flag rules enrich results. Users can also submit missing products for local scoring and storage. The sampled sources establish these main calls; the product API route’s behavior was not shown, so it is omitted.

Main entry points: [`src/app/page.tsx`](https://github.com/arun7148/indian-food-rating/blob/main/src/app/page.tsx) (Main screen), [`src/lib/foodService.ts`](https://github.com/arun7148/indian-food-rating/blob/main/src/lib/foodService.ts) (Food lookup service), [`src/lib/contributions.ts`](https://github.com/arun7148/indian-food-rating/blob/main/src/lib/contributions.ts) (Contribution handling), [`src/components/SearchBar.tsx`](https://github.com/arun7148/indian-food-rating/blob/main/src/components/SearchBar.tsx) (Search bar)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Consumer experience"]
  node_main_screen["Main screen<br/>[page.tsx]"]
  node_search["Search bar<br/>[SearchBar.tsx]"]
  node_debounce["Query debounce<br/>[useDebounce.ts]"]
  node_scanner["Barcode scanner<br/>[BarcodeScanner.tsx]"]
  node_product_card["Product summary<br/>[ProductCard.tsx]"]
  node_score_badge["Grade badge<br/>[ScoreBadge.tsx]"]
  node_nutrient_view["Nutrient details"]
  node_alternatives["Better alternatives"]
  node_state_views["State views<br/>[StateViews.tsx]"]
end

subgraph group_product_data["Product data"]
  node_food_service["Food lookup service<br/>[foodService.ts]"]
  node_open_food_facts["Open Food Facts"]
  node_mock_data[("Indian mock dataset<br/>[mockData.ts]")]
end

subgraph group_analysis["Nutrition analysis"]
  node_scoring["Nutri-Score engine"]
  node_red_flags["Ingredient red flags<br/>[redFlags.ts]"]
end

subgraph group_contributions["Community contributions"]
  node_contribution_modal["Product submission form"]
  node_contribution_logic["Contribution handling<br/>[contributions.ts]"]
  node_local_storage[("Browser storage")]
  node_contribute_api["Contribution API<br/>[route.ts]"]
end

node_consumer(("Consumer"))

node_consumer -->|"enters query"| node_search
node_consumer -->|"scans barcode"| node_scanner
node_search -->|"debounces input"| node_debounce
node_search -->|"searches products"| node_food_service
node_scanner -->|"reports barcode"| node_main_screen
node_search -->|"selects product"| node_main_screen
node_main_screen -->|"loads products"| node_food_service
node_main_screen -->|"renders result"| node_product_card
node_main_screen -->|"renders nutrients"| node_nutrient_view
node_main_screen -->|"renders alternatives"| node_alternatives
node_main_screen -->|"renders states"| node_state_views
node_product_card -->|"renders grade"| node_score_badge
node_food_service -->|"fetches product data"| node_open_food_facts
node_food_service -->|"falls back to"| node_mock_data
node_food_service -->|"calculates grade"| node_scoring
node_food_service -->|"detects flags"| node_red_flags
node_main_screen -->|"gets alternatives"| node_food_service
node_consumer -->|"submits product"| node_contribution_modal
node_contribution_modal -->|"previews and saves"| node_contribution_logic
node_contribution_logic -->|"scores contribution"| node_scoring
node_contribution_logic -->|"checks ingredients"| node_red_flags
node_contribution_logic -->|"reads and writes"| node_local_storage
node_contribution_logic -->|"posts submission"| node_contribute_api

click node_main_screen "https://github.com/arun7148/indian-food-rating/blob/main/src/app/page.tsx"
click node_search "https://github.com/arun7148/indian-food-rating/blob/main/src/components/SearchBar.tsx"
click node_debounce "https://github.com/arun7148/indian-food-rating/blob/main/src/hooks/useDebounce.ts"
click node_scanner "https://github.com/arun7148/indian-food-rating/blob/main/src/components/BarcodeScanner.tsx"
click node_product_card "https://github.com/arun7148/indian-food-rating/blob/main/src/components/ProductCard.tsx"
click node_score_badge "https://github.com/arun7148/indian-food-rating/blob/main/src/components/ScoreBadge.tsx"
click node_nutrient_view "https://github.com/arun7148/indian-food-rating/blob/main/src/components/NutrientBreakdown.tsx"
click node_alternatives "https://github.com/arun7148/indian-food-rating/blob/main/src/components/AlternativesSection.tsx"
click node_state_views "https://github.com/arun7148/indian-food-rating/blob/main/src/components/StateViews.tsx"
click node_food_service "https://github.com/arun7148/indian-food-rating/blob/main/src/lib/foodService.ts"
click node_mock_data "https://github.com/arun7148/indian-food-rating/blob/main/src/lib/mockData.ts"
click node_scoring "https://github.com/arun7148/indian-food-rating/blob/main/src/lib/calculateNutriScore.ts"
click node_red_flags "https://github.com/arun7148/indian-food-rating/blob/main/src/lib/redFlags.ts"
click node_contribution_modal "https://github.com/arun7148/indian-food-rating/blob/main/src/components/ContributeProductModal.tsx"
click node_contribution_logic "https://github.com/arun7148/indian-food-rating/blob/main/src/lib/contributions.ts"
click node_contribute_api "https://github.com/arun7148/indian-food-rating/blob/main/src/app/api/contribute/route.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_main_screen,node_search,node_debounce,node_scanner,node_product_card,node_score_badge,node_nutrient_view,node_alternatives,node_state_views toneBlue
class node_food_service,node_open_food_facts,node_mock_data toneAmber
class node_scoring,node_red_flags toneMint
class node_contribution_modal,node_contribution_logic,node_local_storage,node_contribute_api toneRose
class node_consumer toneIndigo
```

## Components

### Consumer experience

- [Main screen](https://github.com/arun7148/indian-food-rating/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Search bar](https://github.com/arun7148/indian-food-rating/blob/main/src/components/SearchBar.tsx): `src/components/SearchBar.tsx`
- [Query debounce](https://github.com/arun7148/indian-food-rating/blob/main/src/hooks/useDebounce.ts): `src/hooks/useDebounce.ts`
- [Barcode scanner](https://github.com/arun7148/indian-food-rating/blob/main/src/components/BarcodeScanner.tsx): `src/components/BarcodeScanner.tsx`
- [Product summary](https://github.com/arun7148/indian-food-rating/blob/main/src/components/ProductCard.tsx): `src/components/ProductCard.tsx`
- [Grade badge](https://github.com/arun7148/indian-food-rating/blob/main/src/components/ScoreBadge.tsx): `src/components/ScoreBadge.tsx`
- [Nutrient details](https://github.com/arun7148/indian-food-rating/blob/main/src/components/NutrientBreakdown.tsx): `src/components/NutrientBreakdown.tsx`
- [Better alternatives](https://github.com/arun7148/indian-food-rating/blob/main/src/components/AlternativesSection.tsx): `src/components/AlternativesSection.tsx`
- [State views](https://github.com/arun7148/indian-food-rating/blob/main/src/components/StateViews.tsx): `src/components/StateViews.tsx`

### Product data

- [Food lookup service](https://github.com/arun7148/indian-food-rating/blob/main/src/lib/foodService.ts): `src/lib/foodService.ts`
- **Open Food Facts**
- [Indian mock dataset](https://github.com/arun7148/indian-food-rating/blob/main/src/lib/mockData.ts): `src/lib/mockData.ts`

### Nutrition analysis

- [Nutri-Score engine](https://github.com/arun7148/indian-food-rating/blob/main/src/lib/calculateNutriScore.ts): `src/lib/calculateNutriScore.ts`
- [Ingredient red flags](https://github.com/arun7148/indian-food-rating/blob/main/src/lib/redFlags.ts): `src/lib/redFlags.ts`

### Community contributions

- [Product submission form](https://github.com/arun7148/indian-food-rating/blob/main/src/components/ContributeProductModal.tsx): `src/components/ContributeProductModal.tsx`
- [Contribution handling](https://github.com/arun7148/indian-food-rating/blob/main/src/lib/contributions.ts): `src/lib/contributions.ts`
- **Browser storage**
- [Contribution API](https://github.com/arun7148/indian-food-rating/blob/main/src/app/api/contribute/route.ts): `src/app/api/contribute/route.ts`

### Other components

- **Consumer**

## Connections

- Consumer → Search bar: enters query (evidence: `src/components/SearchBar.tsx`)
- Consumer → Barcode scanner: scans barcode (evidence: `README.md`)
- Search bar → Query debounce: debounces input (evidence: `src/components/SearchBar.tsx`)
- Search bar → Food lookup service: searches products (evidence: `src/components/SearchBar.tsx`)
- Barcode scanner → Main screen: reports barcode (evidence: `src/app/page.tsx`)
- Search bar → Main screen: selects product (evidence: `src/app/page.tsx`)
- Main screen → Food lookup service: loads products (evidence: `src/app/page.tsx`)
- Main screen → Product summary: renders result (evidence: `src/app/page.tsx`)
- Main screen → Nutrient details: renders nutrients (evidence: `src/app/page.tsx`)
- Main screen → Better alternatives: renders alternatives (evidence: `src/app/page.tsx`)
- Main screen → State views: renders states (evidence: `src/app/page.tsx`)
- Product summary → Grade badge: renders grade (evidence: `src/components/ProductCard.tsx`)
- Food lookup service → Open Food Facts: fetches product data (evidence: `README.md`)
- Food lookup service → Indian mock dataset: falls back to (evidence: `src/lib/foodService.ts`)
- Food lookup service → Nutri-Score engine: calculates grade (evidence: `src/lib/foodService.ts`)
- Food lookup service → Ingredient red flags: detects flags (evidence: `src/lib/foodService.ts`)
- Main screen → Food lookup service: gets alternatives (evidence: `src/app/page.tsx`)
- Consumer → Product submission form: submits product (evidence: `src/components/ContributeProductModal.tsx`)
- Product submission form → Contribution handling: previews and saves (evidence: `src/components/ContributeProductModal.tsx`)
- Contribution handling → Nutri-Score engine: scores contribution (evidence: `src/lib/contributions.ts`)
- Contribution handling → Ingredient red flags: checks ingredients (evidence: `src/lib/contributions.ts`)
- Contribution handling → Browser storage: reads and writes (evidence: `src/lib/contributions.ts`)
- Contribution handling → Contribution API: posts submission (evidence: `src/lib/contributions.ts`)
