# naveen-n-07/legal_lens architecture

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

- Interactive diagram: https://gitdiagram.com/naveen-n-07/legal_lens
- Repository: https://github.com/naveen-n-07/legal_lens

## Overview

METRIX-LM is a legal-metrology inspection system for assessing declarations on packaged goods. Inspectors submit package images through the web client; backend scanning runs image analysis and OCR, then compliance evaluation produces findings for review. Officers can verify inspections and view amendment history, while reporting, analytics, and administration support oversight. The graph includes the documented multilingual OCR and package-detection capabilities. README content was not provided, and several subsystems are represented at their enclosing paths where implementation details were not sampled.

Main entry points: [`frontend/src/services/api.js`](https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/services/api.js) (API services), [`backend/app/ocr/pipeline.py`](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/pipeline.py) (OCR pipeline), [`backend/app/database.py`](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/database.py) (Application database), [`frontend/src/App.jsx`](https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/App.jsx) (Role-based app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Inspection client"]
  node_app["Role-based app<br/>[App.jsx]"]
  node_inspection_ui["Inspection screens"]
  node_review_ui["Review screens"]
  node_client_api["API services<br/>[api.js]"]
end

subgraph group_api["Backend workflows"]
  node_scan_api["Scanner routes<br/>[scanner_routes.py]"]
  node_inspection_api["Inspection routes"]
  node_ocr_api["OCR routes<br/>[ocr_routes.py]"]
  node_detection_api["Detection routes"]
  node_auth["Authentication and roles<br/>[rbac.py]"]
end

subgraph group_analysis["Image and compliance analysis"]
  node_scanner_pipeline["OCR pipeline<br/>[pipeline.py]"]
  node_package_detector["Package detector"]
  node_image_prep["Image preprocessing"]
  node_ocr_engine["OCR engines<br/>[ocr_engine.py]"]
  node_field_extract["Declaration extraction<br/>[data_extractor.py]"]
  node_compliance["Compliance service"]
  node_rule_engine["Statutory rule engine<br/>[engine.py]"]
  node_rule_repo["Rule repository<br/>[repository.py]"]
end

subgraph group_oversight["Review and oversight"]
  node_report_api["Report routes<br/>[report_routes.py]"]
  node_analytics_api["Analytics routes"]
  node_admin_api["Admin routes<br/>[admin_routes.py]"]
  node_database[("Application database<br/>[database.py]")]
end

node_inspector(("Inspector or officer"))

node_inspector -->|"uses"| node_app
node_app -->|"routes"| node_inspection_ui
node_app -->|"routes"| node_review_ui
node_inspection_ui -->|"requests"| node_client_api
node_review_ui -->|"requests"| node_client_api
node_client_api -->|"calls"| node_scan_api
node_client_api -->|"calls"| node_inspection_api
node_client_api -->|"calls"| node_report_api
node_client_api -->|"calls"| node_analytics_api
node_client_api -->|"calls"| node_admin_api
node_scan_api -->|"processes images"| node_scanner_pipeline
node_scanner_pipeline -->|"detects regions"| node_package_detector
node_scanner_pipeline -->|"preprocesses images"| node_image_prep
node_scanner_pipeline -->|"recognizes text"| node_ocr_engine
node_scanner_pipeline -->|"extracts fields"| node_field_extract
node_scan_api -->|"validates declarations"| node_compliance
node_ocr_api -->|"runs OCR"| node_scanner_pipeline
node_detection_api -->|"runs detection"| node_package_detector
node_compliance -->|"evaluates rules"| node_rule_engine
node_compliance -->|"loads rules"| node_rule_repo
node_inspection_api -->|"reads and writes"| node_database
node_report_api -->|"reads records"| node_database
node_analytics_api -->|"reads records"| node_database
node_admin_api -->|"manages records"| node_database
node_inspection_api -->|"checks identity"| node_auth

click node_app "https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/App.jsx"
click node_inspection_ui "https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/pages/InspectionUpload.jsx"
click node_review_ui "https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/pages/OfficerReviewQueue.jsx"
click node_client_api "https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/services/api.js"
click node_scan_api "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/scanner_routes.py"
click node_inspection_api "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/inspection_routes.py"
click node_ocr_api "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/ocr_routes.py"
click node_detection_api "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/detection_routes.py"
click node_report_api "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/report_routes.py"
click node_analytics_api "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/analytics_routes.py"
click node_admin_api "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/admin_routes.py"
click node_scanner_pipeline "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/pipeline.py"
click node_package_detector "https://github.com/naveen-n-07/legal_lens/tree/main/backend/app/package_detection"
click node_image_prep "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/image_preprocessor.py"
click node_ocr_engine "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/ocr_engine.py"
click node_field_extract "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/data_extractor.py"
click node_compliance "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/rules/compliance_service.py"
click node_rule_engine "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/rules/engine.py"
click node_rule_repo "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/rules/repository.py"
click node_auth "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/auth/rbac.py"
click node_database "https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/database.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_inspection_ui,node_review_ui,node_client_api toneBlue
class node_scan_api,node_inspection_api,node_ocr_api,node_detection_api,node_auth toneAmber
class node_scanner_pipeline,node_package_detector,node_image_prep,node_ocr_engine,node_field_extract,node_compliance,node_rule_engine,node_rule_repo toneMint
class node_report_api,node_analytics_api,node_admin_api,node_database toneRose
class node_inspector toneIndigo
```

## Components

### Inspection client

- [Role-based app](https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Inspection screens](https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/pages/InspectionUpload.jsx): `frontend/src/pages/InspectionUpload.jsx`
- [Review screens](https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/pages/OfficerReviewQueue.jsx): `frontend/src/pages/OfficerReviewQueue.jsx`
- [API services](https://github.com/naveen-n-07/legal_lens/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Backend workflows

- [Scanner routes](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/scanner_routes.py): `backend/app/api/scanner_routes.py`
- [Inspection routes](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/inspection_routes.py): `backend/app/api/inspection_routes.py`
- [OCR routes](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/ocr_routes.py): `backend/app/api/ocr_routes.py`
- [Detection routes](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/detection_routes.py): `backend/app/api/detection_routes.py`
- [Authentication and roles](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/auth/rbac.py): `backend/app/auth/rbac.py`

### Image and compliance analysis

- [OCR pipeline](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/pipeline.py): `backend/app/ocr/pipeline.py`
- [Package detector](https://github.com/naveen-n-07/legal_lens/tree/main/backend/app/package_detection): `backend/app/package_detection`
- [Image preprocessing](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/image_preprocessor.py): `backend/app/ocr/image_preprocessor.py`
- [OCR engines](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/ocr_engine.py): `backend/app/ocr/ocr_engine.py`
- [Declaration extraction](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/ocr/data_extractor.py): `backend/app/ocr/data_extractor.py`
- [Compliance service](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/rules/compliance_service.py): `backend/app/rules/compliance_service.py`
- [Statutory rule engine](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/rules/engine.py): `backend/app/rules/engine.py`
- [Rule repository](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/rules/repository.py): `backend/app/rules/repository.py`

### Review and oversight

- [Report routes](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/report_routes.py): `backend/app/api/report_routes.py`
- [Analytics routes](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/analytics_routes.py): `backend/app/api/analytics_routes.py`
- [Admin routes](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/api/admin_routes.py): `backend/app/api/admin_routes.py`
- [Application database](https://github.com/naveen-n-07/legal_lens/blob/main/backend/app/database.py): `backend/app/database.py`

### Other components

- **Inspector or officer**

## Connections

- Inspector or officer → Role-based app: uses
- Role-based app → Inspection screens: routes
- Role-based app → Review screens: routes
- Inspection screens → API services: requests
- Review screens → API services: requests
- API services → Scanner routes: calls
- API services → Inspection routes: calls
- API services → Report routes: calls
- API services → Analytics routes: calls
- API services → Admin routes: calls
- Scanner routes → OCR pipeline: processes images
- OCR pipeline → Package detector: detects regions
- OCR pipeline → Image preprocessing: preprocesses images
- OCR pipeline → OCR engines: recognizes text
- OCR pipeline → Declaration extraction: extracts fields
- Scanner routes → Compliance service: validates declarations
- OCR routes → OCR pipeline: runs OCR
- Detection routes → Package detector: runs detection
- Compliance service → Statutory rule engine: evaluates rules
- Compliance service → Rule repository: loads rules
- Inspection routes → Application database: reads and writes
- Report routes → Application database: reads records
- Analytics routes → Application database: reads records
- Admin routes → Application database: manages records
- Inspection routes → Authentication and roles: checks identity
