# HelloZ: social-dating app on Flutter and Firebase

> I built this social-dating product end to end: a Flutter app, serverless TypeScript on Firebase, 30+ Firestore collections with security rules, real-time presence, push and Play Billing.

URL: https://thuyavan.netlify.app/projects/helloz-social-app
Updated: 2026-10-12

- Role: End to end: app, serverless back end, rules, billing
- Period: 2025-09 → 2026-06
- Technologies: Flutter, Dart, BLoC, Firebase, TypeScript, Push (OneSignal / FCM), React

## Executive Summary

HelloZ is a full-stack social-dating product the owner built end to end:

a Flutter app (Clean Architecture per feature, BLoC, get_it, go_router)

Firebase Cloud Functions v2 in TypeScript (Node 22, Zod validation, layered controllers / application / infrastructure)

Cloud Firestore (30+ collections with security rules and indexes)

Realtime Database for presence and typing

Firebase Storage for media

OneSignal / FCM push notifications

Google Play Billing subscriptions (in_app_purchase + server verification)

a React 18 + Vite + Tailwind web app for the anonymous “crush” inbox

Features shipped:

Auth: Google, email/password, Auth0 passwordless OTP, with server-side identity linking (auth_index, users_index)

2-step profile creation with image compression and upload

Social posts: text / image / poll, likes, comments with reactions, shares, saves, delete; paged feeds

follow graph, user profile hub, about pages

Discover (filters, swipe-style profiles)

1-to-1 chat with replies, forwards, mentions and images on flutter_chat_ui

Random anonymous chat: anonymous profiles, matchmaking by gender, recency and online status, favourites

Crush chat: anonymous messages to a user’s public crush handle, with send / handle rate limits, warn-sender moderation, mute, stats, and a web inbox

Premium: day / month tiers, ad-free, badge, quotas

Mega posts: premium high-visibility posts with expiry and per-period quota

developer tools for seeding emulator data

The owner treated the project as an engineering case study: dozens of docs analyse Firestore read/write cost per feature, ID consistency (authUid vs fsUserId), security bugs, notification delays and UI bugs before fixing them.

## Portfolio Blurb + Resume Bullets

Blurb:

Designed and built HelloZ, a social-dating app: Flutter (Clean Architecture, BLoC, go_router) on Firebase (Auth, Firestore, RTDB presence, Storage, Cloud Functions in TypeScript with Zod), OneSignal push, Google Play subscriptions and a React web inbox. Features include social posts and polls, follows, discovery, real-time chat, anonymous random-match chat, anonymous “crush” messaging with rate limiting and moderation, and premium “mega posts” with quotas. Documented in 88 design and cost-analysis docs.

Bullets:

Architected a Flutter + Firebase monorepo (app, functions, web, test app) with Clean Architecture per feature (20+ feature modules, ~58k LOC) and 48 HTTPS Cloud Functions plus Firestore triggers.

Implemented hybrid authentication (Google, email/password, Auth0 OTP verified with jose JWKS) and a server-side identity-linking model (auth_index / users_index) separating the Auth UID from the profile id; audited and fixed ID-consistency and security bugs (e.g. an unauthenticated createProfile).

Built social features: posts (text / image / poll), likes, comment reactions, poll votes, shares, saves, follow graph, paged feeds, using transactions and counters designed via written Firestore cost analyses (likes, follows, saves, about).

Built real-time chat on flutter_chat_ui (replies, forwards, mentions, images, seen receipts) with RTDB presence / typing and Firestore-trigger notifications (FCM + OneSignal external-id targeting).

Designed random anonymous chat: anonymous profiles and photos, matchmaking (searchable + online within a window + gender preference, sampled candidates), anonymous chat creation with reverse indexes, favourites, seen markers.

Designed anonymous crush messaging: public crush handles, sender / handle rate-limit collections, sender anonymity via indexes, warn / withdraw / mute moderation, stats; plus a React 18 + TanStack Query + Zustand + Tailwind web inbox with FCM web push.

