MB
← All case studies
04Full-stack product · AI in production

An AI verdict loop you can actually defend

Photo proof → Claude → confidence-tiered rewards, with one appeal and a peer majority vote when the model says no — every rationale persisted for audit.

Next.js 14tRPC v11PrismaNextAuth v5Claude APIRedisExpo
Private – available on request for verified hiring partners

44

tRPC procedures, one auth gate

15

Prisma models · 27 indexes

4

Bearer-protected cron endpoints

3

tiers: ×1.0 · ×0.6 · ×0.0

The problem

Most products 'add AI' by pasting a model response into the UI. When it's wrong, users hit a wall: no appeal, no record, no way to prove the decision was fair — and the team can't answer basic questions about what the model actually did.

The second problem is economic. In a gamified product, if rewards are generous and verification is weak, the economy gets gamed in week one.

The approach

The verdict is a data structure, not a string

Proof submissions go to Claude with goal context and a strict JSON contract: confidence, verified, rejectionReason, rationale — all persisted on the row. XP payout scales with the model's confidence (≥75 → ×1.0, 45–74 → ×0.6, <45 → ×0.0), so the economy pays for certainty, not for optimism.

When the AI layer fails, the product doesn't: any exception returns a defined fallback verdict (confidence 50, verified false, 0.6 multiplier) with a clear reason. A model outage degrades rewards; it never 500s a user's submission.

When the model says no, a human path opens

Rejection starts an escalation ladder: exactly one resubmission, then a peer review request that assigns three friends at random (excluding anyone already assigned). Self-review is blocked, assignment is checked, double-votes are rejected, and majority math (ceil of assigned/2) finalizes early once a side has the votes.

A verified peer verdict routes into the identical XP pipeline — one payout path, two verification sources, and an append-only verdict trail in the database.

The economy is a pure function

Payouts are deterministic math: base × difficulty × verification tier × time bonus × circumstances modifier (a six-axis modifier clamped 0.3–1.5), with a level curve of floor(150 · n^1.85). Tuning the product's generosity means changing constants, not controllers.

The plumbing that decides whether AI survives real traffic

Four Vercel cron endpoints (task seeding, rollover + challenges, leaderboard recompute, daily coaching insights) each enforce a Bearer CRON_SECRET before doing work. Redis handles cache-aside leaderboards with TTLs and sorted-set global rankings; uploads land in per-user Cloudinary folders behind a session gate; CSP allow-lists the exact origins the app talks to, including the Anthropic API.

One typed API serves both clients: 44 procedures behind a single protectedProcedure, with the router types exported to an Expo app so backend changes break the build, not production.

Architecture

  photo proof -> Cloudinary -> Claude Sonnet 4 -> {confidence, verified, rationale}
        | persist
  rejection -> 1 resubmission -> 3-peer majority vote (append-only trail)
        |
        v
  base × difficulty × tier × time × circumstances -> XP ledger
        |
        v
  level-ups · streaks · milestones · achievements
        |
  cron endpoints (Bearer) · Redis caches · leaderboard sets

One payout path, two verification sources, every verdict auditable.

Outcomes

  • ✓An AI decision loop that can be defended in a review: every verdict carries a persisted rationale and a route for appeal
  • ✓Product economics are tunable constants with a single deterministic payout function
  • ✓Operational plumbing ships in v1: protected crons, caching, signed uploads, CSP hardening, auth with bcrypt cost 12
  • ✓End-to-end type safety from database to web and mobile clients through one tRPC contract
  • ✓6,209 lines of app source behind a CI gate that runs lint + typecheck on every push

What I learned

  • →Auditable AI: every verdict needs a persisted rationale and an appeal path to earn trust in production.
  • →Deterministic economics (pure functions) make product tuning safe and testable.
  • →Defense-in-depth for crons, auth, and uploads prevents operational drift in real products.

Scope, honestly

The part most portfolios leave out. Here is exactly what is shipped today, and what is designed but not yet wired — read the repo and check me on it.

Shipped & verified

  • ·AI verification, confidence-tiered XP, escalation ladder (resubmission + peer majority) — live in the API
  • ·Goals, auto-scheduled tasks, streaks, challenges, achievements, analytics, friend graph
  • ·4 protected cron endpoints, Redis leaderboards, Cloudinary uploads, dynamic OG images
  • ·Expo mobile client sharing the same typed router

Designed · next

  • ·The test suite is greenfield — CI gates lint + typecheck, and the pure XP/streak engines are the obvious first targets
  • ·Peer review and appeal endpoints exist in the API but aren't surfaced in the web UI yet
  • ·Mobile auth (Bearer vs cookie session) needs wiring before the app ships to stores

Next case study

A content factory that runs on free tiers

01 →

Start a project

Have a system that should run itself?

Tell me what breaks today — the manual loop, the API bill, the scraper that dies overnight — and I'll tell you what I'd build, what it costs, and what I wouldn't bother automating.