As the name implies, an API service to analyze palm fruit photos
|
|
45 minuten geleden | |
|---|---|---|
| .claude | 1 week geleden | |
| models | 4 dagen geleden | |
| src | 45 minuten geleden | |
| test | 4 dagen geleden | |
| .gitignore | 1 week geleden | |
| .prettierrc | 1 week geleden | |
| CLAUDE.md | 1 uur geleden | |
| README.md | 1 week geleden | |
| best.onnx | 1 week geleden | |
| eslint.config.mjs | 1 week geleden | |
| nest-cli.json | 1 week geleden | |
| package-lock.json | 4 dagen geleden | |
| package.json | 4 dagen geleden | |
| tsconfig.build.json | 1 week geleden | |
| tsconfig.json | 4 dagen geleden |
A NestJS backend API that uses an ONNX-based YOLOv26 model to perform real-time ripeness classification of oil palm fresh fruit bunches (FFB). Detection results are mapped against MPOB (Malaysian Palm Oil Board) grading standards, persisted to a local SQLite database, and served via a REST API.
best.onnx) using onnxruntime-node for zero-dependency, high-performance server-side inference.Ripe | Optimal harvest quality |
| Underripe | Harvested too early |
| Unripe | Not yet ready |
| Overripe | Past optimal harvest window |
| Abnormal | ⚠️ Health alert |
| Empty_Bunch | ⚠️ Health alert |Abnormal or Empty_Bunch classes are automatically flagged with is_health_alert: true.src/
├── main.ts # Bootstrap (port 3000, CORS enabled)
├── app.module.ts # Root module
└── palm-oil/
├── palm-oil.controller.ts # REST endpoints
├── palm-oil.service.ts # Orchestration logic & SQLite persistence
├── palm-oil.module.ts # Feature module
├── providers/
│ └── scanner.provider.ts # ONNX inference pipeline (preprocess → infer → postprocess)
├── entities/
│ └── history.entity.ts # TypeORM entity for scan history
├── interfaces/
│ └── palm-analysis.interface.ts # TypeScript types for API response
└── constants/
└── mpob-standards.ts # MPOB class map, grade colors, and health alert list
ScannerProvider)640×640 using sharp, strip alpha, extract raw pixels, and transpose from HWC → CHW layout, normalizing to [0.0, 1.0].[1, 3, 640, 640] float tensor into the ONNX session. Input key: images.[1, N, 6] output tensor (x1, y1, x2, y2, confidence, class_index). Filter by a default confidence threshold of 0.25. Scale normalized bounding box coordinates to the original image pixel dimensions.>=18>=9best.onnx must be placed in the project root directory.npm install
# Development (single run)
npm run start
# Development (watch mode — auto-restarts on file changes)
npm run start:dev
# Production
npm run start:prod
The server starts on http://localhost:3000 by default. Set the PORT environment variable to override.
POST /palm-oil/analyzeAnalyzes an uploaded image for palm oil ripeness.
Request: multipart/form-data
| Field | Type | Description |
|---|---|---|
image |
File |
The palm oil bunch image to analyze |
Response: application/json
{
"status": "success",
"current_threshold": 0.25,
"total_count": 4,
"industrial_summary": {
"Empty_Bunch": 0,
"Underripe": 1,
"Abnormal": 0,
"Ripe": 2,
"Unripe": 0,
"Overripe": 1
},
"detections": [
{
"bunch_id": 1,
"class": "Ripe",
"confidence": 0.9312,
"is_health_alert": false,
"box": [120.5, 88.3, 450.2, 390.1]
}
],
"image_data": "data:image/jpeg;base64,...",
"inference_ms": 42.15,
"processing_ms": 115.30,
"archive_id": "palm_1712345678901_456"
}
GET /palm-oil/historyReturns the last 50 scan records from the SQLite database, ordered by most recent first.
Response: application/json — Array of History entities.
# Unit tests
npm run test
# Unit tests (watch mode)
npm run test:watch
# End-to-end tests
npm run test:e2e
# Test coverage report
npm run test:cov
Scan history is persisted to a local SQLite file (palm_history.db) in the project root, managed by TypeORM with synchronize: true. No external database setup is required.
Each history record stores:
archive_id — Unique scan identifierfilename — Original uploaded file nametotal_count — Number of detectionsindustrial_summary — Per-class count (JSON)detections — Full detection array with bounding boxes (JSON)inference_ms / processing_ms — Performance timingscreated_at — Auto-generated timestamp| File | Purpose |
|---|---|
best.onnx |
YOLOv8 ONNX inference model (must be in project root) |
palm_history.db |
SQLite scan history database (auto-created) |
src/palm-oil/constants/mpob-standards.ts |
MPOB class definitions, colors, and health alert flags |
src/palm-oil/providers/scanner.provider.ts |
Core AI inference pipeline |
src/palm-oil/palm-oil.service.ts |
Business logic, summary generation, persistence |
src/palm-oil/palm-oil.controller.ts |
REST API layer |
| Package | Purpose |
|---|---|
@nestjs/core |
NestJS framework |
onnxruntime-node |
ONNX model inference |
sharp |
High-performance image preprocessing |
typeorm + sqlite3 |
Database ORM and SQLite driver |
class-validator |
DTO validation |
UNLICENSED — Private project.