Skip to main content
@kneeraazon
Live ProductWeb Apps & SaaSCase Study

Built for Mental Health · Next.js · FastAPI · PostgreSQL · Gemini voice

CBT Recovery Coach for ADHD and OCD

A structured accountability platform built around CBT for ADHD and OCD, with a Next.js front end and a FastAPI backend on PostgreSQL. A one-time intake sets a baseline, daily, weekly and monthly tracking runs across six categories with hard gates, a check-in applies exactly one CBT tool and one homework action, a four-phase 24-week roadmap is gated by success metrics, and a Safety page is reachable from every page. It is not a therapist or a crisis service and makes no clinical claims; an optional voice check-in uses Gemini and ElevenLabs.

OUTCOME.01210API tests passing (re-run)
OUTCOME.0283 / 83Seeded bugs caught, API and web (recorded)
OUTCOME.030Known vulnerabilities in 59 API packages
2D SYSTEM TOPOLOGY // END-TO-END REQUEST PIPELINE4-STAGE DATA FLOW

Next.js Proxy → FastAPI API → PostgreSQL → Voice (Gemini)

FIG.01 // INTERFACE & SYSTEM CAPTURE1 / 10
The dashboard after the required daily tracking was logged: a banner saying check-in and roadmap are unlocked for today, tiles for check-in streak, meds adherence and homework attempt rate, and cards for Check in, Roadmap and Voice Check-In above a list of the six tracking categories.
The dashboard after the required daily tracking was logged: a banner saying check-in and roadmap are unlocked for today, tiles for check-in streak, meds adherence and homework attempt rate, and cards for Check in, Roadmap and Voice Check-In above a list of the six tracking categories.

Role

Full-Stack Developer

Duration

Since August 2026

Tech Stack

Next.js 16 and React 19TypeScript (strict)Tailwind CSS 4FastAPI and Python 3.14SQLAlchemy 2 (async) and AlembicPostgreSQLargon2id, JWT and rotating refresh cookiesGemini and ElevenLabs (optional voice)pytest, Vitest and PlaywrightDocker
SECTION 01 // PROBLEM STATEMENT

The Problem

An accountability tool for people with ADHD and OCD holds sensitive information, and it has to be safe and honest about what it is. The first version did not meet that bar: every visitor shared one rate limit, because the web proxy never passed the visitor's address on, so ten failed logins from anybody locked everybody out; any JWT secret was accepted and a mistyped environment name quietly ran as development; a signed token with no expiry was valid forever; a login for an unknown email returned faster than one for a known email; the Gemini key sat in a request URL and the default model had been shut down; voice conversations went to two outside providers as soon as keys were set; and the privacy policy promised account deletion that did not exist.

SECTION 02 // SYSTEM ARCHITECTURE & EXECUTION

My Approach

  1. Layers. Routers, services, repositories and models, with only the repositories touching the database; the browser never talks to the API directly, because Next.js route handlers proxy to FastAPI so the API origin and the refresh cookie never reach client JavaScript.
  2. Accounts. argon2id password hashing, short-lived JWT access tokens that must carry exp, iat and sub, rotating httpOnly refresh cookies, optional Google sign-in with PKCE, and a stand-in hash check so a login for an unknown email costs the same as for a known one.
  3. Rate limits. A client-address helper, a setting for whether to trust X-Forwarded-For, nginx overwriting the header, and the proxy forwarding the visitor's address, so one visitor's failures no longer lock out others and a forged header does not dodge the limit.
  4. Startup safety. Settings are validated at start: secrets must be long enough, the environment must be one of four names, and a wildcard CORS origin is refused in production.
  5. Product rules. An intake once, daily, weekly and monthly tracking in six categories with four hard gates, a check-in with exactly one CBT tool and one homework action, and a roadmap whose first two phases are gated by metrics computed on the server from real check-ins.
  6. Privacy. Voice is off until a third-party-processing acknowledgement is set, and DELETE /me with a form on the account page erases the account and everything under it (a test reads the live schema and fails if a table referencing a user lacks ON DELETE CASCADE).
  7. Accessibility. Destructive text moved to a new colour token after the old one measured 1.92 to 2.5 to 1 on dark surfaces; focus moves back into the page after deleting; 375 px wide checked for horizontal scrolling.
  8. Delivery. Python 3.14 and Node 26, a four-chapter guide, CI, Docker images that run as a non-root user, and Alembic migrations.
  9. Hosting on Vercel. The Next.js front end runs on Vercel and FastAPI is meant to be hosted separately. If the API address is missing, the proxy now answers 503 with a readable message instead of an empty 500. The sitemap and canonical URLs fall back to the Vercel production domain instead of localhost. The Google sign-in rewrite is skipped instead of pointing at localhost. The voice WebSocket, which Vercel cannot proxy, can connect to the API's own origin, and that origin is added to the CSP.
SECTION 03 // VERIFIED OUTCOMES

Results & Impact

Re-run on 2026-11-14 in a scratch copy on PostgreSQL 18: ruff check and mypy are clean on 72 source files, 210 API tests pass, uv audit finds no known vulnerabilities in 59 packages, lint, type-check and the production build are clean, 45 web unit tests pass, and npm audit finds none in production dependencies (it lists one moderate advisory in dev tooling, minimatch via typescript-eslint, below the repository's high-severity gate). All 14 database migrations applied cleanly.

The real app was also run locally that day: a fictional user signed up, completed the intake, logged the four required daily categories (which unlocked check-in and roadmap), saved a thought-record check-in and received its log block, and opened the roadmap, tools, progress, account and Safety pages. Progress and Tools read browser storage, so a synthetic payload of generated check-ins was loaded to show them. Voice was not run.

Recorded in docs/work-done.md (2026-11-12): 16 end-to-end tests passing, 49 of 49 API and 34 of 34 web mutations killed (one equivalent mutant each, documented), the API and web Docker images built and run together with the rate limit confirmed across containers (ten failed logins from one address gave 429, another address still got 401), and a visual pass at 375 px with measured contrast.

The deployed copy at therapist-cbt.vercel.app was checked on 2026-11-17. The landing, login, robots and sitemap pages answered 200. Sign-up and login answered 500, because no API address was configured and the backend has no host yet. The sitemap listed localhost addresses and the Google sign-in path answered 404. The fixes above were made that day, and lint, type-check, the production build and 48 web unit tests pass. They reach the live site once they are pushed and the Vercel project has its API address set.

Not verified: sign-in, tracking and voice on the deployed copy (they need a hosted backend), the voice feature (Gemini, ElevenLabs and the WebSocket), Google sign-in, the Playwright end-to-end suite and the Docker images in these runs, and the benefit of the tool for anyone, which this project does not claim.