An AI-assisted compliance validation system for checking packaged commodities against the requirements of the Legal Metrology (Packaged Commodities) Rules, 2011.
The system allows users to upload package images, process them through a backend validation pipeline, evaluate applicable compliance rules, review validation results, and generate inspection reports.
- User authentication using JWT
- Create and manage inspection sessions
- Upload packaged-commodity images
- Image-based validation
- Rule-based compliance evaluation
- Compliance score and overall status
- Field-level validation results
- Processed images with validation annotations
- Inspection result review
- Automated inspection report generation
- PDF report download
- PostgreSQL database
- REST API based frontend-backend integration
User
│
▼
React Frontend
│
│ REST API + JWT
▼
FastAPI Backend
│
├── Authentication
├── Validation API
├── Image API
├── Review API
└── Report API
│
▼
Validation Pipeline
│
├── Image Analysis
├── Rule Engine
└── Processed Images
│
▼
PostgreSQL
│
▼
PDF Report
project-root/
│
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ ├── services/
│ │ ├── context/
│ │ └── ...
│ ├── .env
│ ├── package.json
│ └── README.md
│
├── backend/
│ ├── api/
│ │ └── v1/
│ │ ├── auth.py
│ │ ├── images.py
│ │ ├── validation.py
│ │ ├── review.py
│ │ └── reports.py
│ │
│ ├── core/
│ ├── db/
│ ├── models/
│ ├── services/
│ │ └── validation_pipeline.py
│ ├── ruleEngine/
│ ├── uploads/
│ ├── main.py
│ ├── requirements.txt
│ └── README.md
│
└── README.md
The user logs into the application through the frontend.
Login
│
▼
POST /api/auth/login
│
▼
JWT Access Token
│
▼
GET /api/auth/me
│
▼
Authenticated User
The JWT token is automatically attached to protected API requests.
When a new inspection is started, the frontend creates a validation session.
POST /api/validation/The backend creates a validation record with an initial status of PENDING.
The returned validation_id identifies the inspection throughout the workflow.
The selected package image is uploaded using:
POST /api/validation/{validation_id}/imagesSupported image formats:
- JPEG
- PNG
- WebP
The frontend starts the validation pipeline using:
POST /api/validation/{validation_id}/processThe pipeline produces validation results, compliance status, validation score, processed images, and rule-level explanations.
The frontend displays:
- Overall validation status
- Compliance score
- Product information
- Package information
- Individual validation results
- Applicable rules
- Original images
- Processed images
An inspection report can be generated using:
POST /api/validation/{validation_id}/reportThe generated report can be retrieved using:
GET /api/validation/{validation_id}/report| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/login |
Authenticate user |
GET |
/api/auth/me |
Get current authenticated user |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/validation/ |
Create validation |
GET |
/api/validation/ |
List validations |
GET |
/api/validation/{id} |
Get validation |
PUT |
/api/validation/{id} |
Update validation |
DELETE |
/api/validation/{id} |
Delete validation |
POST |
/api/validation/{id}/process |
Run validation pipeline |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/validation/{id}/images |
Upload image |
GET |
/api/validation/{id}/images |
List images |
GET |
/api/validation/{id}/images/{image_id} |
Get image |
PUT |
/api/validation/{id}/images/{image_id} |
Update image |
DELETE |
/api/validation/{id}/images/{image_id} |
Delete image |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/validation/{id}/report-data |
Get report data |
POST |
/api/validation/{id}/report |
Generate report |
GET |
/api/validation/{id}/report |
Download PDF report |
The review API allows validation results to be reviewed and decisions/comments to be submitted for individual validation results.
- React
- Vite
- Tailwind CSS
- Axios
- React Router
- Lucide React
- Python
- FastAPI
- SQLAlchemy
- PostgreSQL
- JWT Authentication
- OpenCV
- Image analysis
- Rule-based compliance engine
- Legal Metrology compliance rules
- Processed image generation
- Node.js
- npm
- Python 3
- PostgreSQL
cd backend
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reloadBackend: http://localhost:8000
FastAPI documentation: http://localhost:8000/docs
cd frontend
npm install
npm run devCreate .env:
VITE_API_BASE_URL=http://localhost:8000
VITE_USE_MOCK_API=falseFrontend: http://localhost:5173
The frontend communicates with the backend through REST APIs using Axios.
Authenticated requests include:
Authorization: Bearer <access_token>
Main frontend services include:
api.jsauthService.jsinspectionService.js
Create Validation
│
▼
Upload Image
│
▼
Start Processing
│
▼
Validation Pipeline
│
├── Image Analysis
├── Rule Evaluation
└── Processed Image Generation
│
▼
Validation Results
│
▼
Inspection Result
│
▼
Report Data
│
▼
Generate PDF
Uploaded images are stored according to their validation session and exposed through /uploads/.
Typical structure:
uploads/
└── <validation_id>/
└── <generated_image_name>.<extension>
Each validation produces rule-level results containing information such as:
- Rule identifier
- Field being validated
- Validation status
- Reason or explanation
- Evidence information
The inspection also produces an overall compliance status and score.
Possible validation states include:
PASSFAILREVIEWPENDING
The report data contains information about:
- Inspection
- Product
- Package
- Images
- Validation results
- Applicable rules
- Inspection status
- Compliance score
The backend generates the final PDF report, which can be downloaded from the frontend.
The application uses authenticated API requests. Protected backend resources verify the authenticated user before allowing access to validation and inspection data.
The frontend stores the JWT access token and automatically attaches it to API requests through an Axios interceptor.
The system is designed to assist with the inspection of packaged commodities by combining image-based analysis, rule-based validation, persistent inspection records, and automated reporting.
The complete workflow is:
Image Upload → Validation → Review → Compliance Report