Files
erp-nutzfahrzeuge/.a0/worklog.md
T

2.4 KiB

Worklog

2026-07-17 - T03: OCR-Erfassung via OpenRouter Vision + OCR UI

Files Created (Backend)

  • backend/app/models/ocr_result.py - OCRResult model (UUID, vehicle_id FK, file_path, status enum, raw_text, structured_data JSONB, confidence_score, error_message, timestamps)
  • backend/app/schemas/ocr.py - OCRUploadResponse, OCRResultResponse, OCRResultListResponse, OCRApplyResponse, OCRStructuredData
  • backend/app/utils/openrouter.py - OpenRouter API client for Qwen2.5-VL vision model (base64 encoding, prompt engineering, JSON parsing, confidence extraction)
  • backend/app/services/ocr_service.py - upload_file, get_result, list_results, apply_to_vehicle, process_ocr (async), MIME/size validation, confidence threshold logic
  • backend/app/tasks/ocr_processing.py - Async background task with independent DB session
  • backend/app/tasks/__init__.py - Tasks package init
  • backend/app/routers/ocr.py - POST /upload, GET /results/:id, GET /results, POST /results/:id/apply
  • backend/tests/test_ocr.py - 33 tests (service unit tests, router integration tests, OpenRouter client tests)

Files Created (Frontend)

  • frontend/lib/ocr.ts - OCR API client (uploadOCRScan, getOCRResult, listOCRResults, applyOCRToVehicle)
  • frontend/components/ocr/OCRUpload.tsx - Drag-and-drop file upload component
  • frontend/components/ocr/OCRResults.tsx - Results list with pagination and status badges
  • frontend/components/ocr/OCRDetail.tsx - Side-by-side original scan + extracted data with apply button
  • frontend/app/[locale]/ocr/page.tsx - OCR page combining upload, results, and detail
  • frontend/tests/ocr.test.tsx - 18 frontend tests

Files Modified

  • backend/app/config.py - Added OPENROUTER_API_KEY, OPENROUTER_BASE_URL, OPENROUTER_OCR_MODEL, MAX_FILE_SIZE_MB
  • backend/app/main.py - Registered OCR router under /api/v1/ocr

Test Results

  • Backend: 33/33 OCR tests passed, 85% coverage (target: 80%)
  • Backend: 229/229 full suite passed
  • Frontend: 18/18 OCR tests passed

Key Decisions

  • Used FastAPI BackgroundTasks for async processing (Redis Queue noted for production)
  • Confidence threshold: 0.7 (below → manual_review, above → completed)
  • structured_data JSONB contains: brand, model, vin, first_registration, mileage, power_kw, fuel_type
  • OpenRouter model: qwen/qwen2.5-vl-72b-instruct (configurable via env)
  • File validation: image/* MIME types only, max 50 MB