# labcoder-ctrl/parakh architecture

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

- Interactive diagram: https://gitdiagram.com/labcoder-ctrl/parakh
- Repository: https://github.com/labcoder-ctrl/parakh

## Overview

PARAKH checks packaged-product labels against India’s Legal Metrology rules. An officer supplies package facts and a label photo with a known-size reference; the pipeline rectifies the image and estimates scale/panel area, reads and measures text, identifies declarations, applies rules, then produces a report. The law layer supplies panel-area calculations, gazette thresholds, and uncertainty-aware verdict logic. README documents a phone app, API, scan store, and supervisor dashboard, but their implementations are not present in the sampled source; links for these documented capabilities are therefore limited.

Main entry points: [`pipeline/run.py`](https://github.com/labcoder-ctrl/parakh/blob/main/pipeline/run.py) (Pipeline Runner), [`api`](https://github.com/labcoder-ctrl/parakh/tree/main/api) (Scan API), [`rules/stage.py`](https://github.com/labcoder-ctrl/parakh/blob/main/rules/stage.py) (Rule Checks), [`lmpc/registry.py`](https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/registry.py) (Law Registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Officer Workflow"]
  node_capture["Phone Capture"]
  node_api["Scan API"]
  node_report["Officer Report<br/>[stage.py]"]
  node_dashboard["Supervisor Dashboard"]
end

subgraph group_processing["Label Analysis"]
  node_pipeline["Pipeline Runner<br/>[run.py]"]
  node_rectify["Image Rectification<br/>[stage.py]"]
  node_ocr["Text OCR<br/>[stage.py]"]
  node_extract["Declaration Extraction<br/>[stage.py]"]
  node_rules["Rule Checks<br/>[stage.py]"]
end

subgraph group_law["Legal Metrology"]
  node_lmpc_area["Panel Area<br/>[panel_area.py]"]
  node_lmpc_table["Table-I Thresholds<br/>[table_i.py]"]
  node_lmpc_decision["Verdict Logic<br/>[decision.py]"]
  node_registry["Law Registry<br/>[registry.py]"]
  node_provisions["Rule Provisions<br/>[provisions.yaml]"]
end

subgraph group_records["Scan Data"]
  node_contract["ScanRecord Contract<br/>[scanrecord.py]"]
  node_store[("Scan Store")]
end

node_officer(("Officer"))

node_officer -->|"enters scan"| node_capture
node_capture -->|"submits capture"| node_api
node_api -->|"starts analysis"| node_pipeline
node_pipeline -->|"calls first"| node_rectify
node_pipeline -->|"calls next"| node_ocr
node_pipeline -->|"calls next"| node_extract
node_pipeline -->|"calls next"| node_rules
node_pipeline -->|"calls last"| node_report
node_rectify -->|"calculates panel"| node_lmpc_area
node_rules -->|"decides verdict"| node_lmpc_decision
node_rules -->|"looks up threshold"| node_lmpc_table
node_rules -->|"gets version"| node_registry
node_lmpc_table -->|"loads table"| node_registry
node_registry -->|"reads rules"| node_provisions
node_api -.->|"stores scans"| node_store
node_dashboard -.->|"views scans"| node_api
node_api -->|"uses record"| node_contract
node_pipeline -->|"validates record"| node_contract
node_officer -->|"reviews results"| node_dashboard

click node_capture "https://github.com/labcoder-ctrl/parakh/tree/main/capture"
click node_api "https://github.com/labcoder-ctrl/parakh/tree/main/api"
click node_pipeline "https://github.com/labcoder-ctrl/parakh/blob/main/pipeline/run.py"
click node_rectify "https://github.com/labcoder-ctrl/parakh/blob/main/rectify/stage.py"
click node_ocr "https://github.com/labcoder-ctrl/parakh/blob/main/ocr/stage.py"
click node_extract "https://github.com/labcoder-ctrl/parakh/blob/main/extract/stage.py"
click node_rules "https://github.com/labcoder-ctrl/parakh/blob/main/rules/stage.py"
click node_report "https://github.com/labcoder-ctrl/parakh/blob/main/report/stage.py"
click node_lmpc_area "https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/panel_area.py"
click node_lmpc_table "https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/table_i.py"
click node_lmpc_decision "https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/decision.py"
click node_registry "https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/registry.py"
click node_provisions "https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/provisions.yaml"
click node_contract "https://github.com/labcoder-ctrl/parakh/blob/main/contracts/scanrecord.py"
click node_store "https://github.com/labcoder-ctrl/parakh/tree/main/store"
click node_dashboard "https://github.com/labcoder-ctrl/parakh/tree/main/dashboard"

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_capture,node_api,node_report,node_dashboard toneBlue
class node_pipeline,node_rectify,node_ocr,node_extract,node_rules toneAmber
class node_lmpc_area,node_lmpc_table,node_lmpc_decision,node_registry,node_provisions toneMint
class node_contract,node_store toneRose
class node_officer toneIndigo
```

## Components

### Officer Workflow

- [Phone Capture](https://github.com/labcoder-ctrl/parakh/tree/main/capture): `capture`
- [Scan API](https://github.com/labcoder-ctrl/parakh/tree/main/api): `api`
- [Officer Report](https://github.com/labcoder-ctrl/parakh/blob/main/report/stage.py): `report/stage.py`
- [Supervisor Dashboard](https://github.com/labcoder-ctrl/parakh/tree/main/dashboard): `dashboard`

### Label Analysis

- [Pipeline Runner](https://github.com/labcoder-ctrl/parakh/blob/main/pipeline/run.py): `pipeline/run.py`
- [Image Rectification](https://github.com/labcoder-ctrl/parakh/blob/main/rectify/stage.py): `rectify/stage.py`
- [Text OCR](https://github.com/labcoder-ctrl/parakh/blob/main/ocr/stage.py): `ocr/stage.py`
- [Declaration Extraction](https://github.com/labcoder-ctrl/parakh/blob/main/extract/stage.py): `extract/stage.py`
- [Rule Checks](https://github.com/labcoder-ctrl/parakh/blob/main/rules/stage.py): `rules/stage.py`

### Legal Metrology

- [Panel Area](https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/panel_area.py): `lmpc/panel_area.py`
- [Table-I Thresholds](https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/table_i.py): `lmpc/table_i.py`
- [Verdict Logic](https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/decision.py): `lmpc/decision.py`
- [Law Registry](https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/registry.py): `lmpc/registry.py`
- [Rule Provisions](https://github.com/labcoder-ctrl/parakh/blob/main/lmpc/provisions.yaml): `lmpc/provisions.yaml`

### Scan Data

- [ScanRecord Contract](https://github.com/labcoder-ctrl/parakh/blob/main/contracts/scanrecord.py): `contracts/scanrecord.py`
- [Scan Store](https://github.com/labcoder-ctrl/parakh/tree/main/store): `store`

### Other components

- **Officer**

## Connections

- Officer → Phone Capture: enters scan
- Phone Capture → Scan API: submits capture
- Scan API → Pipeline Runner: starts analysis
- Pipeline Runner → Image Rectification: calls first
- Pipeline Runner → Text OCR: calls next
- Pipeline Runner → Declaration Extraction: calls next
- Pipeline Runner → Rule Checks: calls next
- Pipeline Runner → Officer Report: calls last
- Image Rectification → Panel Area: calculates panel
- Rule Checks → Verdict Logic: decides verdict
- Rule Checks → Table-I Thresholds: looks up threshold
- Rule Checks → Law Registry: gets version
- Table-I Thresholds → Law Registry: loads table
- Law Registry → Rule Provisions: reads rules
- Scan API → Scan Store: stores scans
- Supervisor Dashboard → Scan API: views scans
- Scan API → ScanRecord Contract: uses record
- Pipeline Runner → ScanRecord Contract: validates record
- Officer → Supervisor Dashboard: reviews results
