Coach a fictional friend through a hard moment, then discover the advice was for you.
Dear Alex is a private, playful self-help experience for university students after a setback. It turns self-distancing into a four-minute narrative: the user helps Alex, then watches the story return to their own words as a Letter to You.
If you are a developer or reviewer, start here:
- START_HERE.md: Master developer blueprint, memory recovery guide, architectural rationale, and engineering mental model.
- docs/ARCHITECTURE.md: Architecture and data flow.
After a disappointing grade, awkward social interaction, or failed performance, students often meet themselves with a harsher voice than they would use with a friend. Dear Alex creates a little distance first, so the player can practise a fairer response.
The player tells Alex’s story, offers three pieces of coaching, and receives their own advice as a saved letter. The mechanism is self-distancing, not points: viewing a situation from an outside perspective can support wiser reasoning and emotion regulation [1]–[3].
Read the full research basis document for in-depth analysis of Solomon's Paradox and how each study maps directly to the system design choices.
- Optional 1–5 mood check-in with always-visible skip/exit paths.
- Intake, category selection, and character naming (personalize your companion).
- Deterministic, aligned first-person-to-third-person story engine with confidence scoring and safe fallback.
- Crisis-language safety gate that routes to Canadian 9-8-8 and UVic Counselling before saving to database.
- Three coaching scenes with 18 curated Compassion, Perspective, and Action cards or free text.
- Dynamic visual world ("Alex’s World"): sky, light level, and horizon brighten as kind advice is offered.
- Word-by-word Reveal animation: tokens morph back into your own original sentences.
- In-App Diagnostics & Test Launcher: Direct header button to launch live tests for backend health, normal workflow simulation, and emergency crisis redirection verification right in the browser.
- Classical ambient music: local, opt-in Web Audio synthesis of an original Satie/Bach-inspired piano nocturne (zero network calls).
- Light & Dark mode: seamless theme switching respecting accessibility and contrast.
- Accessibility preferences: the accessibility button in the header opens motion, contrast and text-size settings. Each follows your device (
prefers-reduced-motion,prefers-contrast) by default, can be overridden, and is stored only in this browser (localStorage, keydear-alex-a11y). - Automated showcase procedure: click "Watch auto-demo" on the home screen or run the automated scripts.
- Local SQLite vault & collection slots that celebrate growth without streak pressure.
- Scored past-letter resurfacing, JSON export, and device-scoped deletion.
- Demo seed data:
python -m app.seed_demo.
No streaks, streak restores, XP loss, push notifications, leaderboards, accounts, paywalls, or social sharing. A wellbeing tool should not turn missed days into guilt.
Prerequisites: Python 3.11+ and Node.js 22+.
cd backend
python -m venv .venv
# Activate virtual environment:
# macOS / Linux:
source .venv/bin/activate
# Windows PowerShell:
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
python -m uvicorn app.main:app --reload --port 8000cd frontend
npm install
npm run devOpen http://localhost:5173 in your browser.
| Variable | Default | Description |
|---|---|---|
CORS_ORIGINS |
http://localhost:5173 |
Comma-separated list of browser origins the backend allows via CORS, e.g. CORS_ORIGINS=https://app.example.com,http://localhost:5173. |
To pre-populate demo data into the vault, run from backend directory: python -m app.seed_demo. Its terminal output prints the demo device ID; set that ID in browser localStorage under dear-alex-device-id to view it.
You can run automated end-to-end verification and interactive showcases in four ways:
-
Unified Master Test & Concurrency Suite (Recommended):
python scripts/automated_system_test.py
Automatically kickstarts servers and executes:
- Stage 1: Multi-threaded database concurrency stress test (measures throughput and p50/p95 latency, and fails if any request errors; SQLite runs in WAL mode).
- Stage 2: Launches Chromium (via Playwright) and drives a complete normal student session (mood, intake, 3 scenes, lantern glow, word-by-word reveal, letter vault).
- Stage 3: Launches Chromium and tests an emergency crisis interaction (verifies immediate 9-8-8 helpline & UVic Counselling routing, plus a direct SQLite query confirming the crisis phrases were not saved).
(Add
--headlessto run the browser without a visible window. Requirespip install playwright && playwright install chromium.)
Running the end-to-end suite locally (the same way CI does):
pip install -r backend/requirements.txt -r scripts/requirements-e2e.txt playwright install chromium # add --with-deps on a fresh Linux box (cd frontend && npm ci && npm run build) (cd backend && python -m uvicorn app.main:app --port 8000) & (cd frontend && npx vite preview --port 5173 --strictPort) & python scripts/automated_system_test.py --headless
If the servers are not already running the script starts the backend and the Vite dev server itself. Set
E2E_ARTIFACT_DIR=some/dirto get a failure screenshot and a Playwright trace (npx playwright show-trace <file>.zip) when a browser stage fails. -
In-App Auto-Demo (Zero setup): Open
http://localhost:5173and click "Watch auto-demo" on the welcome screen. The app will automatically enter a realistic student scenario, coach Alex, morph the words in the Reveal, and seal the letter. -
Terminal API Showcase Runner:
python scripts/api_showcase.py
Simulates and validates the complete game loop, self-distancing transform, 3 scenes, and letter generation in your terminal.
-
Standalone Browser Automation:
python scripts/demo.py --headed --slow
flowchart LR
React --> FastAPI --> SQLite
FastAPI --> StoryEngine
FastAPI --> SafetyGate
See the full architecture document.
This is not therapy or a substitute for professional care. A conservative safety check routes clear crisis wording to 9-8-8 (Canada) and UVic Counselling information; it is intentionally evaluated before text reaches the database. There are no accounts or analytics. Data stays on the local deployment and can be exported or deleted.
- GitHub Actions CI Workflow: GitHub Actions automatically runs backend
ruff check,ruff format --checkandpytest, frontendnpm ci,npm run lint,npm test(Vitest) andnpm run build, and the headless Playwright end-to-end suite (its owne2ejob; screenshots, traces and server logs are uploaded as an artifact on failure) on pushes tomainand on pull requests intomain. - In-App Diagnostics & Crisis Demo: In the frontend UI, click Diagnostics & Tests or Demo Crisis Hotline Screen to test API health, application flow, and safety gates live.
- Frontend Unit Tests (
cd frontend && npm test): Vitest + Testing Library cover the accessibility-preference logic and that the settings UI applies and persists it. - Backend Test Suite:
cd backend
.venv/bin/pytest -vThe 76 tests cover 32 story-engine cases, crisis detection and false-positive guards, deterministic resurfacing selection, edge cases including multi-thread DB access, and an end-to-end API workflow.
START_HERE.md Developer blueprint & memory recovery guide
backend/app/ FastAPI, models, story engine, safety, seed script
backend/tests/ pytest suite (76 tests covering engine, safety, resurfacing, showcase, edge cases)
frontend/src/ React screens, Diagnostics modal, Web Audio classical synthesizer, and styles
scripts/ Automated showcase scripts (in-browser Playwright & terminal runner)
docs/ Research basis, architecture, design principles, agent disclosure
The rule-based language transform only supports common English first-person forms and uses a quoted fallback for uncertain text. The crisis check is not a clinical assessment. Future work could include expanded linguistic rules and user research with appropriate ethics review.
See the agent disclosure.
MIT © 2026 Deniz Ikili. See LICENSE.
- E. Kross et al., “Self-talk as a regulatory mechanism: How you do it matters,” Journal of Personality and Social Psychology, 2014.
- I. Grossmann and E. Kross, “Exploring Solomon’s paradox,” Psychological Science, 2014.
- E. Kross and O. Ayduk, “Self-distancing: Theory, research, and current directions,” Advances in Experimental Social Psychology, 2017.