Skip to content

Replace Monica file import with API-crawl approach#18

Merged
bashar-qassis merged 4 commits intomainfrom
feature/monica-api-import
Apr 3, 2026
Merged

Replace Monica file import with API-crawl approach#18
bashar-qassis merged 4 commits intomainfrom
feature/monica-api-import

Conversation

@bashar-qassis
Copy link
Copy Markdown
Owner

@bashar-qassis bashar-qassis commented Apr 3, 2026

Summary

  • Replace the unreliable file-based Monica import with a direct API-crawl that paginates through GET /api/contacts?limit=100&with=contactfields, importing all embedded data in a single pass
  • Remove all old Monica import code — file parser, API supplement workers, photo batch sync worker (-3,521 lines of dead code)
  • Add CI auto-versioning using conventional commits and a manual dev build workflow for GHCR

What changed

New API-crawl import (monica_api)

  • 4-phase architecture: contact crawl → cross-reference resolution → extra notes → photos
  • first_met_through_contact resolved reliably via two-pass approach (all contacts imported before any cross-references resolved)
  • Batch photo import via GET /api/photos?limit=100 instead of per-contact requests
  • Connection tested in the import wizard before job creation
  • Rate limit handling with 429 retry + sleep

Old code removed

  • monica.ex (1,407 lines) — file-based import with v2/v4 format normalization
  • ApiSupplementWorker — per-contact API calls that hit rate limits
  • PhotoBatchSyncWorker — per-photo downloads, also rate-limit-prone
  • :api_supplement Oban queue
  • Associated tests and fixtures

CI improvements

  • Production publish auto-versions from conventional commits (feat: → minor, fix: → patch, ! → major)
  • Creates git tags (v0.1.0, v0.2.0, ...) and pushes to GHCR with semver + latest
  • New dev-build.yml workflow: manually trigger from any branch, optional tag suffix (e.g. rc1)

Test plan

  • mix quality passes (compile + format + credo --strict + sobelow + dialyzer)
  • 988 tests, 0 failures (down from 1037 — removed old Monica tests)
  • New: 40 tests covering API crawl, pagination, cross-references, rate limiting, cancellation, re-import
  • Manual: test dev build workflow via Actions → "Dev Build" → Run workflow
  • Manual: verify auto-versioning on merge to main

🤖 Generated with Claude Code

Replace the unreliable file-based Monica import supplement approach with
a direct API-crawl that paginates through GET /api/contacts and imports
all embedded data in a single pass. Resolves first_met_through_contact
and relationships in a second pass after all contacts exist locally.

- New MonicaApi source module with 4-phase crawl architecture
- New MonicaApiCrawlWorker (Oban, 30-min timeout, queue: :imports)
- Import wizard updated with "Monica CRM (API)" option and connection test
- Batch photo import via GET /api/photos (no per-contact requests)
- Extra notes fetched only for contacts with >3 notes
- 40 tests covering pagination, cross-references, rate limiting, and more
The new API-crawl approach (monica_api) fully replaces the file-based
Monica import. Remove all dead code paths:

- Delete monica.ex (1400-line file-based import source)
- Delete ApiSupplementWorker (per-contact API calls that hit rate limits)
- Delete PhotoBatchSyncWorker (per-photo download, also rate-limit-prone)
- Strip Monica-specific logic from ImportSourceWorker (now vCard-only)
- Remove "Monica CRM (file)" option from import wizard
- Remove api_supplement_options/fetch_supplement/list_photos callbacks
- Remove :api_supplement Oban queue
- Delete associated tests and fixtures (-3543 lines)
@bashar-qassis bashar-qassis force-pushed the feature/monica-api-import branch from 1aeffea to e474853 Compare April 3, 2026 19:25
… how-we-met editor, and expanded data types

- Add address and note deduplication during import to prevent duplicate sub-records
- Add auto-merge toggle for definite duplicate contacts (same name + shared email/phone)
- Add "How We Met" slide-over panel with grouped sections (When/Where/Who/Story) and contact picker
- Add phone number normalization (E.164 storage) with account-wide display format setting
- Import 8 new data types from Monica: pets, calls, activities, gifts, debts, tasks, reminders, conversations
- Add async document import worker (MonicaDocumentImportWorker) for background file downloads
- Add Playwright E2E tests: 5 spec files with 33 tests covering all new features
- Add shared test helpers (contacts.ts) and vCard fixtures for import dedup testing
@bashar-qassis
Copy link
Copy Markdown
Owner Author

Verified on dev. a lot of pollution from the monica data (duplicate contacts) but that's likely caused by a bug in their carddav. contacts merge feature handles this after import manually. automatic merge only happens if its 100% certain

@bashar-qassis bashar-qassis merged commit b7be75d into main Apr 3, 2026
5 checks passed
@bashar-qassis bashar-qassis deleted the feature/monica-api-import branch April 3, 2026 23:17
bashar-qassis added a commit that referenced this pull request Apr 3, 2026
Incorporate phone_format support from PR #18 (monica-api-import)
into the redesigned contact page layout. Keep redesigned UI as
the canonical version, add phone_format prop to ContactFieldsComponent
in both desktop and mobile views.
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.

1 participant