Service Layer medium complexity mobile
0
Dependencies
1
Dependents
1
Entities
1
Integrations

Description

Performs client-side image compression before upload to Supabase Storage, reducing file size while preserving legibility for auditing purposes. Enforces a maximum file size limit and converts images to a standardized format. Returns a compressed file ready for upload.

Feature: Receipt Capture and Attachment

receipt-image-compressor

Summaries

The Receipt Image Compressor reduces the size of photos taken on modern smartphones before they are uploaded to cloud storage, directly lowering storage costs at scale and improving upload speed on mobile networks. Faster uploads mean employees experience less friction when attaching receipts, increasing completion rates for compliant submissions. By standardizing the image format and enforcing a maximum file size, the component also ensures that the resulting files are legible for auditors without consuming excessive storage. PDF pass-through support accommodates users who store digital receipts, broadening the range of valid submission formats without additional complexity.

Medium-complexity component with no external dependencies, making it a strong candidate for early parallel development. The primary risk is compression quality — over-aggressive compression can produce receipts that are illegible for auditing, which is a compliance issue. QA must include visual legibility checks at the configured size limit, not just file size assertions. The `maxSizeKb` parameter should be driven by configuration to allow tuning without code changes.

PDF pass-through logic is straightforward but must be tested explicitly. No deployment dependencies exist — this component can be delivered and tested in isolation before the Receipt Attachment Service requires it. Estimate 2–3 days including edge case coverage.

The Receipt Image Compressor operates as a pure transformation utility — input is a `File`, output is a compressed `File`, with no side effects or external I/O. Use a platform-appropriate image compression library (e.g., `flutter_image_compress` on mobile) to handle JPEG/PNG resizing and quality reduction. The compression loop should iteratively reduce quality until the file is under `maxSizeKb`, with a safety exit to prevent infinite loops. Dimension resizing should maintain aspect ratio.

PDF files must be detected by MIME type (not file extension) and returned unchanged. The `getCompressionRatio` method is diagnostic-only and can be lazy — compute on demand rather than during the compression pass. Expose `isFileSizeAcceptable` as a pre-check so callers can short-circuit when the original is already within limits. No state is held between calls; the service is safe to use as a singleton.

Responsibilities

  • Compress images to target file size limit
  • Resize image dimensions proportionally if oversized
  • Validate file size after compression against configured limit
  • Pass through PDF files without modification
  • Report compression statistics for diagnostics

Interfaces

compressImage(File imageFile, {int maxSizeKb})
getCompressedSize(File imageFile)
isFileSizeAcceptable(File file)
getCompressionRatio(File original, File compressed)

Relationships

Dependents (1)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component

Used Integrations (1)

External integrations and APIs this component relies on

API Contract

View full contract →
REST /api/v1/receipt-images 5 endpoints
GET /api/v1/receipt-images List compressed receipt images on record
GET /api/v1/receipt-images/:imageId Get metadata for a specific compressed receipt image
POST /api/v1/receipt-images/compress Compress an uploaded receipt image
POST /api/v1/receipt-images/size-check Estimate compressed size and acceptability before full upload
DELETE /api/v1/receipt-images/:imageId Delete a compressed receipt image record