How omkar-z7709/legal-metrology-complience works
This is an AI-assisted Legal Metrology inspection system for packaged commodities. An officer uses the Next.js interface to submit package scans and review inspection results; the backend persists scan data and runs OCR, structured declaration extraction, product classification, deterministic compliance checks, and legal-context retrieval. Results can be stored and rendered as inspection reports. The README also documents rules, analytics, product, audit-log, user, and settings screens. Pipeline, storage, RAG, and report wiring is supported by sampled source; unsampled route internals are shown only at the documented module boundary.
Main entry points: pipeline.service.ts Inspection pipeline · api.ts API client · app.ts Fastify API · rag.service.ts Legal context retrieval
Components 32
Officer interface
- Next.js application
frontend/src/app - API client
frontend/src/lib/api.ts - Dashboard and analytics
frontend/src/app/analytics/page.tsx - Inspection screens
frontend/src/app/inspections - Products and rules
frontend/src/app/products - Reports and administration
frontend/src/app/reports
API and access
- Fastify API
backend/src/app.ts - Authentication routes
backend/src/routes/auth.ts - Scan routes
backend/src/routes/scans.ts - Inspection routes
backend/src/routes/inspections.ts - Rules routes
backend/src/routes/rules.ts - RAG routes
backend/src/routes/rag.ts - JWT authentication
backend/src/middleware/auth.ts
Inspection analysis
- Inspection pipeline
backend/src/services/inspection/pipeline.service.ts - Image storage
backend/src/services/storage.service.ts - Image preprocessing
backend/src/services/preprocess.service.ts - OCR service
backend/src/services/ocr/ocr.service.ts - Declaration extraction
backend/src/services/extraction/gemini.extractor.ts - Product classification
backend/src/services/classification/classifier.service.ts - Compliance decision
backend/src/services/engine/decision.engine.ts - Rule validators
backend/src/services/engine/validators
Legal knowledge
- Legal context retrieval
backend/src/services/rag/rag.service.ts - Statutory rules
backend/src/services/rules/rules.service.ts - Text embeddings
backend/src/services/rag/embedding.service.ts
Records and reports
- Data repository
backend/src/db/repo.ts - PostgreSQL and pgvector
backend/src/db/schema.ts - PDF report generation
backend/src/services/reports/report.service.ts - DOCX report generation
backend/src/services/reports/docx-report.service.ts
Other components
- Officer / Inspector
- Google Cloud Vision
- Gemini services
- Supabase Storage
Connections 37
- Officer / Inspector → Next.js application: uses
- Next.js application → API client: requests through
- API client → Fastify API: sends HTTP
- Fastify API → Authentication routes: dispatches
- Fastify API → Scan routes: dispatches
- Fastify API → Inspection routes: dispatches
- Fastify API → Rules routes: dispatches
- Fastify API → RAG routes: dispatches
- Authentication routes → JWT authentication: authenticates
- Scan routes → JWT authentication: authenticates
- Inspection routes → JWT authentication: authenticates
- Scan routes → Inspection pipeline: starts scan analysis
- Inspection pipeline → Data repository: reads and updates scans
- Inspection pipeline → Image storage: downloads images
- Inspection pipeline → Image preprocessing: preprocesses images
- Inspection pipeline → OCR service: extracts text
- Inspection pipeline → Declaration extraction: extracts declarations
- Inspection pipeline → Product classification: classifies product
- Inspection pipeline → Compliance decision: evaluates compliance
- Compliance decision → Rule validators: runs checks
- Compliance decision → Legal context retrieval: retrieves legal context
- Legal context retrieval → Statutory rules: loads rules
- Legal context retrieval → Text embeddings: embeds queries and rules
- Legal context retrieval → PostgreSQL and pgvector: searches vectors
- Statutory rules → PostgreSQL and pgvector: reads rule records
- Data repository → PostgreSQL and pgvector: reads and writes records
- Image storage → Supabase Storage: downloads stored files
- OCR service → Google Cloud Vision: uses when configured
- Declaration extraction → Gemini services: extracts structured data
- Text embeddings → Gemini services: requests embeddings
- PDF report generation → Data repository: loads and saves report data
- PDF report generation → Image storage: stores PDF
- DOCX report generation → Image storage: stores document
- API client → Dashboard and analytics: provides API access
- API client → Inspection screens: provides API access
- API client → Products and rules: provides API access
- API client → Reports and administration: provides API access