Cursor prompt

Build Data Export Feature

Export large datasets to CSV or Excel with streaming for memory efficiency, background jobs, and signed download links.

Build a data export feature for {{project_name}} that exports {{entity}} records.

## Formats: {{export_formats}}
## Expected volume: {{data_size}}

### Architecture
Large exports (> 5k rows): async background job + polling + signed download URL.
Small exports: direct streaming response with Content-Disposition: attachment.

### Background Export Job
1. POST /api/exports → create Job record (status: pending), return jobId
2. Queue worker picks up job, starts processing
3. Batch DB queries: fetch {{batch_size}} rows at a time to stay memory-efficient
4. Stream rows to CSV/Excel incrementally using csv-stringify or exceljs streaming API
5. Upload completed file to {{storage}} with private ACL
6. Update Job: status → done, downloadUrl (signed, expires in {{expiry}}h)
7. GET /api/exports/:jobId → return status + downloadUrl when done

### CSV Implementation
- UTF-8 BOM prefix for Excel compatibility: 
- Proper header row from column definitions
- Quote fields containing commas, newlines, or quotes
- Handle null/undefined values as empty strings

### Excel Implementation
- Auto-width columns based on header + first 50 rows
- Frozen header row with bold styling
- Date cells formatted as dates (not numbers)

### Security
- Verify user owns the export job before returning download URL
- Signed URLs expire after {{expiry}} hours
- Never serve files without re-checking authorization

### Output
Export API route, job worker, CSV/Excel generators, progress polling component.

Fill in: {{project_name}}, {{entity}}, {{export_formats}}, {{data_size}}, {{batch_size}}, {{storage}}, {{expiry}}. In Loopy you fill these in a form and copy the finished prompt in one click.