# hassanhaddane/greecheck architecture

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

- Interactive diagram: https://gitdiagram.com/hassanhaddane/greecheck
- Repository: https://github.com/hassanhaddane/greecheck

## Overview

GreeCheck is a privacy-first nutrition web/PWA. A user scans a barcode or searches, the client obtains and normalizes product data, and the domain layer computes an explainable GreeScore for product evaluation. Other documented product flows include preference-based filtering, comparison, cart analysis, replacements, environmental impact, discovery, and locally stored product history. The graph reflects sampled code and source-index references; unsampled subsystem links are omitted where their callers are not shown.

Main entry points: [`packages/domain/src/scoring/gree-score.ts`](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/scoring/gree-score.ts) (GreeScore), [`src/domains/product/repository.ts`](https://github.com/hassanhaddane/greecheck/blob/main/src/domains/product/repository.ts) (Product lookup), [`src/app/[locale]/scan/scan-client.tsx`](https://github.com/hassanhaddane/greecheck/blob/main/src/app/%5Blocale%5D/scan/scan-client.tsx) (Barcode scan), [`src/app/api/product/[barcode]/route.ts`](https://github.com/hassanhaddane/greecheck/blob/main/src/app/api/product/%5Bbarcode%5D/route.ts) (Product API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_scan["Barcode scan<br/>[scan-client.tsx]"]
  node_scanner["Scanner hook"]
  node_search["Product search<br/>[search-client.tsx]"]
  node_criteria_ui["Goal setup"]
  node_discover["Place discovery<br/>[route.ts]"]
end

subgraph group_domain["Nutrition intelligence"]
  node_normalizer["Product normalization<br/>[normalizer.ts]"]
  node_model["Product model<br/>[model.ts]"]
  node_score["GreeScore<br/>[gree-score.ts]"]
  node_battle["Product battle<br/>[engine.ts]"]
  node_compare["Comparison<br/>[engine.ts]"]
  node_cart["Cart analysis<br/>[engine.ts]"]
  node_swap["Replacement engine<br/>[engine.ts]"]
  node_impact["Environmental impact<br/>[engine.ts]"]
  node_coach["GreeCoach<br/>[engine.ts]"]
  node_discover_model["Discovery model<br/>[model.ts]"]
  node_weekly["Weekly progress<br/>[engine.ts]"]
end

subgraph group_data["Product data"]
  node_product["Product lookup<br/>[repository.ts]"]
  node_product_api["Product API<br/>[route.ts]"]
  node_off["Food data sources<br/>[openfoodfacts.ts]"]
  node_places_service["Places provider<br/>[upstream.ts]"]
end

subgraph group_local["Personal and local"]
  node_criteria["Preferences<br/>[store.ts]"]
  node_library["Product history<br/>[history-store.ts]"]
  node_storage[("Local persistence<br/>[repositories.ts]")]
end

node_user(("Consumer"))

node_user -->|"scans barcode"| node_scan
node_user -->|"searches products"| node_search
node_scan -->|"uses scanner"| node_scanner
node_scan -->|"looks up product"| node_product
node_search -->|"requests search"| node_product
node_product -->|"fetches barcode"| node_product_api
node_product_api -->|"gets product data"| node_off
node_product_api -->|"normalizes data"| node_normalizer
node_normalizer -->|"produces model"| node_model
node_score -->|"scores product"| node_model
node_criteria_ui -->|"updates preferences"| node_criteria
node_criteria -->|"persists preferences"| node_storage
node_library -->|"persists history"| node_storage
node_product -->|"reads product cache"| node_storage
node_battle -->|"computes scores"| node_score
node_compare -->|"uses battle engine"| node_battle
node_cart -->|"computes scores"| node_score
node_swap -->|"evaluates alternatives"| node_score
node_compare -->|"includes impact"| node_impact
node_coach -->|"uses product signals"| node_score
node_discover -->|"uses place model"| node_discover_model
node_discover -->|"queries provider"| node_places_service
node_user -->|"sets goals"| node_criteria_ui
node_user -->|"discovers places"| node_discover

click node_scan "https://github.com/hassanhaddane/greecheck/blob/main/src/app/%5Blocale%5D/scan/scan-client.tsx"
click node_scanner "https://github.com/hassanhaddane/greecheck/blob/main/src/hooks/use-barcode-scanner.ts"
click node_search "https://github.com/hassanhaddane/greecheck/blob/main/src/app/%5Blocale%5D/search/search-client.tsx"
click node_product "https://github.com/hassanhaddane/greecheck/blob/main/src/domains/product/repository.ts"
click node_product_api "https://github.com/hassanhaddane/greecheck/blob/main/src/app/api/product/%5Bbarcode%5D/route.ts"
click node_off "https://github.com/hassanhaddane/greecheck/blob/main/src/services/api/openfoodfacts.ts"
click node_normalizer "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/product/normalizer.ts"
click node_model "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/product/model.ts"
click node_score "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/scoring/gree-score.ts"
click node_criteria "https://github.com/hassanhaddane/greecheck/blob/main/src/domains/criteria/store.ts"
click node_criteria_ui "https://github.com/hassanhaddane/greecheck/blob/main/src/app/%5Blocale%5D/criteria/criteria-client.tsx"
click node_battle "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/battle/engine.ts"
click node_compare "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/compare/engine.ts"
click node_cart "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/cart/engine.ts"
click node_swap "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/swap/engine.ts"
click node_impact "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/impact/engine.ts"
click node_coach "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/coach/engine.ts"
click node_discover "https://github.com/hassanhaddane/greecheck/blob/main/src/app/api/places/route.ts"
click node_discover_model "https://github.com/hassanhaddane/greecheck/blob/main/src/domains/discover/model.ts"
click node_library "https://github.com/hassanhaddane/greecheck/blob/main/src/domains/library/history-store.ts"
click node_storage "https://github.com/hassanhaddane/greecheck/blob/main/src/services/storage/repositories.ts"
click node_weekly "https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/weekly/engine.ts"
click node_places_service "https://github.com/hassanhaddane/greecheck/blob/main/src/services/api/upstream.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_scan,node_scanner,node_search,node_criteria_ui,node_discover toneBlue
class node_normalizer,node_model,node_score,node_battle,node_compare,node_cart,node_swap,node_impact,node_coach,node_discover_model,node_weekly toneAmber
class node_product,node_product_api,node_off,node_places_service toneMint
class node_criteria,node_library,node_storage toneRose
class node_user toneIndigo
```

## Components

### User experience

- [Barcode scan](https://github.com/hassanhaddane/greecheck/blob/main/src/app/%5Blocale%5D/scan/scan-client.tsx): `src/app/[locale]/scan/scan-client.tsx`
- [Scanner hook](https://github.com/hassanhaddane/greecheck/blob/main/src/hooks/use-barcode-scanner.ts): `src/hooks/use-barcode-scanner.ts`
- [Product search](https://github.com/hassanhaddane/greecheck/blob/main/src/app/%5Blocale%5D/search/search-client.tsx): `src/app/[locale]/search/search-client.tsx`
- [Goal setup](https://github.com/hassanhaddane/greecheck/blob/main/src/app/%5Blocale%5D/criteria/criteria-client.tsx): `src/app/[locale]/criteria/criteria-client.tsx`
- [Place discovery](https://github.com/hassanhaddane/greecheck/blob/main/src/app/api/places/route.ts): `src/app/api/places/route.ts`

### Nutrition intelligence

- [Product normalization](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/product/normalizer.ts): `packages/domain/src/product/normalizer.ts`
- [Product model](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/product/model.ts): `packages/domain/src/product/model.ts`
- [GreeScore](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/scoring/gree-score.ts): `packages/domain/src/scoring/gree-score.ts`
- [Product battle](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/battle/engine.ts): `packages/domain/src/battle/engine.ts`
- [Comparison](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/compare/engine.ts): `packages/domain/src/compare/engine.ts`
- [Cart analysis](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/cart/engine.ts): `packages/domain/src/cart/engine.ts`
- [Replacement engine](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/swap/engine.ts): `packages/domain/src/swap/engine.ts`
- [Environmental impact](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/impact/engine.ts): `packages/domain/src/impact/engine.ts`
- [GreeCoach](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/coach/engine.ts): `packages/domain/src/coach/engine.ts`
- [Discovery model](https://github.com/hassanhaddane/greecheck/blob/main/src/domains/discover/model.ts): `src/domains/discover/model.ts`
- [Weekly progress](https://github.com/hassanhaddane/greecheck/blob/main/packages/domain/src/weekly/engine.ts): `packages/domain/src/weekly/engine.ts`

### Product data

- [Product lookup](https://github.com/hassanhaddane/greecheck/blob/main/src/domains/product/repository.ts): `src/domains/product/repository.ts`
- [Product API](https://github.com/hassanhaddane/greecheck/blob/main/src/app/api/product/%5Bbarcode%5D/route.ts): `src/app/api/product/[barcode]/route.ts`
- [Food data sources](https://github.com/hassanhaddane/greecheck/blob/main/src/services/api/openfoodfacts.ts): `src/services/api/openfoodfacts.ts`
- [Places provider](https://github.com/hassanhaddane/greecheck/blob/main/src/services/api/upstream.ts): `src/services/api/upstream.ts`

### Personal and local

- [Preferences](https://github.com/hassanhaddane/greecheck/blob/main/src/domains/criteria/store.ts): `src/domains/criteria/store.ts`
- [Product history](https://github.com/hassanhaddane/greecheck/blob/main/src/domains/library/history-store.ts): `src/domains/library/history-store.ts`
- [Local persistence](https://github.com/hassanhaddane/greecheck/blob/main/src/services/storage/repositories.ts): `src/services/storage/repositories.ts`

### Other components

- **Consumer**

## Connections

- Consumer → Barcode scan: scans barcode (evidence: `README.md`)
- Consumer → Product search: searches products (evidence: `README.md`)
- Barcode scan → Scanner hook: uses scanner (evidence: `src/app/[locale]/scan/scan-client.tsx`)
- Barcode scan → Product lookup: looks up product (evidence: `src/app/[locale]/scan/scan-client.tsx`)
- Product search → Product lookup: requests search (evidence: `src/app/[locale]/search/search-client.tsx`)
- Product lookup → Product API: fetches barcode (evidence: `src/domains/product/repository.ts`)
- Product API → Food data sources: gets product data (evidence: `src/app/api/product/[barcode]/route.ts`)
- Product API → Product normalization: normalizes data (evidence: `src/app/api/product/[barcode]/route.ts`)
- Product normalization → Product model: produces model (evidence: `packages/domain/src/product/normalizer.ts`)
- GreeScore → Product model: scores product (evidence: `packages/domain/src/scoring/gree-score.ts`)
- Goal setup → Preferences: updates preferences
- Preferences → Local persistence: persists preferences (evidence: `src/domains/criteria/store.ts`)
- Product history → Local persistence: persists history (evidence: `src/domains/library/history-store.ts`)
- Product lookup → Local persistence: reads product cache (evidence: `src/domains/product/repository.ts`)
- Product battle → GreeScore: computes scores (evidence: `packages/domain/src/battle/engine.ts`)
- Comparison → Product battle: uses battle engine (evidence: `packages/domain/src/compare/engine.ts`)
- Cart analysis → GreeScore: computes scores (evidence: `packages/domain/src/cart/engine.ts`)
- Replacement engine → GreeScore: evaluates alternatives (evidence: `packages/domain/src/swap/engine.ts`)
- Comparison → Environmental impact: includes impact (evidence: `packages/domain/src/compare/engine.ts`)
- GreeCoach → GreeScore: uses product signals (evidence: `packages/domain/src/coach/engine.ts`)
- Place discovery → Discovery model: uses place model (evidence: `src/app/api/places/route.ts`)
- Place discovery → Places provider: queries provider (evidence: `src/app/api/places/route.ts`)
- Consumer → Goal setup: sets goals (evidence: `README.md`)
- Consumer → Place discovery: discovers places (evidence: `README.md`)
