Architecture Review

The 20-Minute Hero

A GPS-based mobile RPG where real-world quests earn XP, level up your character, and pay out HERO tokens on-chain.

TypeScript React Native / Expo Hono v4 PostgreSQL + PostGIS Gemini 3 Flash BullMQ Firebase Auth Drizzle ORM

What is it?

Players create a Cyber-Fantasy character, walk outside, accept GPS-anchored quests (photo, video, text, multi-photo proofs), and get verified by AI + community voting. Completed quests earn XP β†’ levels β†’ HERO tokens. Tokens are real on-chain assets with a 2-phase economy: off-chain ledger first, ERC-20 bridge post-PMF.

πŸ—ΊοΈ

GPS Quest Discovery

PostGIS ST_DWithin query. Quests anchored to real locations within configurable radius.

πŸ€–

AI Proof Verification

Gemini 3 Flash with few-shot calibration. Photo/video/text. Per-category weights. Temperature 0.1.

πŸ—³οΈ

Community Voting

24–72h voting window. Social graph exclusion. Anti-gaming: voter level β‰₯3, daily XP cap, blind voting.

πŸ’Ž

HERO Token Economy

Off-chain ledger β†’ ERC-20. Earned by quests, spent in token_shop. B2B sponsored quests bypass app store tax.

βš”οΈ

8 Character Classes

Cyber-Fantasy "Neon & Mana" universe. Techno-Mag, Chrom-Paladin, Widmo-Biegacz, Bio-Szaman and 4 more.

🏰

Guilds & Seasons

Season pass (free + 200 HERO paid), weekly challenges, guild weekly objectives. Retention Day 1β†’60+.

Minimum Viable Product

Core Loop to Validate

Go outside β†’ accept GPS quest β†’ take photo β†’ AI verifies β†’ earn XP + HERO tokens.
Everything beyond this loop is post-PMF.

β†’ Full MVP specification (Doc 10)

14
working days
30
seed quests
7
screens
βœ… In MVP
ModuleDetail
Firebase AuthGoogle + Apple Sign-In
AI OnboardingAldric, 3–4 turns, class selection
GPS Quest DiscoveryPostGIS, 30 seeded templates
Photo Proof Uploadexpo-camera β†’ Cloudflare R2
AI VerificationGemini 3 Flash, few-shot Β§35
XP + HERO AwardBullMQ, idempotency_key
Push NotificationsQuest result via FCM/APNs
LeaderboardTop 20 weekly by XP
❌ Post-MVP
ModuleReason
Community VotingAI alone sufficient to validate
Guilds / SeasonsRetention β€” needs user base first
IAP / Token ShopMonetize after PMF
Sponsored QuestsRequires B2B sales motion
Social (follow/tips)Needs critical mass
UFS Fraud ScoringBasic rate limit ok for alpha
Video proofPhoto first, video sprint 2
AI Quest GenerationSeeded templates on alpha
Build Schedule
PhaseScopeDays
1 β€” SetupTurborepo, Hono skeleton, Drizzle + PostgreSQL/PostGIS, Docker Compose, Zod env config1
2 β€” Auth + CharacterFirebase middleware, auth endpoint, AI onboarding (Aldric), character creation2
3 β€” Quest SystemMigration subset, 30 seeded quest_templates, nearby endpoint (PostGIS), quest accept2
4 β€” Proof + AIPresigned URL (R2), proof submit, BullMQ verifyProof worker, Gemini few-shot, XP award (idempotent)2
5 β€” Push + LeaderboardFCM push (quest result), weekly leaderboard, character profile endpoint1
6 β€” MobileExpo setup, Auth, Onboarding chat, Map, Quest detail, Camera + upload, Proof status, Profile, Leaderboard4
7 β€” Deploy + QAVPS deploy, HTTPS, real device testing (GPS + camera), bugfixes, seed data2
Total~14 days

Architecture Overview

