Trigger-based change log for sync
Every syncable table has a PostgreSQL trigger appending to sync_changes under one seq cursor. The app bootstraps a role-scoped snapshot once, then pulls only what changed since its cursor.
Case study · Private project
An offline-first, multi-school learning platform — NestJS API, Next.js portals and a Flutter app — built for classrooms where the internet comes and goes.
01Problem
Daw was designed for schools in Gaza running in tents and shelters, where internet and power are unreliable. Typical e-learning tools stop working the moment the connection drops.
The goal: run a full school day — attendance, lessons, quizzes, grades, parent messages — offline, and sync whenever a connection appears.
02My role
I own the product end to end: requirements, architecture, stack rules (NestJS + TypeORM + PostgreSQL, Flutter + Riverpod + drift, Arabic-first RTL) and the three repositories — backend, web, mobile — each with CI, module READMEs and tests.
03How it works
One NestJS API serves five Next.js portals (platform, school, teacher, student, parent) and the Flutter app. Media processing, PDF report cards, nightly jobs and AI indexing run on BullMQ workers.
On the phone, drift (SQLite) is the source of truth: screens read only the local database, the network just fills it, and offline work waits in an outbox.
04Screens
05Key technical decisions
Every syncable table has a PostgreSQL trigger appending to sync_changes under one seq cursor. The app bootstraps a role-scoped snapshot once, then pulls only what changed since its cursor.
One database, school_id on every school-owned table, and the school always taken from the access token — never the request body. A dedicated e2e suite proves cross-school isolation.
POST /sync/push replays offline work through the same services and permission checks as REST — no second, weaker code path.
06Hard parts solved
Each mutation carries a clientMutationId and returns APPLIED, DUPLICATE, CONFLICT or REJECTED, so flaky retries are idempotent. Explicit rules settle conflicts: an admin's attendance edit beats a teacher's offline copy; lesson fields merge one by one.
The teacher's phone runs a token-protected HTTP server on local Wi-Fi with a QR code. Lessons stream in resumable 256 KB Range chunks verified by SHA-256; quizzes arrive without answer keys.
Short answers are normalised (tashkeel, alef/hamza forms, Arabic-Indic digits) before grading. The study assistant runs RAG over each course's PDFs with pgvector (HNSW), scoped in SQL to the caller's school, and cites pages — or says the answer isn't in the materials.
07Outcome
All three apps pass their checks: zero lint/analyze warnings, reversible migrations, an Android build. It is a private project, not publicly deployed; screenshots use local demo seed data.
Source: test cases counted in each repo's main branch (Jest, Vitest, flutter_test).
Source: folders under src/modules (backend), src/features (web), lib/features (mobile).
08Stack & links
Private project — no public demo, live link or source code.
© 2026 Abd Alftah Salem · Back to portfolio