# shramita17-del/label-guard architecture

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

- Interactive diagram: https://gitdiagram.com/shramita17-del/label-guard
- Repository: https://github.com/shramita17-del/label-guard

## Overview

LabelGuard AI is a FastAPI packaging-compliance verifier. The main workflow accepts a package image, detects regions and extracts text, normalizes fields and routes by product category, runs common and category-specific checks, then returns a verdict with an annotated image and rendered report. The repository also contains a physical-versus-digital listing comparison engine and FoSCoS license verification with a local-cache fallback. The README is empty; edges reflect only the shown main workflow and source references, not uninspected runtime wiring.

Main entry points: [`backend/main.py`](https://github.com/shramita17-del/label-guard/blob/main/backend/main.py) (Scan API), [`backend/schemas.py`](https://github.com/shramita17-del/label-guard/blob/main/backend/schemas.py) (Data contracts), [`backend/rule_engine/fssai_verifier.py`](https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/fssai_verifier.py) (FSSAI verification), [`backend/ocr_service/detector.py`](https://github.com/shramita17-del/label-guard/blob/main/backend/ocr_service/detector.py) (Region detector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Image extraction"]
  node_api["Scan API<br/>[main.py]"]
  node_detector["Region detector<br/>[detector.py]"]
  node_ocr["Text extraction<br/>[extractor.py]"]
end

subgraph group_interpret["Field interpretation"]
  node_schemas["Data contracts<br/>[schemas.py]"]
  node_category["Category routing<br/>[main.py]"]
  node_normalizers["Field normalization<br/>[normalizers.py]"]
  node_mark_geometry["Mark analysis<br/>[geometry.py]"]
end

subgraph group_compliance["Compliance checks"]
  node_common_checks["Common checks<br/>[common.py]"]
  node_apparel_checks["Apparel checks<br/>[apparel_textile.py]"]
  node_food_checks["Food checks<br/>[food_beverage.py]"]
  node_license_check["FSSAI verification<br/>[fssai_verifier.py]"]
  node_foscos["FoSCoS lookup<br/>[foscos_scraper.py]"]
  node_license_cache[("License cache<br/>[fssai_cache.json]")]
end

subgraph group_outputs["Report outputs"]
  node_annotator["Image annotation<br/>[annotator.py]"]
  node_pdf["PDF report<br/>[pdf_generator.py]"]
  node_report_template["Report template"]
end

subgraph group_comparison["Listing comparison"]
  node_listing_scraper["Listing scraper<br/>[listing_scraper.py]"]
  node_mismatch["Mismatch comparison<br/>[engine.py]"]
  node_fuzzy_match["Fuzzy matching<br/>[fuzzy_match.py]"]
end

node_user(("Package uploader"))
node_foscos_service(("FoSCoS service"))
node_result["Compliance result"]

node_user -->|"uploads image"| node_api
node_api -->|"detects regions"| node_detector
node_api -->|"extracts text"| node_ocr
node_detector -->|"supplies regions"| node_ocr
node_api -->|"routes scan"| node_category
node_api -->|"normalizes fields"| node_normalizers
node_api -->|"analyzes mark"| node_mark_geometry
node_api -->|"runs checks"| node_common_checks
node_api -->|"runs apparel check"| node_apparel_checks
node_api -->|"runs food check"| node_food_checks
node_api -->|"verifies license"| node_license_check
node_license_check -->|"queries lookup"| node_foscos
node_foscos -->|"queries"| node_foscos_service
node_license_check -->|"reads fallback"| node_license_cache
node_api -->|"annotates image"| node_annotator
node_api -->|"generates report"| node_pdf
node_pdf -->|"renders template"| node_report_template
node_api -->|"returns report"| node_result
node_listing_scraper -.->|"supplies listing"| node_mismatch
node_mismatch -->|"matches text"| node_fuzzy_match
node_normalizers -->|"creates fields"| node_schemas
node_detector -->|"creates regions"| node_schemas
node_ocr -->|"creates OCR results"| node_schemas
node_mark_geometry -->|"creates mark data"| node_schemas
node_common_checks -->|"creates check results"| node_schemas
node_apparel_checks -->|"creates check results"| node_schemas
node_food_checks -->|"creates check results"| node_schemas
node_license_check -->|"creates check result"| node_schemas
node_mismatch -->|"creates mismatch report"| node_schemas

click node_api "https://github.com/shramita17-del/label-guard/blob/main/backend/main.py"
click node_detector "https://github.com/shramita17-del/label-guard/blob/main/backend/ocr_service/detector.py"
click node_ocr "https://github.com/shramita17-del/label-guard/blob/main/backend/ocr_service/extractor.py"
click node_schemas "https://github.com/shramita17-del/label-guard/blob/main/backend/schemas.py"
click node_category "https://github.com/shramita17-del/label-guard/blob/main/backend/main.py"
click node_normalizers "https://github.com/shramita17-del/label-guard/blob/main/backend/parser_service/normalizers.py"
click node_mark_geometry "https://github.com/shramita17-del/label-guard/blob/main/backend/parser_service/geometry.py"
click node_common_checks "https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/validators/common.py"
click node_apparel_checks "https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/validators/apparel_textile.py"
click node_food_checks "https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/validators/food_beverage.py"
click node_license_check "https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/fssai_verifier.py"
click node_foscos "https://github.com/shramita17-del/label-guard/blob/main/backend/scraper_service/foscos_scraper.py"
click node_license_cache "https://github.com/shramita17-del/label-guard/blob/main/data/fssai_cache.json"
click node_listing_scraper "https://github.com/shramita17-del/label-guard/blob/main/backend/scraper_service/listing_scraper.py"
click node_mismatch "https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/engine.py"
click node_fuzzy_match "https://github.com/shramita17-del/label-guard/blob/main/backend/parser_service/fuzzy_match.py"
click node_annotator "https://github.com/shramita17-del/label-guard/blob/main/backend/report_service/annotator.py"
click node_pdf "https://github.com/shramita17-del/label-guard/blob/main/backend/report_service/pdf_generator.py"
click node_report_template "https://github.com/shramita17-del/label-guard/blob/main/reports/report_template.html"

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_api,node_detector,node_ocr toneBlue
class node_schemas,node_category,node_normalizers,node_mark_geometry toneAmber
class node_common_checks,node_apparel_checks,node_food_checks,node_license_check,node_foscos,node_license_cache toneMint
class node_annotator,node_pdf,node_report_template toneRose
class node_listing_scraper,node_mismatch,node_fuzzy_match,node_user,node_foscos_service,node_result toneIndigo
```

## Components

### Image extraction

- [Scan API](https://github.com/shramita17-del/label-guard/blob/main/backend/main.py): `backend/main.py`
- [Region detector](https://github.com/shramita17-del/label-guard/blob/main/backend/ocr_service/detector.py): `backend/ocr_service/detector.py`
- [Text extraction](https://github.com/shramita17-del/label-guard/blob/main/backend/ocr_service/extractor.py): `backend/ocr_service/extractor.py`

### Field interpretation

- [Data contracts](https://github.com/shramita17-del/label-guard/blob/main/backend/schemas.py): `backend/schemas.py`
- [Category routing](https://github.com/shramita17-del/label-guard/blob/main/backend/main.py): `backend/main.py`
- [Field normalization](https://github.com/shramita17-del/label-guard/blob/main/backend/parser_service/normalizers.py): `backend/parser_service/normalizers.py`
- [Mark analysis](https://github.com/shramita17-del/label-guard/blob/main/backend/parser_service/geometry.py): `backend/parser_service/geometry.py`

### Compliance checks

- [Common checks](https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/validators/common.py): `backend/rule_engine/validators/common.py`
- [Apparel checks](https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/validators/apparel_textile.py): `backend/rule_engine/validators/apparel_textile.py`
- [Food checks](https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/validators/food_beverage.py): `backend/rule_engine/validators/food_beverage.py`
- [FSSAI verification](https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/fssai_verifier.py): `backend/rule_engine/fssai_verifier.py`
- [FoSCoS lookup](https://github.com/shramita17-del/label-guard/blob/main/backend/scraper_service/foscos_scraper.py): `backend/scraper_service/foscos_scraper.py`
- [License cache](https://github.com/shramita17-del/label-guard/blob/main/data/fssai_cache.json): `data/fssai_cache.json`

### Report outputs

- [Image annotation](https://github.com/shramita17-del/label-guard/blob/main/backend/report_service/annotator.py): `backend/report_service/annotator.py`
- [PDF report](https://github.com/shramita17-del/label-guard/blob/main/backend/report_service/pdf_generator.py): `backend/report_service/pdf_generator.py`
- [Report template](https://github.com/shramita17-del/label-guard/blob/main/reports/report_template.html): `reports/report_template.html`

### Listing comparison

- [Listing scraper](https://github.com/shramita17-del/label-guard/blob/main/backend/scraper_service/listing_scraper.py): `backend/scraper_service/listing_scraper.py`
- [Mismatch comparison](https://github.com/shramita17-del/label-guard/blob/main/backend/rule_engine/engine.py): `backend/rule_engine/engine.py`
- [Fuzzy matching](https://github.com/shramita17-del/label-guard/blob/main/backend/parser_service/fuzzy_match.py): `backend/parser_service/fuzzy_match.py`

### Other components

- **Package uploader**
- **FoSCoS service**
- **Compliance result**

## Connections

- Package uploader → Scan API: uploads image (evidence: `backend/main.py`)
- Scan API → Region detector: detects regions (evidence: `backend/main.py`)
- Scan API → Text extraction: extracts text (evidence: `backend/main.py`)
- Region detector → Text extraction: supplies regions (evidence: `backend/main.py`)
- Scan API → Category routing: routes scan (evidence: `backend/main.py`)
- Scan API → Field normalization: normalizes fields (evidence: `backend/main.py`)
- Scan API → Mark analysis: analyzes mark (evidence: `backend/main.py`)
- Scan API → Common checks: runs checks (evidence: `backend/main.py`)
- Scan API → Apparel checks: runs apparel check (evidence: `backend/main.py`)
- Scan API → Food checks: runs food check (evidence: `backend/main.py`)
- Scan API → FSSAI verification: verifies license (evidence: `backend/main.py`)
- FSSAI verification → FoSCoS lookup: queries lookup (evidence: `backend/rule_engine/fssai_verifier.py`)
- FoSCoS lookup → FoSCoS service: queries (evidence: `backend/scraper_service/foscos_scraper.py`)
- FSSAI verification → License cache: reads fallback (evidence: `backend/rule_engine/fssai_verifier.py`)
- Scan API → Image annotation: annotates image (evidence: `backend/main.py`)
- Scan API → PDF report: generates report (evidence: `backend/main.py`)
- PDF report → Report template: renders template (evidence: `backend/report_service/pdf_generator.py`)
- Scan API → Compliance result: returns report (evidence: `backend/main.py`)
- Listing scraper → Mismatch comparison: supplies listing
- Mismatch comparison → Fuzzy matching: matches text (evidence: `backend/rule_engine/engine.py`)
- Field normalization → Data contracts: creates fields (evidence: `backend/parser_service/normalizers.py`)
- Region detector → Data contracts: creates regions (evidence: `backend/ocr_service/detector.py`)
- Text extraction → Data contracts: creates OCR results (evidence: `backend/ocr_service/extractor.py`)
- Mark analysis → Data contracts: creates mark data (evidence: `backend/parser_service/geometry.py`)
- Common checks → Data contracts: creates check results (evidence: `backend/main.py`)
- Apparel checks → Data contracts: creates check results (evidence: `backend/main.py`)
- Food checks → Data contracts: creates check results (evidence: `backend/rule_engine/validators/food_beverage.py`)
- FSSAI verification → Data contracts: creates check result (evidence: `backend/rule_engine/fssai_verifier.py`)
- Mismatch comparison → Data contracts: creates mismatch report (evidence: `backend/rule_engine/engine.py`)
