BUILD · 0082026healthLIVE
The Node.js + MongoDB engine powering ClearedMind, with business rules ported faithfully from a legacy Rails app

ClearedMindBackendAPI

Production-ready Express + MongoDB API with domain-driven models, soft deletes, premium gating, and assessment scoring lifted intact from a legacy Rails system.

A modular Node.js backend that powers the ClearedMind mobile app. It handles JWT auth, role and subscription gating, mindfulness assessments with weighted scoring, premium content management, push notifications, and scheduled background jobs — hardened with rate limiting, validation at every boundary, structured logging, and a documented function catalog.

ROLE
Lead engineer & architect
TIMELINE
1 MO
TEAM
2
STATUS
LIVE

The big idea

Backends for wellness apps quietly accumulate business rules disguised as code paths. The legacy Rails system had years of this baked in. The goal here was not just to rewrite it in Node, but to lift the rules into versioned, documented models.

Architecture: domain-driven, soft-delete by default

  • Mongoose models as the source of truthUser, Resource, Assessment, Subscription, UserAssessmentResult. Each owns its validation, indexes, query helpers, and lifecycle hooks.
  • Embedded vs. referenced relationships chosen per access pattern.
  • Soft delete everywhere — every model carries archived_at and deleted_at, with a .active() query helper.
  • Compound + sparse indexes for uniqueness scoped by type.
  • Layered security — Helmet, CORS allowlist, rate limiting, Passport-JWT + bcrypt, Joi/express-validator at every boundary.

Innovative features

  • Generic assessment scoring enginesum, average, weighted strategies with result_ranges matching.
  • Edge-enforced visibility model — one canAccess function gates all/premium/private uniformly.
  • Status workflow with guardrailstemporary → draft → published, unidirectional from temporary.
  • Trial + reminder automation via node-cron + Nodemailer + Expo push.
  • Profile-completion gate computed centrally.
  • Operational ergonomics — nightly backups, function catalog, structured Winston logs, Docker compose.

Outcome

  • Replaced the legacy Rails backend without breaking a single shipped feature.
  • Centralised all business rules in versioned, documented models.
  • Stable production deployment with automated nightly backups and scheduled jobs.