The REST API and admin panel for a subscription habit-tracking iOS app: habits on daily, weekly or monthly schedules, completion scores, reminders and App Store billing.
The client had a habit app on an older Express backend and wanted it rebuilt with subscriptions, an admin panel and cleaner data. Users track good habits, picked from a suggested catalogue or written themselves, and bad habits they want to cut, on schedules like “every weekday” or “once a month”, and see how consistently they keep them.
The core rule is easy to state and fiddly to implement: a habit's period ends at the user's midnight, not the server's, for users spread across time zones.
Feature modules with separate user and admin controllers over shared services, so admin endpoints have their own guards and DTOs without branching inside handlers.
An interceptor wraps every success in the same envelope (success flag, message, data, pagination), and exception filters return the same shape for errors. Validation rejects unknown fields and flattens nested errors into one readable message the app can show as is.
Each assigned habit has a current status, pending or completed. A log table keeps a dated completed or missed record for every period, and scores are computed from the log.
Services emit events such as habit.assigned and habit.merged, and a listener sends the push notifications, so business logic doesn't depend on Firebase.
One job covers every time zone, including half-hour offsets, instead of one scheduled job per user.
Daily, weekday, weekend, weekly and monthly habits. Completing a weekday habit on a Saturday, or the same habit twice in one period, is rejected.
Each schedule type is scored over its own period. The overall score averages only the types a user actually has, so someone with only daily habits isn't penalised for having no weekly ones.
Phone verification through Twilio Verify. The session token is bound to a device, and signing in elsewhere blacklists the older session.
Receipt verification with a sandbox fallback, and App Store server notifications for renewals, expiry, cancellations and plan changes. The first 1,000 users get a free plan; later sign-ups get a trial.
Habit catalogue, merging duplicate habits (with users notified), blog with resized WebP image variants, FAQs, support tickets with threaded replies, and plans priced per country.
An offset is simple to store and to query by window. But it misses daylight-saving changes until the next login, and the day of the week comes from the UTC date. Storing the IANA zone and computing the local date would fix both.
Duplicating some routing was worth it: user and admin endpoints evolve differently and need different guards, and keeping them apart made both easier to read.