How sarthakwalunj18-tech/legal-metrology- works
This is an officer-facing Legal Metrology compliance system: inspectors submit package images, which are processed into declarations, classified, checked against statutory rules, and persisted as an explainable inspection result. The Next.js portal also exposes inspection history, reports, products, rules, analytics, audit logs, and administration. The README documents the UI-to-API HTTP boundary; sampled source and the SOURCE INDEX support the backend relationships shown. Some frontend page-to-API and unsampled service internals are not shown, so those links are omitted.
Main entry points: pipeline.service.ts Inspection pipeline · scans.ts Scan routes · app.ts Fastify API · inspections.ts Inspection routes
Components 25
Inspector portal
- Inspection screens
frontend/src/app/inspections/new/page.tsx - Live scan capture
frontend/src/components/liveScan/useLiveScan.ts - Portal features
frontend/src/app/analytics/page.tsx - API client
frontend/src/lib/api.ts
Backend API
- Fastify API
backend/src/app.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 - Inspection reports
backend/src/services/reports/report.service.ts
Inspection processing
- Inspection pipeline
backend/src/services/inspection/pipeline.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
Rules and retrieval
- Legal context retrieval
backend/src/services/rag/rag.service.ts - Text embeddings
backend/src/services/rag/embedding.service.ts - Rule management
backend/src/services/rules/rules.service.ts
Data and files
- Domain repository
backend/src/db/repo.ts - PostgreSQL data
backend/src/db/schema.ts - Image storage
backend/src/services/storage.service.ts - Supabase services
backend/src/db/supabase.ts
Other components
- Officer / inspector
Connections 32
- Officer / inspector → Inspection screens: uses
README.md - Officer / inspector → Live scan capture: captures images
README.md - Inspection screens → API client: requests
- Live scan capture → API client: submits scans
- API client → Fastify API: HTTP / JSON
README.md - Portal features → API client: uses
- Fastify API → Scan routes: registers
backend/src/app.ts - Fastify API → Inspection routes: registers
backend/src/app.ts - Fastify API → Rules routes: registers
backend/src/app.ts - Fastify API → RAG routes: registers
backend/src/app.ts - Scan routes → Image preprocessing: calls
backend/src/routes/scans.ts - Scan routes → OCR service: calls
backend/src/routes/scans.ts - Scan routes → Declaration extraction: calls
backend/src/routes/scans.ts - Scan routes → Image storage: stores images
backend/src/routes/scans.ts - Scan routes → Domain repository: persists scan
backend/src/routes/scans.ts - Inspection routes → Inspection pipeline: invokes
backend/src/routes/inspections.ts - Inspection routes → Inspection reports: requests reports
backend/src/routes/inspections.ts - Inspection pipeline → Domain repository: loads and saves
backend/src/services/inspection/pipeline.service.ts - Inspection pipeline → OCR service: calls
backend/src/services/inspection/pipeline.service.ts - Inspection pipeline → Image storage: loads images
backend/src/services/inspection/pipeline.service.ts - Inspection pipeline → Declaration extraction: extracts declarations
backend/src/services/inspection/pipeline.service.ts - Inspection pipeline → Product classification: classifies
backend/src/services/inspection/pipeline.service.ts - Inspection pipeline → Compliance decision: evaluates compliance
backend/src/services/inspection/pipeline.service.ts - Compliance decision → Rule validators: runs checks
backend/src/services/engine/decision.engine.ts - Compliance decision → Legal context retrieval: retrieves context
backend/src/services/engine/decision.engine.ts - Legal context retrieval → Text embeddings: embeds queries
backend/src/services/rag/rag.service.ts - Legal context retrieval → Rule management: loads rules
backend/src/services/rag/rag.service.ts - Rules routes → Rule management: calls
backend/src/routes/rules.ts - RAG routes → Legal context retrieval: calls
backend/src/routes/rag.ts - Domain repository → PostgreSQL data: reads and writes
backend/src/db/repo.ts - Image storage → Supabase services: uses optionally
backend/src/services/storage.service.ts - Inspection routes → Domain repository: reads inspection data
backend/src/routes/inspections.ts