Technical Deep Dive

ACT Journal — AI System Design

How a solo-built AI journaling app does 14 AI task types across 3 providers for ~$0.09 per session.

14
AI task types
3
AI providers supported
$0.09
cost per session
89.9%
eval pass rate
01

The Product

An AI journaling app grounded in ACT (Acceptance & Commitment Therapy). Users define their values, journal daily, and receive AI reflections that track behavioral patterns over time.

AI Reflections

Streaming, multi-turn responses that reference values, history, and patterns.

Pattern Detection

Tracks behavioral shifts, recurring themes, emotions, and promises made.

Insight → Action

Suggests practices with daily tracking. Detects when you've tried them.

Therapeutic framework invisible to users. No jargon — the ACT scaffolding shapes the AI's behavior, never the surface of the app.

02

Architecture

A serverless stack: the frontend never touches AI providers directly — every call flows through an edge-function proxy that owns auth, keys, access control, and cost tracking.

React 19 + Vite
modern frontend · instant UI · minimal deps
Supabase
database · auth · row-level security on every table
Edge Function Proxy
auth · key management · access control · cost tracking
AI Providers
Claude · GPT · Gemini

Key Decisions

Server-side keys

API keys live on the server, never in the browser.

Runtime prompt loading

AI instructions in a text file — change behavior without changing code.

Three prompt sizes

Bigger prompt for important tasks, smaller for simple. Less context = less cost.

Instant UI

The app never waits for the database.

Working formulation

Compact user model generated once, reused in every AI call.

No backend server

Serverless functions only.

03

What the AI Does

14 specialized tasks, grouped by when they fire — at each entry, during each conversation, and across the whole journal over time.

Each Entry

  • ReflectionStreaming response referencing values, history, patterns.
  • Emotion mapping2–3 emotions from Plutchik's 8.
  • Value taggingWhich values does this entry touch.
  • Label + summaryShort title + bullets, batched.

Each Conversation

  • 5-turn follow-upDeepens reflection, checks in on active practices.
  • Move detectionToward or away from a value.
  • Practice suggestionConcrete action with a cue trigger.
  • Commitment extractionDetects "I'm going to…" and tracks it.

Over Time

  • InsightsWeekly / monthly / all-time pattern analysis.
  • About YouAn evolving portrait.
  • Working FormulationCompact model that calibrates every AI call.
  • Themes + digestsRecurring patterns + monthly narrative summaries.
04

Prompt Engineering

v1 → v6. Rewrote from imperative rules to values-driven guidance.

v1 — what NOT to do

Telling the AI what not to do produced robotic output — stilted, defensive, hollow.

v6 — how to think

Describing how it should think — its worldview, beliefs, what it cares about — produced natural, calibrated responses.

Three prompt tiers

Full · ~15KB

Reflections, conversations

Full personality + task rules + the user's values, history, and patterns.

Overview · ~13KB

Insights, About You, digests

Personality + task rules + all journal entries, no per-entry context.

Light · ~10KB

Labels, tags, emotions

Minimal personality + output format only. Fast and cheap.

The prompt is a static file — edit prose, deploy instantly, no code changes.

05

Cost Optimization

Before
$2.83
per user / day
−97%
After
$0.09
per session

Four levers

Prompt Caching

35KB system prompt cached 5 min; turns 2–5 hit ~90% cache rate → 10% of input cost.

Model Routing

Haiku for labels at 1/15th cost; Sonnet for analysis; Opus for user-facing prose.

Context Tiering

Three prompt sizes 15KB → 13KB → 10KB; mechanical tasks get minimal context.

Smart Guards

Short-entry skip (<10 words); metadata folded into the reflection pass; time-based insight caching.

06

Model Selection

The right model per task — paying for nuance only where the user can feel it.

TierModelPrice / 1M tokensUse cases
Mechanical Haiku $0.80 Labels, sorting, batch cleanup (simple output, no nuance)
Default Sonnet $3.00 Emotions, tags, insights, digests (quality at reasonable cost)
Interpretive Opus $5.00 Reflections, conversations (user-facing prose; quality = experience)

Typical session cost

$0.04
Reflection
$0.05
Conversation ×3
$0.001
Labels
~$0.09
Total
07

Evaluation Pipeline

Reflection quality is graded, not guessed — synthetic ground truth in, an LLM judge on a weighted rubric, results on a dashboard.

80 synthetic entries
8 categories · ground truth
Sonnet reflects
same prompt as production
Opus judges
5 weighted criteria
Results dashboard
pass rate · failure analysis

The rubric

CriterionWeightWhat it checks
Reflection Quality40%Depth, emotional truth, avoids summary (1–5).
Move Classification30%Toward vs away correctly identified.
Advice Check15%No disguised advice, no silver-lining.
Question Quality10%Deep and genuine, not solution-seeking.
Language Check5%No clinical terms, no "I" opener.
89.9% pass rate 71 / 79 entries · 0.83 average score.
08

Data Quality Over Time

AI-generated data gets messy. The system that cleans it matters as much as the one that creates it.

388 ThemesNear-duplicates collapsed via fuzzy matching.
9212 MovesCanonicalized with stemming + stop-word expansion.

Dedup pipeline

Fuzzy Matching

Detects near-duplicates even with different wording (≥50% word overlap).

Theme Dedup

Catches similar themes on creation; keeps the first name on merge.

Move Dedup

Checks overlapping behavioral patterns before creating new.

Practice Dedup

Double-gate: title AND description must match; works across values.

Design bias: false negatives over false positives. Better to miss a duplicate than wrongly merge two distinct patterns.

09

Closed-Loop System

Not just inference — user signal feeds back at every step, so each session calibrates the next.

AI Generates
reflections, moves, themes, practices, commitments
User Responds
"does this move fit?" · practice attempted · commitment kept / missed
System Learns
confirmed patterns weighted higher · working formulation updated · About You evolves
Next Session Better
more calibrated reflections · relevant practice check-ins · accurate pattern detection

Key mechanisms

Calibration Card

After each conversation; user confirms or rejects detected moves.

Practice Check-ins

AI probes active practices mid-conversation.

Auto-confirmation

Moves auto-confirm at 3+ supporting entries; user can override.

Attempt Detection

AI passively detects practice attempts in entries.

Usage Ledger

Per-task cost tracking · admin dashboard · global spend vs budget.

10

Production Rollout

Four layers of production safeguards are live and server-side; the rest is a clear-eyed map of what's next.

Built

Stripe payments · free/paid tiers · per-user spend caps · budget controls · usage tracking · admin dashboard.

Testing Gaps

Cheaper-model quality testing · expanded eval coverage · multi-provider edge cases · load testing.

Scale

AI-powered search for large journals · smarter caching per task type · faster prompt delivery · database scaling.

Compliance

Mental-health disclaimers · data-retention policy · HIPAA evaluation · terms + privacy (drafted).

Try it live.

Click "Try sample journal" to explore the whole system without signing up.