MonorepoTurborepo + pnpmapps/api, apps/mobile, packages/types
Backend APIHono v4 + TypeScriptZod validation, Firebase Bearer auth
DatabasePostgreSQL + PostGISDrizzle ORM, drizzle-kit migrations
QueueBullMQ + RedisProof verify, XP award, push, seasons
AIGemini 3 Flash@google/genai, responseSchema, Batch API
AuthFirebase AdminID token verify only, no custom JWT
MobileExpo (React Native)expo-router, Zustand, TanStack Query
Observabilitypino + PrometheusStructured logs, /metrics endpoint
TestingVitest + mswhono/testing testClient, faker-js

Key Architectural Choices

Firebase ID Token β€” no custom JWT

Backend verifies Firebase Bearer token directly. No refresh token table, no token rotation complexity. Firebase SDK auto-renews client-side.

Idempotency on all ledgers

Both xp_ledger and token_ledger have idempotency_key UNIQUE NOT NULL. BullMQ job retries can never double-award XP or HERO tokens.

Off-chain HERO tokens first

Phase 1: PostgreSQL token_ledger. Phase 2: ERC-20 bridge post-PMF. Avoids gas cost UX friction during growth phase.

Anti-fraud: UFS scoring

User Fraud Score 0–100. 11 weighted signals. 5 action tiers: monitoring β†’ review queue β†’ soft limits β†’ shadow_ban β†’ hard ban.

GPS anti-spoofing: 3 layers

Speed check (impossible travel), accuracy radius validation, temporal liveness challenge. PostGIS for all geo queries.

AI verification calibration

Few-shot anchor examples per category (photo/text/video). Temperature 0.1. responseMimeType JSON. Per-category confidence weights.

B2B Sponsored Quests

€200–500/quest. Brands pay directly (no app store). Quests marked is_sponsored, separate table. Avoids Apple/Google 30% cut.

Zero-vote outcome: rejected

Ghost proofs (no voters before deadline) default to rejected. Prevents token farming in low-traffic areas. Configurable per zero_vote_outcome.

Architecture Documents

10 documents, ~16 000 lines. Click to read full spec.

Doc 01

Overview & PostgreSQL Schema

Full DDL β€” Migrations 001/002/003. All tables, indexes, enums. Project structure (Turborepo). AI model decision with cost breakdown.

DDLPostgreSQLMigrations
Doc 02

REST API Endpoints

All endpoints with Zod schemas. Auth, onboarding, quests, proofs, voting, social, guilds, seasons, IAP, admin fraud queue, GDPR deletion.

HonoZodREST
Doc 03

AI Integration

Onboarding AI (Aldric, 2-turn fast-track), quest generation prompts, proof verification policy engine, avatar generation, Β§35 calibration.

GeminiFew-shotPrompts
Doc 04

Quest, Proof, XP & BullMQ

Quest discovery flow, upload URL generation, XP/leveling (idempotent), BullMQ workers, community voting with social graph exclusion, push notifications.

BullMQXPVoting
Doc 05

Config, Social & Monetization

Zod env config, all game_config values, social graph (follow/tips/reactions), guilds Β§11.6, seasons Β§11.7, weekly challenges Β§11.8, retention Β§11.9, monetization Β§10.

game_configIAPGuilds
Doc 06

Auth, Admin & Seed Data

Error handling (pino), weather service, admin panel, Vitest test suite, full seed data β€” token_shop catalog, showcase proofs Β§19.6 for cold start.

VitestSeedAdmin
Doc 07

Migrations, Deploy & Mobile

drizzle-kit migration files, Docker Compose setup, group quests (post-MVP), Expo mobile architecture Β§25 β€” screens, navigation, state, react-native-iap.

ExpoDockerDrizzle
Doc 08

Security & Moderation

Rate limiting, content moderation, GPS anti-spoofing Β§30, liveness Β§30.4, safety policy engine Β§31, UFS fraud scoring Β§34, GDPR deletion Β§33, Prometheus metrics Β§32.

SecurityAnti-fraudGDPR
Doc 09

Remediation Plan

P0–P3 priority backlog β€” stack issues already resolved, security gaps, remaining idempotency items, GPS spoofing hardening, auth simplification decisions.

P0BacklogFixes
Doc 10 β€” MVP

MVP Scope & Build Plan

What's in / out of MVP. DB subset, 30 seeded quests, 7 mobile screens. Phase-by-phase 14-day schedule. Definition of done checklist.

MVP14 daysRoadmap