Implemented Google Play subscriptions (in_app_purchase) with server verification records, purchase history, and premium-gated mega posts with transactional per-period quotas, expiry, and country/language filtering.

Built emulator seed tooling (≈ 4k lines of seed scripts: users, follows, chats, anon chats, discover profiles, mega posts, subscriptions) and a developer console screen.

Ran an AI-assisted engineering workflow: Codex agent branches → reviewed PRs (Phase 1); design-doc-first development with LLM pairing (Phase 2).

## Business Domain

Module
Concept

Identity
Firebase Auth user (authUid) ↔ Firestore profile (users/{fsUserId}), via auth_index/{authUid} and users_index/{emailNorm}; unique usernames/{username}

Profile
Unique ID (a-z 0-9 _), DOB, gender, country / city, photos, bio, about

Timeline
Posts from follows + engagement; ads every 5 posts (planned)

Interactions
Like, comment (+ reactions), poll vote, share, save

Discover
Filters (country, city, gender, age, language, online) and swipeable profiles

Chat
1:1 chats with messages, media, replies / forwards / mentions, presence, typing

Random chat
Anonymous persona (anonymous_users), random match, anonymous chats, favourites

Crush chat
Public handle → anonymous messages; inbox / sent / received / threads; rate limits; warn sender; mute; stats; web inbox

Premium
Subscriptions Day ($1) / Month ($10) [requirement]; benefits: ad-free, ghost watch, premier badge

Mega posts
Paid / premium high-visibility posts with expiry; quota per period (day tier 1, month tier 5)

## Technology Stack

6.1 Flutter app (app/pubspec.yaml)

Package
Version
Use

firebase_core, firebase_auth, cloud_firestore, firebase_storage, firebase_messaging, firebase_database, firebase_analytics, firebase_remote_config, cloud_functions
2.30 / 4.19 / 4.17 / 11.7 / 14.7 / 10.4 / 10.10 / 4.4 / 4.6
Full Firebase suite (RTDB for presence / typing; Remote Config for flags)

google_sign_in
^6.2.1
Google auth

flutter_bloc, equatable, formz
^8.1.4 / ^2.0.5 / ^0.5.0
State + form validation

go_router
^13.2.2
Navigation (app_routes.dart, 385 lines)

get_it
^7.7.0
DI (di.dart, 555 lines)

provider
^6.0.0
Supplementary state

dio
^5.0.3
http_client.dart (355 lines: auth headers, masked logging) for Cloud Functions HTTPS

image_picker, flutter_image_compress, path_provider, cached_network_image
—
Media pick, compress, cache

flutter_chat_ui ^2.0.0, flutter_chat_core ^2.0.0, flyer_chat_image_message ^2.3.0, cross_cache ^1.0.0
—
Chat UI framework (v2)

hive, hive_flutter
^2.2.3 / ^1.1.0
Local cache

onesignal_flutter
^5.3.5
Push (external-id mapping)

flutter_local_notifications
^17.2.2
Foreground notifications

in_app_purchase (+ _android ^0.3.6+3)
^3.2.0
Google Play subscriptions (billing_service.dart)

pin_code_fields
^8.0.0
OTP input

flutter_countdown_timer
^4.1.0
OTP / quota timers

connectivity_plus, shared_preferences, intl, flutter_localizations, logger
—
Utilities, i18n

Dev
bloc_test ^9.1.5, mockito ^5.4.4, build_runner, flutter_lints
Testing infrastructure

Dart SDK >=3.5.0 <4.0.0.

6.2 Cloud Functions (backend/functions/package.json)

Node 22; firebase-functions ^6.4.0 (v2 onRequest, Firestore triggers), firebase-admin ^13.4.0, zod ^3.25 (DTO validation), jose ^5.10 (Auth0 JWT verification), busboy ^1.6 (multipart photo uploads), dotenv ^17. Root dev tools: concurrently, wait-on (emulator + seed orchestration).

