A complete full-stack prototype system for gold purity analysis with certificate generation, designed to run on Raspberry Pi 4 with mobile app connectivity.
This system provides:
- ML-powered gold purity analysis using spectroscopic parameters (f0, A0, Q)
- Professional PDF certificate generation with QR codes and digital signatures
- Mobile app interface for field testing and analysis
- Web-based certificate verification with tamper detection
- SQLite database for secure result storage
- FastAPI web framework with automatic API documentation
- SQLite database for storing analysis results and certificates
- scikit-learn machine learning model for purity prediction
- ReportLab PDF generation with professional formatting
- QR code generation for certificate verification links
- SHA256 hashing for certificate integrity verification
- Expo React Native app for cross-platform mobile support
- Axios HTTP client for backend API communication
- Professional UI with input validation and error handling
- Certificate download and sharing functionality
- Real-time analysis with loading states and feedback
- Web-based verification accessible via QR codes
- Certificate integrity checking using SHA256 hashes
- Responsive design for mobile and desktop access
- API endpoints for programmatic verification
```bash
cd backend
python3 -m venv venv source venv/bin/activate
pip install -r requirements.txt
python main.py ```
The server will start on http://0.0.0.0:8000 and display your local IP address.
```bash
npm install -g @expo/cli
cd frontend
npm install
npm start
```
- Input Parameters: Enter f0, A0, Q values in mobile app
- Analysis: Tap "Analyze Sample" to get ML prediction
- Certificate: Download PDF certificate with QR code
- Verification: Scan QR code or visit verification URL
- Integrity Check: System validates certificate hasn't been tampered with
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
API status and version |
| POST | /api/scan |
Analyze gold sample parameters |
| GET | /api/certificate/{id} |
Download PDF certificate |
| GET | /verify/{id} |
Web verification page |
| GET | /api/verify/{id} |
JSON verification data |
The system uses a Random Forest classifier trained on spectroscopic features:
- Input Features: f0 (frequency), A0 (amplitude), Q (quality factor)
- Output Classes: 18K Gold, 22K Gold, 24K Gold, Gold Plated
- Model File:
rf_model.joblib(auto-generates dummy model if not provided)
- Certificate Hashing: SHA256 hashes prevent tampering
- Unique IDs: UUID-based certificate identification
- Integrity Verification: Real-time hash checking
- Secure Storage: SQLite database with proper schema
```bash hostname -I ```
Update the BACKEND_URL in frontend/App.js:
```javascript
const BACKEND_URL = "http://YOUR_PI_IP:8000"
```
```bash sudo ufw allow 8000 ```
``` gold-purity-system/ ├── backend/ │ ├── main.py # FastAPI application │ ├── database.py # SQLite database operations │ ├── ml_model.py # Machine learning model │ ├── certificate_generator.py # PDF generation │ ├── utils.py # Utility functions │ ├── requirements.txt # Python dependencies │ └── README.md # Backend documentation ├── frontend/ │ ├── App.js # React Native main component │ ├── package.json # Node.js dependencies │ ├── app.json # Expo configuration │ └── README.md # Frontend documentation └── README.md # This file ```
- Port already in use: Change port in
main.pyor kill existing process - Module not found: Ensure virtual environment is activated and dependencies installed
- Database errors: Delete
gold_purity.dbto reset database
- Connection refused: Verify backend URL and network connectivity
- Expo errors: Update Expo CLI and clear cache with
expo r -c - Certificate download fails: Check backend is running and accessible
- Can't connect from phone: Ensure devices are on same WiFi network
- Firewall blocking: Configure firewall to allow port 8000
- IP address changes: Update mobile app configuration when Pi IP changes
For production use, consider:
- HTTPS/SSL certificates for secure communication
- Authentication system for user management
- Database backup and recovery procedures
- Load balancing for multiple concurrent users
- Model retraining pipeline for improved accuracy
This is a prototype system for educational and testing purposes. Ensure compliance with local regulations for commercial gold assay operations.