Adopt agents-settings kit, ship Product/SKU scan models, harden auth, verify OCR accuracy

Backend (app-pfm-ocr-v2/backend):
- Product/SKU scan feature complete: trained DINOv2 index (118 reference
  photos, 16 SKU classes) and YOLO classifier (83.3% top-1 val accuracy),
  fixed scripts/install-pipeline.sh (was missing ultralytics/torch), fully
  browser-verified end-to-end on /scan-pfm. Mobile m-scan-pfm page cancelled
  (Flutter app handles mobile; web UI is desktop-only for pipeline testing).
- Fixed a real data-loss bug: Save Ground Truth (scan-pfm and the DO-flow's
  manual-label) was silently writing into the pfm-web-app container's
  ephemeral filesystem instead of the host, because /sources wasn't
  bind-mounted in docker-compose.yml. Added the mount, recovered an
  orphaned entry.
- accounts.password is now bcrypt-hashed (bcryptjs, idempotent migration
  in db/init.ts) instead of plaintext; login route compares hashes.
- /api/v1/documents/* (list, PUT, upload) now enforces real 401 auth,
  matching what the Flutter client already sends. The "classic" routes
  deliberately stay open — they're dev-only web UI with no login flow and
  won't exist in production.
- OCR accuracy investigated end-to-end: real baseline is 95.10% overall
  (target met; accuracy_report.md was stale at 75.04%, now flagged). Fixed
  one genuine parser.ts bug (SO/DO field duplication in the global fallback
  regex); remaining gaps are OCR/layout-model limitations, not parser bugs.
- Adopted a standalone copy of the fhanyuh/agents-settings e/n workflow
  scoped to backend/ (AGENTS.md Part A/B split, SKILLS.md, plans/, docs/),
  independent of the root copy which now covers Flutter only.
- next-implementation.md deleted; content folded into
  backend/plans/next-enhancements.md for traceability.

Root:
- Adopted fhanyuh/agents-settings kit (AGENTS.md, SKILLS.md, plans/,
  docs/feature-list.md), scoped to the Flutter app only.
- Pending documents queue now persists to Hive (lib/core/storage) instead
  of memory-only, surviving an app kill mid-upload.

Removed backend_backup/ (stale Express/Prisma prototype, superseded by
pfm-web-app) and the completed plans/next-enhancement-plan.md checklist.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Rafhan Mazaya FathurrahmanandClaude Sonnet 5 committed 2026-07-08 11:56:32 +07:00
1 parent 3df9f6ec5d
commit e60ab63154
129 files changed
+8520 -6684

No files matched your search

+25 -29
View File
@@ -3,47 +3,24 @@ import '../../models/document_model.dart';
class LocalStorage {
static const String documentBoxName = 'documents_box';
static const String pendingDocumentsBoxName = 'pending_documents_box';
Future<void> init() async {
await Hive.initFlutter();
// Note: In a real flutter run with build_runner, you would register adapters here
// Hive.registerAdapter(DocumentModelAdapter());
// Hive.registerAdapter(DocumentItemAdapter());
await Hive.openBox<Map>(documentBoxName); // Using Map directly for scaffold without build_runner generated files
await Hive.openBox<Map>(pendingDocumentsBoxName);
}
Box get documentBox => Hive.box<Map>(documentBoxName);
Box get pendingDocumentsBox => Hive.box<Map>(pendingDocumentsBoxName);
Future<void> saveDocument(DocumentModel doc) async {
final box = documentBox;
await box.put(doc.id, {
'id': doc.id,
'nama_driver': doc.namaDriver,
'nama_penerima': doc.namaPenerima,
'created_at': doc.createdAt.toIso8601String(),
'latitude': doc.latitude,
'longitude': doc.longitude,
'header': {
'tanggal': doc.tanggal,
'no_po': doc.noPo,
'no_so': doc.noSo,
'no_do': doc.noDo,
},
'shipment': {
'kepada_yth': doc.kepadaYth,
'order_untuk': doc.orderUntuk,
'alamat': doc.alamat,
'plat_truk': doc.platTruk,
},
'items': doc.items.map((e) => {
'nomor_sku': e.nomorSku,
'nama_barang': e.namaBarang,
'banyak': e.banyak,
'jumlah': e.jumlah,
}).toList(),
});
await documentBox.put(doc.id, doc.toJson());
}
List<DocumentModel> getAllDocuments() {
@@ -59,4 +36,23 @@ class LocalStorage {
docs.sort((a, b) => b.createdAt.compareTo(a.createdAt));
return docs;
}
/// Persists one entry of the in-flight pending-documents queue, keyed by its
/// local id, so an OS-level app kill doesn't lose it (see `PendingDocumentsNotifier`).
Future<void> savePendingDocument(Map<String, dynamic> data) async {
await pendingDocumentsBox.put(data['id'], data);
}
Future<void> removePendingDocument(String id) async {
await pendingDocumentsBox.delete(id);
}
List<Map<String, dynamic>> getAllPendingDocuments() {
final box = pendingDocumentsBox;
return box.keys
.map((key) => box.get(key))
.whereType<Map>()
.map((data) => Map<String, dynamic>.from(data))
.toList();
}
}