Skip to content

feat: implement offline-first typed data layer for mailbox (#69)#90

Open
strngecloud wants to merge 6 commits into
Stellar-Mail:mainfrom
strngecloud:feat/offline-first-data-layer
Open

feat: implement offline-first typed data layer for mailbox (#69)#90
strngecloud wants to merge 6 commits into
Stellar-Mail:mainfrom
strngecloud:feat/offline-first-data-layer

Conversation

@strngecloud

Copy link
Copy Markdown

Offline-First Typed Data Layer for Mailbox

Summary

Replaces hard-coded component data with a typed, offline-first repository pattern that enables reliable synchronization, testing, and recovery.

Changes

  • New Feature: Typed repository interface (IMailboxRepository) with CRUD operations for messages, threads, contacts, policies, proofs, and sync cursors
  • Memory Adapter: In-memory implementation for deterministic testing
  • Storage Adapter: localStorage-backed persistence with automatic hydration
  • React Hook: useMailbox() hook providing state management with loading states (idle, loading, stale, error)
  • Idempotent Mutations: All operations are safe to retry
  • Seed Data: Development data using realistic timestamps instead of string times
  • Schema Versioning: Support for future migrations via version field

Acceptance Criteria Met

✅ Components depend on interfaces, not seed data
✅ Loading, stale, offline, and error states modeled
✅ Mutations are idempotent
✅ Migration strategy exists for local schema changes
✅ Same logic works against both memory and storage adapters

Files Added

  • src/features/mailbox/types.ts - Core domain types
  • src/features/mailbox/repository.ts - Repository interface
  • src/features/mailbox/adapters/memory-adapter.ts - Testing adapter
  • src/features/mailbox/adapters/storage-adapter.ts - Production adapter
  • src/features/mailbox/useMailbox.ts - React hook
  • src/features/mailbox/seed.ts - Seed data
  • src/features/mailbox/README.md - Architecture documentation

Files Modified

  • src/components/mail/data.ts - Removed hardcoded emails, added helper functions
  • src/routes/index.tsx - Integrated useMailbox hook, replaced local state

Testing

Run existing tests to verify no regressions:

npm run test

Components automatically work offline via localStorage and continue functioning if network fails.

Closes #69

…ail#69)

- Add typed repository interface for messages, threads, contacts, policies, proofs, and sync cursors
- Implement memory adapter for deterministic testing
- Implement storage adapter for persistent offline-first state
- Add React hook (useMailbox) for managing mailbox state with loading states
- Support idle, loading, stale, and error states for reliable synchronization
- Ensure all mutations are idempotent
- Create seed data for development
- Update mail route to use new data layer
- Replace hard-coded component data with repository pattern
- Enable versioning for future schema migrations
@strngecloud

Copy link
Copy Markdown
Author

@kryputh
please approve

@kryputh

kryputh commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

@strngecloud fix all

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.

client: replace mock mailbox state with a typed offline-first data layer

2 participants