6.3 Web (web/)

React 18.3, react-router-dom 6.26, firebase 10.13 (Auth + FCM web push), @tanstack/react-query 5.51, zustand 4.5, framer-motion 11, zod 3.23, axios, date-fns, lucide-react, clsx + tailwind-merge, Tailwind CSS, Vite, TypeScript.

6.4 Infrastructure

Firebase Local Emulator Suite (Auth, Firestore, Functions, Storage, RTDB) with exported snapshots (firebase-export-*, seed-snapshot) to restore seeded states; Secret Manager config (config/secrets.ts, env.ts); Google Play Developer API (planned via googleapis for production verification).

## Architecture

7.1 Flutter app

app/lib/
├─ main.dart (146) · config/{di.dart (555), app_routes.dart (385), app_config.dart (121)}
├─ services/{http_client.dart, billing_service.dart}
├─ infrastructure/cloud_functions/ (1.5k) # typed callers for every HTTPS function
├─ core/{widgets (1.4k), paged_list, validators}
├─ features/ # each: data / domain / presentation (BLoC)
│ ├─ auth (2.7k) · profile_creation (3.0k) · profile · profile_hub (1.2k) · user_profile · user_about
│ ├─ home · navigation · post (5.7k) · saved_post · follow
│ ├─ discover (3.0k)
│ ├─ chat (7.0k) · chat_v1 (2.7k, previous implementation)
│ ├─ random_chat (3.9k) · crush_chat (3.1k)
│ ├─ premium (1.4k) · mega_posts (4.2k)
│ └─ developer (2.0k: seed / test tools)
└─ ui/ NN_*_code # reference UI screen samples (design prototypes per requirement number)

Conventions are documented (barrel_import_pattern.md, module_creation_guide, development_rules.md, reusable_widgets.md, ui_design_guide.md, ui_inventory.md).

7.2 Cloud Functions: layered (hexagonal-ish)

functions/src/
├─ index.ts # exports 48 HTTPS functions + 3 Firestore triggers
├─ interfaces/http/ # controllers: auth, profile, post, follow, chat, chat_notifications,
│ # random_chat (+ notifications), crush_chat (+ notifications), mega_post, premium, dev
│ └─ dto/ # Zod schemas: auth, profile, post, follow, random_chat, crush_chat, mega_post, premium
├─ application/ # createOrLinkUser (195), normalizeEmail, normalizeUsername, policies
├─ domain/ # user, provider types
├─ infrastructure/ # firebase admin, firestore repositories (190), auth (verifyFirebaseAuth, auth0Jwt via jose), logging
├─ config/ (env, secrets) · shared/ (errors, result)
└─ scripts/ # seedEmulator (1,954), seedFollows, seedDiscoverProfiles, seedMegaPosts, seedPremiumSubscriptions,
 # seedRandomChats, seedConfig, migrateAuthId

7.3 Data stores

Firestore collections (from rules): users (+ followers, following, savedPosts sub-collections), auth_index, users_index, posts (+ likes, poll_votes, comments, post_shares), chats / messages, anonymous_users, anonymous_chats, anon_chat_index, anon_reverse_index, crush_chats, crush_inboxes, crush_index, crush_reverse_index, crush_sender_index, crush_handle_index, crush_handle_rates, crush_send_rates, crush_stats, mega_posts, subscriptions, purchase_tokens, purchase_history.

RTDB: presence/{fs_<userId> | anon_<anonId>} (write allowed only for the caller’s own resolved id) and typing/{chatId}/{key}.

Storage: profile photos, post media, anon photos (rules in storage.rules).

## System Diagrams

8.1 Context

8.2 Identity linking

8.3 Random match

8.4 Mega-post quota

8.5 Chat notification

