Skip to content

Comments

feat(import): Add Splitwise CSV Import (Stacked on #472)#483

Open
Uli-Z wants to merge 31 commits intospliit-app:mainfrom
Uli-Z:feature/splitwise-import
Open

feat(import): Add Splitwise CSV Import (Stacked on #472)#483
Uli-Z wants to merge 31 commits intospliit-app:mainfrom
Uli-Z:feature/splitwise-import

Conversation

@Uli-Z
Copy link
Contributor

@Uli-Z Uli-Z commented Dec 26, 2025

Overview

This PR implements the Splitwise Import (closes #22), building on the generic import infrastructure from #472. It enables users to migrate their group history from Splitwise to Spliit.

Note: This PR is stacked on #472. Please review and merge #472 first.

The Challenge

As discussed in #22, Splitwise exports provide a ledger of balance changes ("User A paid 50, User B owes 50") rather than the original split configuration. This means the original intent (how exactly an expense was split) is often lost.

Implementation

1. Reconstruction Algorithm

The core of this PR is a deterministic algorithm that reconstructs plausible expenses from the balance deltas.

  • Balance Guarantee: While we cannot always know the exact original split type (e.g., percentages), the algorithm guarantees that the resulting balances in Spliit match the source file exactly.
  • Reimbursement Detection: It distinguishes between shared expenses and direct payments (Reimbursements) by analyzing localized category names (e.g., "Payment", "Zahlung").

2. Localization & Future Scope

The adapter currently supports imports in English and German.

  • It automatically detects the language based on CSV headers and maps localized categories.
  • Future Scope: The implementation is designed to be extensible; adding more languages (FR, ES, etc.) is possible in future PRs.
  • Workaround: For currently unsupported languages, users can temporarily switch their Splitwise account to English before exporting the CSV to ensure a successful import.

Verification

Automated tests (index.test.ts) verify that the reconstruction logic holds up against complex scenarios (multi-payer, uneven splits, self-payments) and preserves the mathematical integrity of the group balances.

Uli-Z added 30 commits December 7, 2025 20:26
- Introduce ImportFormat interface and in-memory registry for adapters
- Add registry helper to detect formats and delegate parsing
- Add file import builder to parse, collect errors, and compute participant summaries via balances
- Establish clear types for parsed group meta (name, currency, participants)
- Implement robust detection on full JSON payload with minimal structure checks
- Parse export into ExpenseFormValues; coerce amounts/dates and validate against schema
- Aggregate per-row errors and expose optional group meta (name, currency, participants)
- Self-register adapter in the global registry
- Add marker-based debug format (DEBUG_IMPORT/DEBUG_ERRORS) with unambiguous detection
- Emit one error per line for quick UI testing of failure paths
- Include simple fixture file for manual verification
- Register debug adapter with registry at low priority
…finalize)

- Expose preview endpoint to parse and summarize uploaded file before import
- Implement job-based create flow with chunked processing and progress reporting
- Provide cancel/cleanup and finalize endpoints to control lifecycle
- Register endpoints under groups router
- Dropzone with drag-and-drop and accessible labeling
- Analysis panel to display detected format, totals and errors
- Progress view for chunked import with visual bar
- Result view to confirm completion or cancellation
- Combine upload + preview + scroll-to-confirm + chunked import in one dialog
- Handle cancel/finalize flows with toasts and resilient state reset
- Support optional prefill of group name from parsed file meta
- Integrate TRPC mutations with defensive error handling
- Add Import from file option to create menu
- Mount FileImportModal and navigate to new group on success
- Persist created group to recent list and refresh view
- Add strings for upload, preview errors, progress, and results
- Provide German, English, Spanish and French localizations
- Wire keys used across import components and modal
…ility

Extracted complex parsing logic from 'parseToInternal' into smaller, private helper methods for better readability and easier maintenance.
Implemented a daily cleanup of ImportJob records older than 24 hours at the start of a new import, preventing database bloat from stale jobs.
Implemented Zod validation for 'expensesToCreate' in the ImportJob model when processing chunks. This ensures data integrity and prevents runtime errors from corrupted job data by safely parsing and validating the JSON.
…factoring

This commit consolidates the review feedback implementation:

Security & Robustness:
- Enforced a 10MB limit on file uploads to prevent DoS.
- Implemented optimistic locking in chunk processing to prevent race conditions.

Refactoring:
- Extracted UI logic into 'useFileImportProcess' hook for better separation of concerns.
- Centralized participant derivation logic in the import library.

Quality:
- Added integration tests for category mapping consistency.
- Applied code formatting.
- Updated ImportFormat interface to be async (Promise-based) to support non-blocking operations and future worker offloading.
- Moved file preview logic from server-side tRPC to client-side.
- Removed fs dependencies from import parsers to allow browser execution.
- Removed obsolete importFromFilePreview tRPC endpoint.
- Fixed type errors and updated tests to align with async interface.
Adds a new tRPC procedure 'processBatch' that accepts a list of expenses and inserts them transactionally. This enables client-side batching strategies.
Moves the import orchestration to the client to reduce server load and complexity.

- Implements batching logic (processing 50 expenses at a time).
- Adds a 10MB file size limit validation.
- Includes logic to correctly map participant names to UUIDs during the import process, ensuring expenses are linked to the correct users even if the source file uses names.
…cedures

Removes the stateful 'ImportJob' model and associated procedures (start-job, run-chunk, etc.).

Previously, the server tracked import progress in the database, which caused excessive I/O overhead. The process is now stateless on the server, relying on the new client-driven batching approach.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import from Splitwise

1 participant