Data Layer medium complexity Shared Component mobile
0
Dependencies
2
Dependents
0
Entities
1
Integrations

Description

Adapter encapsulating all interactions with Supabase Storage for receipt image management. Handles image compression before upload, generates access-controlled URLs, and manages deletion of orphaned receipt images when expense records are cancelled.

Feature: Travel & Expense Registration

receipt-storage-adapter

Summaries

The Receipt Storage Adapter is a shared infrastructure component that directly controls storage costs and data security for all receipt images across the application. By compressing images before upload, the system reduces Supabase Storage consumption — which scales with user volume — delivering ongoing cost savings as the customer base grows. Access-controlled URL generation ensures that sensitive financial documents are never publicly exposed, reducing legal and compliance risk for both the business and its enterprise clients. Automatic deletion of orphaned receipt images when expenses are cancelled prevents unbounded storage growth, protecting against unexpected infrastructure cost spikes.

As a shared component, any improvements to its compression or security logic immediately benefit all features that handle receipts.

Rated medium complexity, this shared mobile-only component affects every feature that captures or displays receipt images, making it a high-priority deliverable that should be completed and stabilised before dependent features reach integration testing. Key delivery risks include: image compression performance on lower-end mobile hardware (requires device-range testing), network failure handling during upload (retry logic and user feedback), and correct Supabase Storage bucket scoping per organisation to prevent data leakage between tenants. Because it is shared, any breaking interface change requires coordinated updates across all consuming features — treat it as a stable internal API from the point of initial release. Plan time for testing the full lifecycle: upload, URL retrieval, and deletion triggered by expense cancellation.

Implements the Adapter pattern to isolate all Supabase Storage SDK calls behind a stable domain interface, preventing storage implementation details from leaking into feature-level code. The `compressImage(imageFile, maxSizeKb)` method should run client-side before the upload call to `uploadReceipt(imageFile, expenseId, organizationId)`, which writes to an organisation-scoped bucket path for tenant isolation. `getReceiptUrl(storagePath)` should support both signed (time-limited, private) and public URL modes depending on bucket policy configuration. `deleteReceipt(storagePath)` is invoked by the expense cancellation flow and must be idempotent to handle retry scenarios safely.

The data model is `receipt`. As a shared component, all interface signatures must remain stable; changes should be versioned or feature-flagged. Consider abstracting the compression quality threshold into a configuration constant to allow tuning without code changes.

Responsibilities

  • Compress receipt images before upload to reduce storage costs
  • Upload images to organisation-scoped Supabase Storage bucket
  • Generate signed or public URLs referencing stored receipt images
  • Delete receipt images when associated expense records are removed

Interfaces

uploadReceipt(imageFile, expenseId, organizationId)
getReceiptUrl(storagePath)
deleteReceipt(storagePath)
compressImage(imageFile, maxSizeKb)

Relationships

Dependents (2)

Components that depend on this component

Used Integrations (1)

External integrations and APIs this component relies on

API Contract

View full contract →
REST /api/v1/receipts 5 endpoints
GET /api/v1/receipts List receipts for an expense
GET /api/v1/receipts/:id Get receipt metadata and download URL
POST /api/v1/receipts Upload a receipt image (multipart/form-data)
PUT /api/v1/receipts/:id Replace receipt file (re-upload)
DELETE /api/v1/receipts/:id Delete a receipt from storage