onChatMessageCreated / onAnonChatMessageCreated / onCrushMessageCreated (Firestore onDocumentCreated triggers) → resolve recipient → skip if muted or online (presence) → send FCM (registered token via registerFcmToken) and / or OneSignal (external id = fsUserId) → deep link payload. The delay analysis led to sending server-side immediately and adding “notification modes” (docs 06-05 / 06-06).

## Screens / Modules Inventory

Module
Screens (representative)

Auth
Welcome, Google sign-in, email/password login, password setup, OTP (pin code), email verification

Profile creation
Step 1 (username with live check, display name, DOB, gender), Step 2 (details: country / city, about, photos), image crop / compress

Navigation
Splash, bottom nav shell (home, discover, chat, profile), back-button handling

Home / Post
Feed (paged), create post (text / image / poll), post detail, comments (reactions), share, delete, save

Profile
Profile hub (stats, tabs: posts, saved, mega), user profile, user about, follow lists

Discover
Filters, swipeable profiles, trending

Chat
Chat list, conversation (flutter_chat_ui: reply, forward, mention, images, seen), presence / typing

Random chat
Anon profile setup / photo, find match, anon chat list / room, favourites

Crush chat
My crush handle / inbox, send crush, received / sent, thread, warn / withdraw / mute, stats

Premium
Subscription tiers (day / month), purchase, status, history

Mega posts
Mega feed (country / language filter), create / edit, my mega posts, quota display, likes

Developer
Seed chats / anon chats / mega posts, grant premium, send test notification

Web
Home, Crush profile page (send to handle), Crush room, Inbox, 404

Plus ui/NN_*_code reference screens (welcome & auth, profile creation, home timeline, user profile, chat list / interface, post interactions, swipeable profile, mega section, subscription tiers).

## Features — complete list

Auth (Google / email / Auth0 OTP) · identity linking · username check · email check / verify · profile create (2 steps) · photo upload (busboy) · posts (text / image / poll) · like · comment · comment reactions · poll vote · share · delete post / comment · save / unsave · follow / unfollow · followers / following lists · profile hub · about · discover · chat 1:1 (reply / forward / mention / images / seen) · presence · typing · FCM token registration · chat notifications · random anon chat (profile, photo, match, create chat, favourite, seen) · anon notifications · crush (inbox, handle resolve, send, received / sent / thread, warn / withdraw, mute, seen, stats) · crush notifications · crush web inbox · premium subscriptions (verify, status, history) · mega posts (create, edit, like, feed, mine, quota) · dev seeding / test tools · emulator snapshots.

## Cloud Functions catalogue (48 HTTPS + triggers)

Auth / profile: authCheckEmail, authCreateOrLinkUser, checkUsername, createProfile, authVerifyEmail, getUserAbout.
Posts: createPost, togglePostLike, addComment, toggleCommentReaction, votePoll, sharePost, deletePost, deleteComment, savePost, unsavePost.
Follow: followUser, unfollowUser.
Chat: registerFcmToken; triggers onChatMessageCreated.
Random chat: getAnonProfile, updateAnonProfile, uploadAnonPhoto, findRandomMatch, createAnonChat, toggleAnonFavorite, markAnonMessagesSeen; trigger onAnonChatMessageCreated.
Crush chat: getMyCrushInbox, updateCrushInbox, resolveCrushHandle, sendCrushMessage, getReceivedCrushes, getSentCrushes, getCrushThread, warnSender, withdrawWarning, muteCrushConversation, markCrushSeen, getMyCrushStats; trigger onCrushMessageCreated.
Mega posts: createMegaPost, editMegaPost, toggleMegaPostLike, getMegaPosts, getMyMegaPosts, getMegaPostQuota.
Premium: verifySubscriptionPurchase, getSubscriptionStatus, getPurchaseHistory.
Dev: devSeedChatsForUser, devSeedAnonChatsForUser, devSendTestNotification, devGrantPremiumForUser, devSeedMegaPostsForUser; helloWorld.

