MABANDLA®
BuildsAtlasField notesAboutLet's talk ↗

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

ClearedMind Backend API

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.

2026 · health · Live · Lead engineer & architect · 1 months · team of 2

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 truth — User, 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 engine — sum, average, weighted strategies with result_ranges matching.
  • Edge-enforced visibility model — one canAccess function gates all/premium/private uniformly.
  • Status workflow with guardrails — temporary → 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.

Built with

Node.js 18+ExpressMongoDBMongoosePassport-JWTbcryptJoiexpress-validatorNodemailerExpo Server SDKWinstonnode-cronSocket.IOFirebase AdminAzure Blob StorageDockerJest
All builds →
← PREVIOUSClearedMindNEXT →Universal AI Agent
MABANDLA®

AN ARCHITECTURE OF ONE · JHB · MMXXVI

Contact
bumat11@gmail.com
Social
githublinkedin
Pages
buildsfield notesaboutstackcontactatlas
Colophon

v6 · built in JHB

© 2026 Bubele Mabandla.