Maintenance receipts correctly classified from keywords
Unclear receipts marked as unclassified
OCR extraction called with correct endpoint per type
Attachments stored as documents
Relates to #149
## Scope
Create the receipt type classifier and integrate with existing OCR pipeline.
### ReceiptClassifier
New module in `domain/receipt-classifier.ts`:
- Classify receipt type from email subject + body text first
- Fuel keywords: gas, fuel, gallons, octane, pump, diesel, unleaded, shell, chevron, exxon, bp
- Maintenance keywords: oil change, brake, alignment, tire, rotation, inspection, labor, parts, service, repair, transmission, coolant
- If classification confident (>= 2 keyword matches), use that type
- If unclear from email text, perform general OCR and classify from rawText
- If still unclear, mark as 'unclassified' for user review
- Returns: { type: 'fuel' | 'maintenance' | 'unclassified', confidence: number }
### OCR Integration
- For fuel receipts: Call `OcrService.extractReceipt(userId, {fileBuffer, contentType})`
- For maintenance receipts: Call `OcrService.extractMaintenanceReceipt(userId, {fileBuffer, contentType})`
- For unclassified: Store document as pending, notify user
- Reuse existing OCR pipeline - no changes to OCR service needed
### Document Storage
- Store each attachment as a document via `DocumentsService.createDocument()` + upload
- Link document to created record via `receipt_document_id`
### Files
- `backend/src/features/email-ingestion/domain/receipt-classifier.ts`
## Acceptance Criteria
- [ ] Fuel receipts correctly classified from keywords
- [ ] Maintenance receipts correctly classified from keywords
- [ ] Unclear receipts marked as unclassified
- [ ] OCR extraction called with correct endpoint per type
- [ ] Attachments stored as documents
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Relates to #149
Scope
Create the receipt type classifier and integrate with existing OCR pipeline.
ReceiptClassifier
New module in
domain/receipt-classifier.ts:OCR Integration
OcrService.extractReceipt(userId, {fileBuffer, contentType})OcrService.extractMaintenanceReceipt(userId, {fileBuffer, contentType})Document Storage
DocumentsService.createDocument()+ uploadreceipt_document_idFiles
backend/src/features/email-ingestion/domain/receipt-classifier.tsAcceptance Criteria
Milestone: Receipt Classifier and OCR Integration
Phase: Execution | Agent: Feature Agent | Status: PASS
Completed
receipt-classifier.tswith keyword-basedReceiptClassifierclass{ type: 'fuel' | 'maintenance' | 'unclassified', confidence: number }Integration
EmailIngestionService.processEmail()pipelineFiles Changed
backend/src/features/email-ingestion/domain/receipt-classifier.ts(new)backend/src/features/email-ingestion/domain/email-ingestion.service.ts(modified)backend/src/features/email-ingestion/domain/email-ingestion.types.ts(modified)backend/src/features/email-ingestion/index.ts(modified)Quality
Verdict: PASS | Next: QR post-implementation review