## Data & Cost Engineering

The owner wrote schema cost analyses before implementing: feed likes (read amplification per feed page vs a denormalised likedBy sub-collection check), follow schema (sub-collection pairs + counters), saved posts (users/{id}/savedPosts vs a global collection), user about (embedded vs separate doc). Decisions favour sub-collections + transactional counters and avoid unbounded array fields. Reverse indexes (anon_reverse_index, crush_reverse_index, crush_sender_index) support anonymous lookups without exposing identities to clients.

## Security

Firestore rules per collection; RTDB presence writes restricted to the caller’s own resolved key (via auth_index / anon_chat_index lookups inside the rules).

All mutating operations go through Functions with ID-token verification; Zod validation; policies module.

The documented audit found and planned fixes for: createProfile without verifyAuth (overwrite risk), authorId stored as authUid vs fsUserId inconsistencies (posts / comments / follows), and seed scripts not writing auth_index (doc 2026-05-27).

Anonymity: crush senders and anon users are mapped through server-only indexes; rate-limit collections (crush_send_rates, crush_handle_rates) throttle abuse; warn / mute moderation.

Secrets in Secret Manager / env; credential files kept out of docs.

## Payments

in_app_purchase (Google Play) → purchase token → verifySubscriptionPurchase (stores purchase_tokens, upserts subscriptions/{fsUserId} with tier, period end and reset quota fields, appends purchase_history). Production verification via the Google Play Developer API (googleapis + service account) is designed but stubbed for test [V comments]. Mega posts consume the subscription quota.

## Notifications

FCM tokens registered server-side; OneSignal with external id = fsUserId (doc “onesignal_external_id_user_flow”); delay root cause and fix doc; local notifications in the foreground; web push in the React app (lib/messaging.ts, useNotifications).

## Realtime

Firestore snapshots for chats, messages and feeds; RTDB presence (fs_ / anon_ keys, onDisconnect) and typing indicators.

## Testing & Tooling

bloc_test + mockito set up; test_app/ (1.7k LOC) for isolated experiments; a developer feature in the app plus dev Functions; emulator exports for repeatable states; testing plans in docs (mega posts / premium testing plan).

## UI / UX

Design guide and inventory docs; reusable widget catalogue; flutter_chat_ui v2 for chat UX; swipeable discover cards; premium badges; quota indicators; Lottie-free, Material-based custom widgets; web uses Tailwind + framer-motion.

## Reusable Components

core/widgets (1.4k), core/paged_list (generic Firestore paging), core/validators, typed infrastructure/cloud_functions callers, http_client with masked logs, billing_service; backend repositories.ts, policies.ts, Zod DTO pattern, notification helpers per chat type, seed framework.

## Algorithms

Random matching (filtered candidate sampling with a recency cutoff), transactional quota windows (reset on period end), over-fetch ×3 + in-memory filtering for country / language on mega posts (a Firestore query-limit workaround), identity resolution caching per session, rate limiting by counters per time window.

## New / Notable Skills

Firebase at full depth (rules, triggers, RTDB presence, emulators, snapshots), serverless TypeScript with Zod, Auth0 + Firebase identity federation, Firestore data modelling for cost, anonymous-messaging system design, Play Billing, OneSignal, React Query / Zustand, AI-agent-assisted development with PR review.

## Challenges & Solutions

Challenge
Solution

authUid ≠ profile id for real users
auth_index resolution; audit of every write path; seed fixes

Unauthenticated profile overwrite
verifyAuth + ownership check (planned / fixed)

Notification delays
Server-side trigger sends, mode handling, external-id targeting

Chat first-entry / alignment bugs
Documented root causes and fixes (06-07 / 06-08)

Firestore cost of likes / follows
Schema analyses → sub-collections + counters

Anonymous abuse
Rate-limit collections, warn / mute

Quota race conditions
Transaction re-check
