StudyAI
Real-time AI homework assistant with photo OCR, multi-tool writing helpers, code explanation and a streaming chat — freemium with hard paywall after 6 messages per 12 hours.
StudyAI gives students a single home for AI help: snap a homework photo and get it solved, draft an essay with style/tone/audience controls, summarize a chapter, translate a passage, explain code, or just chat. Responses stream token-by-token via OpenAI; the last five messages stay in context so follow-ups feel coherent.
Built as a production-grade freemium SaaS — daily quotas, server-side A/B testing of model and token limits via Firebase Remote Config, two analytics pipelines, and Superwall paywall flows. The codebase reflects the kind of revenue-conscious decisions that made it acquirable.
dart_openaiClean separation between view, view model and model. Persistence is offline-first via Hive, with Firestore syncing chats async. Remote Config gates model name, token limits and paywall behavior so monetization can be tuned without an app release.
lib/
├── view/ Pages + routing
├── view_model/ BLoC layers
│ ├── chat_bloc/ Streams OpenAI responses, manages 5-message history
│ ├── camera_bloc/ Permission, capture, scan state
│ ├── user_bloc/ Firebase Auth
│ ├── task_bloc/ Tool selection (Draft, Improve, Summarize, etc.)
│ └── history_bloc/ Hive-backed chat list
└── model/
├── repositories/ ChatRepository, UserRepository, PurchaseController
├── services/ OpenaiRequest, MessageManager, RemoteConfigService
├── theme/
└── helpers/
functions/ OpenAI proxy + secure key handling
Scan & Solve
Camera → image crop → Base64 encode → multimodal message to gpt-4o vision with a "solve this homework" system prompt.
Multi-tool writing
Draft / Improve / Summarize / Language / Learn / Code each load a custom system prompt with style, tone and audience parameters.
Streaming responses
Real-time token streaming; ChatBloc emits incremental states so the UI rebuilds word-by-word.
Daily quotas
MessageManager tracks request count and resets at noon; free users capped at 6 per 12 h.
Premium tiers
Superwall paywall gates to active subscription; RevenueCat syncs entitlements from App Store / Play Store on purchase.
Server-side model routing
Remote Config switches free vs. premium model and token limits per platform — no release required.
- 01
Pick a tool
User taps "Draft" → TaskInputPage. Selects style, tone and audience.
- 02
Quota gate
MessageManager checks today's count. If <6, proceed; else Superwall presents the pricing sheet.
- 03
Build prompt
ChatBloc creates a SystemMessage from task parameters, appends 5-message history, calls
OpenAI.instance.chat.createStream(). - 04
Stream into UI
Each
delta.contentchunk updates the in-progress ChatMessage. ChatPage rebuilds on every state emit. - 05
Persist
On stream complete, message persisted to Hive locally and Firestore via ChatRepository for cross-device.
Dual-mode token budgeting
Max tokens vary by platform (iOS 700 free / Android 600) and message count — diminishing returns past 5 requests prevents abuse.
Multimodal images inline
Photos are sent as Base64 data URLs in the same OpenAI message as the user prompt — no separate upload, no orphan storage.
Remote Config-driven monetization
Model name, token limits and paywall variants tune without a release — critical for iterating freemium funnels.
Two analytics pipelines
Firebase + AppsFlyer instrumented in parallel to measure both conversion and ad-network attribution (SKAdNetwork on iOS).
In-app review trigger
Triggers the App Store / Play Store rating dialog after the third successful message — when the user is most engaged.
Hidden prompt-engineering field
Each ChatMessage carries a hidedMessage appended to prompts at request time — quick lever for A/B-testing system instructions.
Decisions that made the funnel work — and what each cost.
Streaming over batch responses
Token-by-token streaming makes the app feel premium and keeps users engaged past the first 2 seconds. Cost: mid-stream errors are harder to retry cleanly than a full re-request would be.
Hard 6/12 h paywall over soft
A hard wall converts better than a "you've used X% of your free tier" nag. Cost: some early-funnel users churn before they hit the wall, which a soft model would have nurtured.
Remote Config-driven model routing
Tunable monetization without an app release — A/B model and token caps server-side. Cost: free-tier users on jailbroken devices can spoof the platform value to access premium routes; revenue-side risk traded for iteration speed.
Hive + Firestore dual persistence
Offline-first means a dropped connection never loses a chat. Cost: cross-device sync needs explicit conflict resolution; Hive is treated as source of truth, Firestore as backup.
- 6 requests per 12 hours
- gpt-4o-mini routing
- Banner + interstitial ads
- 5-message context window
- Unlimited requests
- Better model (gpt-4o or gpt-3.5-turbo)
- No ads
- Higher token caps
Outcome: built solo, end-to-end, then acquired. Production-grade revenue infra (RevenueCat + Superwall + Remote Config), dual analytics for measurable acquisition, and a freemium funnel that survived contact with real users.
A consumer SaaS funnel runs on the same infrastructure as enterprise tenant management.
Remote Config-driven model routing is structurally identical to multi-tenant Mendix configuration — toggling behavior per environment without redeployment. Daily quota enforcement is the same primitive as enterprise license metering and rate-limited API access. Offline-first Hive persistence with async Firestore sync is the same pattern field-worker mobile apps need for warehouse, inspection and maritime workflows where connectivity is unreliable.