Skip to content

Data layer - #1

Merged
berkaycinar-dev merged 14 commits into
mainfrom
data-layer
Oct 26, 2026
Merged

berkaycinar-dev merged 14 commits into
mainfrom
data-layer

Conversation

@berkaycinar-dev

@berkaycinar-dev berkaycinar-dev commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a data access layer (repository pattern) between the React hooks and localStorage.

Hooks no longer read or write localStorage directly. They talk to repositories through a DataProvider. Today every repository is backed by localStorage (guest mode). Later, the same interface can get an API implementation without changing the hooks, pages or tests.

The app behaves exactly as before. Storage keys and JSON formats are unchanged, so no data migration is needed.

What changed

  • src/data/local/ – framework-free storage core
    • createLocalStore keeps the old behavior: corrupt data backup (<key>:corrupt), read/quota/unavailable warnings, and first-launch writes.
    • migrations.js and storageStatus.js moved here.
  • Repositories for tasks, routines, projects and settings
    • Synchronous snapshot (getSnapshot / subscribe, read with useSyncExternalStore), so there is no loading flash.
    • Write commands return Promises: create, createMany, update, updateMany, remove, removeMany, reorder, setCheck.
  • src/data/contracts/ – contract tests that define the interface
    • They include optimistic updates (a change is visible before the Promise settles) and stable snapshots.
    • The same suites can later run against API-backed repositories.
  • DataProvider + useRepository + useRepositorySnapshot
    • Repositories are created per provider and started on first use, once.
  • Hooks
    • useTasks, useRoutines, useProjects and the new useSettings now use the repositories. Their public APIs are unchanged.
    • useLocalStorageState was removed.
  • Pure helpers for routine streak / weekly productivity and task reordering.

Fixes

  • Toggling two routine days (or the same day twice) within one update could lose a check. Covered by regression tests.

Verification

  • Tests: 416 → 558. All existing hook and app tests kept their names and assertions.
  • Every step was checked by breaking the code on purpose and confirming the new tests fail.
  • Before/after storage comparison at every step: 0 differences.
  • Real Chromium, main vs data-layer:
    • 8 storage scenarios (fresh launch, corrupt data, full storage, tasks / routines / projects / settings flows, reload) are identical.
    • 32 screenshots (4 devices × 8 screens) show 0 pixel differences.

Commits

Each step is a separate commit. Please merge with "Create a merge commit" to keep them.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01KcNwZMqdqaTTvdpdtWqmDu

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
anchorly Ready Ready Preview Oct 26, 2026 7:28pm UTC

@berkaycinar-dev
berkaycinar-dev merged commit b180f76 into main Oct 26, 2026
3 checks passed
berkaycinar-dev added a commit that referenced this pull request Oct 28, 2026
berkaycinar-dev added a commit that referenced this pull request Oct 28, 2026

This branch was successfully deployed

1 active deployment
Preview — a64de8b0 Deployed Oct 26, 2026 by vercel[bot]
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