Skip to content

How we built Dhikrly: a local-first Islamic companion app on Next.js and Supabase

The stack behind dhikrly.com, and the problems that took the most work: cross-device sync that doesn't overwrite your day, prayer reminders in every time zone, and a Qur'an you can download for offline use.

By StackNothing7 min read

How we built Dhikrly: a local-first Islamic companion app on Next.js and Supabase: article title on a blue background

Dhikrly started as a dhikr counter. It's now a free, ad-free Islamic companion that runs in the browser and installs as a PWA. It includes prayer times with a live countdown, daily adhkār, a tasbīḥ counter, a Qur'an reader with word-by-word translation and memorisation tools, a Qibla compass, a halal barcode scanner, a zakāt calculator and a missed-prayer (qaḍā) tracker.

This is how it's built, and the problems that took the most work to get right.

The stack

LayerWhat we use
FrameworkNext.js 16 (App Router), React 19, TypeScript
StylingTailwind CSS 4 with CSS custom properties for themes
Prayer timesadhan (astronomical calculation, on the device)
Accounts and syncSupabase: PostgreSQL, Row Level Security, OAuth
Offline storagelocalStorage for state, IndexedDB (idb-keyval) and Cache Storage for the Qur'an
RemindersService worker plus Web Push (VAPID keys, web-push)
Barcode scanningNative BarcodeDetector, with @zxing/library as a fallback
ChartsRecharts
QualityVitest unit tests, Playwright end-to-end tests, Sentry, Vercel Analytics and Speed Insights
BackupsA nightly GitHub Actions job that dumps the Supabase database

Local first, cloud second

Dhikrly is built for short visits: tick off the morning adhkār, check when ʿAṣr starts, count a round of tasbīḥ. A spinner while that waits for a server would make the app worse at its main job.

So every action writes to localStorage first, synchronously, and the interface updates straight away. If you're signed in, the same change is added to a sync queue that's sent to Supabase in the background, with exponential backoff when the network is flaky. If you're offline, the queue waits and drains when the connection comes back.

You don't need an account at all. Signing in only adds sync between your devices.

Challenge 1: sync that doesn't overwrite your day

The first version synced each day as one document: a JSON blob of everything you'd done that day. It looked fine with one device. With two, it broke in a predictable way. Tick Fajr on your phone, then tick a dhikr on your laptop before the phone's change has arrived, and the laptop uploads its whole day, without Fajr.

The fix was to stop syncing documents and sync individual items instead. Every completed adhkār or prayer is its own row:

create table if not exists public.practice_entries (
  user_id uuid not null references auth.users(id) on delete cascade,
  date date not null,
  area text not null check (area in ('adhkar', 'salah')),
  item_key text not null,
  value jsonb not null,
  updated_at timestamptz not null default now(),
  primary key (user_id, date, area, item_key)
);

Two devices editing different items never touch the same row, so they can't overwrite each other. For the rare case where both edit the same item, a trigger keeps whichever change is newer:

create or replace function public.keep_latest_practice_entry()
returns trigger language plpgsql as $$
begin
  if new.updated_at < old.updated_at then
    return null; -- an older edit arrived late: ignore it
  end if;
  return new;
end;
$$;

Row Level Security policies on the table mean a signed-in user can only read and write rows where auth.uid() = user_id, so the browser can talk to Supabase directly without a custom API in between.

Challenge 2: prayer reminders in every time zone

Prayer times are calculated on the device with adhan, from your coordinates, calculation method and ʿAṣr school. There's no server round trip, and it works offline.

Reminders are harder, because they have to arrive when the phone is closed. Users can subscribe to morning and evening adhkār reminders through Web Push. A serverless cron route runs every hour, and for each subscription it works out the local date and time in that user's own time zone:

const parts = new Intl.DateTimeFormat("en-CA", {
  timeZone: timezone,
  year: "numeric", month: "2-digit", day: "2-digit",
  hour: "2-digit", minute: "2-digit", hourCycle: "h23",
}).formatToParts(date);

