# sathvick07/unpack architecture

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

- Interactive diagram: https://gitdiagram.com/sathvick07/unpack
- Repository: https://github.com/sathvick07/unpack

## Overview

UnPack is a packaged-food label evidence and nutrition-tracking application. Users can register and set dietary preferences, scan a label, inspect OCR evidence and safety findings, correct extracted fields for server-side re-evaluation, and record confirmed consumption for daily nutrient totals. The frontend routes these tasks through a typed API client to Django endpoints; the backend provides label analysis, user/data persistence, and nutrition calculations. The README documents the analysis stages, while several backend call details and auth/intake endpoint internals were not sampled, so those links are shown only where supported or marked unverified.

Main entry points: [`backend/api/views.py`](https://github.com/sathvick07/unpack/blob/main/backend/api/views.py) (API endpoints), [`frontend/src/api/client.ts`](https://github.com/sathvick07/unpack/blob/main/frontend/src/api/client.ts) (Typed API client), [`backend/api/label_analyzer/ocr_engine.py`](https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/ocr_engine.py) (OCR extraction), [`frontend/src/App.tsx`](https://github.com/sathvick07/unpack/blob/main/frontend/src/App.tsx) (App routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["App routing<br/>[App.tsx]"]
  node_scan["Scan workflow<br/>[ScanPage.tsx]"]
  node_evidence["Evidence review<br/>[EvidenceLens.tsx]"]
  node_nutrition_ui["Nutrition dashboard<br/>[NutritionPage.tsx]"]
  node_auth_ui["Auth and onboarding<br/>[AuthContext.tsx]"]
  node_api_client["Typed API client<br/>[client.ts]"]
end

subgraph group_api["API and persistence"]
  node_api_views["API endpoints<br/>[views.py]"]
  node_models[("Application records<br/>[models.py]")]
  node_serializers["Data serialization<br/>[serializers.py]"]
end

subgraph group_analysis["Label analysis"]
  node_ocr["OCR extraction<br/>[ocr_engine.py]"]
  node_quality["Image quality audit<br/>[quality.py]"]
  node_validator["Evidence validation<br/>[validator.py]"]
  node_matching["Restriction matching<br/>[matching.py]"]
  node_contradiction["Claim contradictions<br/>[contradiction.py]"]
end

subgraph group_nutrition["Nutrition tracking"]
  node_calculator["Intake calculator<br/>[calculator.py]"]
  node_reference["Nutrient references"]
end

subgraph group_identity["User identity"]
  node_identity_api["Identity endpoints<br/>[views.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_scan
node_app -->|"routes to"| node_nutrition_ui
node_app -->|"provides context"| node_auth_ui
node_scan -->|"requests analysis"| node_api_client
node_api_client -->|"calls endpoints"| node_api_views
node_scan -->|"renders review"| node_evidence
node_evidence -->|"submits corrections"| node_api_client
node_api_views -.->|"dispatches analysis"| node_ocr
node_ocr -->|"uses quality audit"| node_quality
node_ocr -->|"validates extraction"| node_validator
node_ocr -->|"uses restriction matching"| node_matching
node_ocr -->|"checks claims"| node_contradiction
node_api_views -.->|"invokes matching"| node_matching
node_api_views -.->|"reads and writes"| node_models
node_api_views -.->|"serializes data"| node_serializers
node_nutrition_ui -->|"requests intake"| node_api_client
node_api_views -.->|"calculates summaries"| node_calculator
node_calculator -->|"uses limits"| node_reference
node_api_views -.->|"serves identity"| node_identity_api
node_auth_ui -->|"restores session"| node_api_client
node_api_client -->|"calls auth endpoints"| node_identity_api

click node_app "https://github.com/sathvick07/unpack/blob/main/frontend/src/App.tsx"
click node_scan "https://github.com/sathvick07/unpack/blob/main/frontend/src/pages/ScanPage.tsx"
click node_evidence "https://github.com/sathvick07/unpack/blob/main/frontend/src/components/EvidenceLens.tsx"
click node_nutrition_ui "https://github.com/sathvick07/unpack/blob/main/frontend/src/pages/NutritionPage.tsx"
click node_auth_ui "https://github.com/sathvick07/unpack/blob/main/frontend/src/context/AuthContext.tsx"
click node_api_client "https://github.com/sathvick07/unpack/blob/main/frontend/src/api/client.ts"
click node_api_views "https://github.com/sathvick07/unpack/blob/main/backend/api/views.py"
click node_models "https://github.com/sathvick07/unpack/blob/main/backend/api/models.py"
click node_serializers "https://github.com/sathvick07/unpack/blob/main/backend/api/serializers.py"
click node_ocr "https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/ocr_engine.py"
click node_quality "https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/quality.py"
click node_validator "https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/validator.py"
click node_matching "https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/matching.py"
click node_contradiction "https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/contradiction.py"
click node_calculator "https://github.com/sathvick07/unpack/blob/main/backend/api/nutrition/calculator.py"
click node_reference "https://github.com/sathvick07/unpack/blob/main/backend/api/nutrition/reference_limits.py"
click node_identity_api "https://github.com/sathvick07/unpack/blob/main/backend/api/views.py"

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_scan,node_evidence,node_nutrition_ui,node_auth_ui,node_api_client,node_user toneBlue
class node_api_views,node_models,node_serializers toneAmber
class node_ocr,node_quality,node_validator,node_matching,node_contradiction toneMint
class node_calculator,node_reference toneRose
class node_identity_api toneIndigo
```

## Components

### Web application

- [App routing](https://github.com/sathvick07/unpack/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Scan workflow](https://github.com/sathvick07/unpack/blob/main/frontend/src/pages/ScanPage.tsx): `frontend/src/pages/ScanPage.tsx`
- [Evidence review](https://github.com/sathvick07/unpack/blob/main/frontend/src/components/EvidenceLens.tsx): `frontend/src/components/EvidenceLens.tsx`
- [Nutrition dashboard](https://github.com/sathvick07/unpack/blob/main/frontend/src/pages/NutritionPage.tsx): `frontend/src/pages/NutritionPage.tsx`
- [Auth and onboarding](https://github.com/sathvick07/unpack/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Typed API client](https://github.com/sathvick07/unpack/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`

### API and persistence

- [API endpoints](https://github.com/sathvick07/unpack/blob/main/backend/api/views.py): `backend/api/views.py`
- [Application records](https://github.com/sathvick07/unpack/blob/main/backend/api/models.py): `backend/api/models.py`
- [Data serialization](https://github.com/sathvick07/unpack/blob/main/backend/api/serializers.py): `backend/api/serializers.py`

### Label analysis

- [OCR extraction](https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/ocr_engine.py): `backend/api/label_analyzer/ocr_engine.py`
- [Image quality audit](https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/quality.py): `backend/api/label_analyzer/quality.py`
- [Evidence validation](https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/validator.py): `backend/api/label_analyzer/validator.py`
- [Restriction matching](https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/matching.py): `backend/api/label_analyzer/matching.py`
- [Claim contradictions](https://github.com/sathvick07/unpack/blob/main/backend/api/label_analyzer/contradiction.py): `backend/api/label_analyzer/contradiction.py`

### Nutrition tracking

- [Intake calculator](https://github.com/sathvick07/unpack/blob/main/backend/api/nutrition/calculator.py): `backend/api/nutrition/calculator.py`
- [Nutrient references](https://github.com/sathvick07/unpack/blob/main/backend/api/nutrition/reference_limits.py): `backend/api/nutrition/reference_limits.py`

### User identity

- [Identity endpoints](https://github.com/sathvick07/unpack/blob/main/backend/api/views.py): `backend/api/views.py`

### Other components

- **User**

## Connections

- User → App routing: uses (evidence: `frontend/src/App.tsx`)
- App routing → Scan workflow: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Nutrition dashboard: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Auth and onboarding: provides context (evidence: `frontend/src/App.tsx`)
- Scan workflow → Typed API client: requests analysis (evidence: `frontend/src/api/client.ts`)
- Typed API client → API endpoints: calls endpoints (evidence: `frontend/src/api/client.ts`)
- Scan workflow → Evidence review: renders review (evidence: `frontend/src/components/EvidenceLens.tsx`)
- Evidence review → Typed API client: submits corrections (evidence: `frontend/src/components/EvidenceLens.tsx`)
- API endpoints → OCR extraction: dispatches analysis (evidence: `backend/api/views.py`)
- OCR extraction → Image quality audit: uses quality audit (evidence: `backend/api/label_analyzer/ocr_engine.py`)
- OCR extraction → Evidence validation: validates extraction (evidence: `backend/api/label_analyzer/ocr_engine.py`)
- OCR extraction → Restriction matching: uses restriction matching (evidence: `backend/api/label_analyzer/ocr_engine.py`)
- OCR extraction → Claim contradictions: checks claims (evidence: `backend/api/label_analyzer/ocr_engine.py`)
- API endpoints → Restriction matching: invokes matching (evidence: `backend/api/views.py`)
- API endpoints → Application records: reads and writes (evidence: `backend/api/views.py`)
- API endpoints → Data serialization: serializes data (evidence: `backend/api/views.py`)
- Nutrition dashboard → Typed API client: requests intake (evidence: `frontend/src/api/client.ts`)
- API endpoints → Intake calculator: calculates summaries (evidence: `backend/api/views.py`)
- Intake calculator → Nutrient references: uses limits (evidence: `backend/api/nutrition/calculator.py`)
- API endpoints → Identity endpoints: serves identity (evidence: `backend/api/views.py`)
- Auth and onboarding → Typed API client: restores session (evidence: `frontend/src/context/AuthContext.tsx`)
- Typed API client → Identity endpoints: calls auth endpoints (evidence: `frontend/src/api/client.ts`)