Each subscription stores when its morning and evening reminders were last sent. The cron route checks that before sending, so a slow run or a retry doesn't send the same reminder twice.

The other surprise was iOS. Web Push on iPhone only works after the app has been added to the Home Screen, from iOS 16.4 onwards. Dhikrly detects iOS Safari and shows step-by-step instructions instead of a permission prompt that would quietly fail.

Challenge 3: a Qur'an that works offline

Reading the Qur'an on a flight or with no signal means the text and audio have to be on the device already. Version 2.4.5 added full offline downloads: individual sūrahs, juzʾ, or all 114 sūrahs (6,236 āyāt) for a chosen reciter.

Text and metadata (Uthmani script, translation, transliteration and word-by-word data) go into IndexedDB. Audio goes into Cache Storage. That split matters: audio files are large, and Cache Storage lets the service worker serve them back to the audio player as if they came from the network.

Downloading hundreds of files reliably took most of the effort:

  • A small queue. At most three downloads run at once, so the app stays responsive and doesn't trip rate limits on the audio CDN.
  • Resumable files. Each request uses HTTP Range headers, plus If-Range with the file's ETag, so a paused or dropped download carries on where it stopped. If a server ignores Range and returns the whole file, the code falls back to a normal full download.
  • Retries with jitter. Failed requests back off exponentially, with random jitter so many clients don't all retry at the same moment.
  • Storage that isn't evicted. The app asks for persistent storage with navigator.storage.persist(), shows usage from navigator.storage.estimate(), and warns before large downloads on a cellular or data-saver connection.
  • Checks on what arrived. Audio files are validated after download, and an older storage format is migrated automatically.

All of this is covered by Vitest unit tests and a Playwright test that runs the offline flow on desktop and mobile viewports.

Challenge 4: living with a service worker

A service worker makes the app installable and fast to reopen, but it also caches mistakes. Dhikrly uses cache-first for the app shell and immutable Next.js chunks, and network-first with an offline fallback for page navigations, so content stays fresh when you're online.

Updates were the tricky part. A common pattern reloads the page when a new service worker takes control. On a first visit, though, the service worker takes control for the first time, which triggered a pointless reload. The update hook now only reloads when it's upgrading from an earlier active service worker.

Challenge 5: a barcode scanner that works on iPhone

The halal scanner reads a product's barcode and looks it up in Open Food Facts to check its ingredients and E-numbers. The browser's built-in BarcodeDetector is fast and costs nothing to load, but it isn't available in every browser, iOS Safari and Firefox included. The scanner tries the native API first and falls back to ZXing where it's missing, so it works on iPhone as well as on Android.

The unglamorous fixes

A lot of the work after launch was polish that nobody notices until it's wrong:

  • Hydration mismatches. The insights page had six. Values that depend on the device's clock or storage are now only rendered after the component has mounted.
  • Horizontal scrolling on small phones. Below 420px wide, the masjid timetable, prayer cards and date picker overflowed. They now fit.
  • Layout shift. Switching tabs in Settings used to jump. The selected tab is now known during server rendering, so nothing moves.
  • Clipped badges. The "Now" and "Next" labels on prayer cards were cut off by overflow: hidden and now sit inside the card header.

Learning while shipping

Dhikrly was also how we learned a large part of this stack. Much of it was new at the start, and deploying a PWA with accounts, sync and push notifications had more moving parts than expected. The habits that kept it manageable:

  • Ranked work. A to-do list ranked from P0 to P3 decides what's next.
  • A changelog. Every release is written up, and the version is shown in the app's footer.
  • Tests on the risky parts. Tests focus on the code most likely to break quietly: sync, offline storage and prayer-time logic.

Sources

Docs & Tooling

Welcome to the StackNothing blog

What this blog covers, who it's for, and how each article is put together: deep dives into languages and frameworks, case studies and performance write-ups.

By StackNothing 2 min read