Answer
SkyAlertsApp replaced Next.js, Vercel, and Neon Postgres 18 with one Flutter client backed by Firebase Hosting, Cloud Firestore (nam5), Firebase Auth, FCM, and 11 Python Cloud Functions.1
- One codebase across platforms: Flutter Web, iOS, and Android share instant splash rendering, on-device visibility math, 9 Solar System portraits, and OLED Red Night Mode.2
- One-read Firestore rollups: Nightly jobs pre-aggregate
rollups/overviewandrollups/trends_90dalongsideobjects/{objectId}, cutting dashboard startup from SQL joins to two document reads.34 - Bounded Gen-2 execution: Cloud Scheduler triggers Python 3.12 Gen-2 Functions with hard ingest caps (
360 sbudget,5pages per source,60enriched objects) inside the540 stimeout.56 - Same-origin Agent & Pro APIs: Firebase Hosting rewrites
/mcp,/api/**, and/webhooks/revenuecatto Python Gen-2 HTTP endpoints while browser WebMCP tools run in Dart.78
Applies toSkyAlertsAppcommit dbb2656Flutter + Firebase (skyalerts-app)
What changed from the legacy Next.js and Postgres stack?
Every major runtime layer moved from server-rendered Next.js on Vercel into client-rendered Flutter and Google Cloud serverless primitives under skyalerts-app. Only shared Python domain helpers in ingest/ and digest/ remained intact inside the new Gen-2 Functions bundle.
| Layer | Legacy Stack (web/) | Current Stack (app/ and functions/) |
|---|---|---|
| Client UI | Web onlyNext.js App Router (Web only) | Cross-platformFlutter 3 (Web, iOS, Android) |
| Edge & Hosting | Vercel Hosting + next.config.ts | Cloudflare + Firebase Hosting (app/build/web) |
| Primary Database | Pooled TCPNeon Postgres 18 (sql migrations) | Offline syncCloud Firestore nam5 (NoSQL + security rules) |
| Scheduled Ingest | Vercel Cron / scripts | Cloud Scheduler (512 MiB / 540 s Gen-2) |
| Auth & Admin | GitHub OAuth + HTTP cookie sessions | Anonymous-first Firebase Auth + Google/Apple + claim guard |
| Backyard & Push | Static views, no push channel | On-device visibility math + Open-Meteo + FCM pushes |
| AI & Automation | Static explainer HTML only | Browser WebMCP + /mcp + /api/v1/* + RevenueCat webhook |
How do Cloudflare, Firebase Hosting, Flutter, and Cloud Functions connect?
Diagram structure
- Flutter Web / Mobile
client - Cloudflare Edge
cf - Firebase Hosting
hosting - Firebase Auth
auth - Cloud Firestore nam5
db - Cloud Scheduler
sched - Daily Ingest Fn
ingestfn - Pro API & MCP Fn
apifn - FCM & Resend
push - ALeRCE / SkyBoT / JPL
astro - Open-Meteo / 7Timer
meteo client→cf· HTTPScf→hosting· Static & rewritesclient→auth· Sign in & linkclient→db· SDK queriesclient→meteo· 0.1-deg weatherhosting→apifn· "/mcp, /api, webhook"sched→ingestfn· UTC croningestfn→astro· Survey & ephemerisingestfn→db· Objects & rollupsingestfn→meteo· Clear-sky checkingestfn→push· Alerts & digestapifn→db· Keys & catalogapifn→meteo· Cloud cover
Cloudflare terminates TLS and caches immutable assets in front of Firebase Hosting, which serves the Flutter bundle and proxies dynamic API and webhook paths to Cloud Functions. Reads go directly from Flutter clients to Cloud Firestore under declarative Security Rules.910
- Flutter Web / Mobile
Boots via an instant
#app-splashshell, attaches WebMCP onnavigator.modelContext, and syncsentitlements/{uid}for Pro state. - Firebase Hosting
Applies global CSP (
'wasm-unsafe-eval'), COOP (same-origin-allow-popups), immutable asset caching, and rewrites/mcp,/api/**, and/webhooks/revenuecat. - Cloud Firestore nam5
Serves public
objectsandrollups, owner-scopedusers/{uid}andentitlements/{uid}, and server-onlyapi_keys/{keyHash}. - Daily Ingest Fn
Runs daily at
06:17 UTCinside540 sto fetch surveys, SkyBoT matches, bright targets, Horizons ephemerides, and Pro backyard notifications. - Pro API & MCP Fn
Authenticates
ska_live_...API keys or Firebase ID tokens via SHA-256 lookup before executing REST or MCP JSON-RPC 2.0 tools.
How does the daily pipeline stay inside the 540 s Gen-2 timeout?
Diagram structure
- 06:17 UTC Cron
cron - ALeRCE Streams
alerce - IMCCE SkyBoT
skybot - Bright & Comets
bright - JPL Horizons
hor - Save Rollups
rol - Dispatch Pushes
fcm alerce→skybot· Bounded batchbright→hor· Touch objectscron→alerce· Start runhor→rol· 9 bodiesrol→fcm· Readyskybot→bright· Matched SSOs
Cloud Functions Gen 2 caps HTTP and scheduled work at 540 s, so execute_daily_pipeline enforces a strict 360 s ingest budget before starting downstream stages. The remaining 180 s window handles asteroid identification, bright targets, JPL Horizons fetches, rollup writes, and FCM push fan-out.611
- 06:17 UTC Cron
Cloud Scheduler invokes
daily_ingest_and_identify(512 MiB,540 s) in UTC. - ALeRCE Streams
Pages LSST and ZTF candidates up to
5pages per source,60enriched objects, and360 stotal ingest budget. - IMCCE SkyBoT
Cross-matches unflagged moving detections against SkyBoT asteroid fields and attaches
ssometadata. - Bright & Comets
Ingests Rochester/TNS supernovae, JPL NEO Close Approaches, MPC comets, and evergreen variables for amateur apertures.
- JPL Horizons
Fetches nightly J2000 coordinates, V magnitudes, AU distances, and solar elongations for 9 outer dwarf planets and candidates.
- Save Rollups
Writes
rollups/overviewandrollups/trends_90dso app tabs load without collection scans. - Dispatch Pushes
Sends transient, bookmark, asteroid, and
entitlements-verified Pro clear-sky backyard alerts via FCM.
- Daily schedule
17 6 * * *UTC (512 MiB,540 stimeout)- Weekly digest schedule
23 14 * * 0UTC (256 MiB,180 stimeout)- Per-source page cap
max_pages_per_source = 5- Ingest time budget
time_budget_s = 360.0(leaves180 sheadroom)- Photometry enrichment cap
enrich_max_objects = 60per run
How is Cloud Firestore modeled and locked down by Security Rules?
Firestore separates public astronomy data from owner-scoped user state and server-only secrets across eight collections. Client apps never write catalog objects, Pro entitlements, or hashed API keys directly.1012
Diagram structure
- objects/{id}
objects - detail/enrichment
detail - rollups/{docId}
rollups - users/{uid}
users - users/{uid}/bookmarks
bookmarks - entitlements/{uid}
entitlements - api_keys/{keyHash}
api_keys - users/{uid}/api_keys
user_api_keys detail→objects· enrichesbookmarks→users· followsentitlements→users· Pro accessapi_keys→users· authenticatesuser_api_keys→users· lists
| Collection | Client Read | Client Write | Access & Schema Guardrail |
|---|---|---|---|
objects/{objectId} & detail | Public | Denied | Server Admin SDK only; 1 catalog doc + 1 enrichment doc |
rollups/{docId} | Public | Denied | Pre-aggregated overview and trends_90d |
users/{uid} | Owner only | Owner validated | Enforces allowed keys, min_confidence range, max 10 FCM tokens |
users/{uid}/bookmarks | Owner only | Owner validated | Enum survey check; immutable object_key and created_at |
users/{uid}/api_keys | Owner only | Denied | Non-secret metadata (prefix, label, revoked) |
entitlements/{uid} | Owner only | Denied | Synced only by revenuecat_webhook / Admin SDK |
api_keys/{keyHash} | Denied | Denied | SHA-256 lookup exclusively inside Cloud Functions |
admin_runs & audit_log | Admin claim / owner | Denied | Verified admin == true or verified owner email |
How do WebMCP, Remote MCP, and Pro API keys work with 0.1-degree privacy?
Browser AI agents call free read-only tools (skyalerts_get_tonight_targets, skyalerts_get_solar_system, skyalerts_search_catalog) registered on navigator.modelContext, while external MCP clients and scripts call Pro endpoints at /mcp and /api/v1/* through Firebase Hosting rewrites.87
Diagram structure
- AI / N.I.N.A. Client
agent - Firebase Hosting
hosting - skyalerts_api Fn
api - Cloud Firestore
db - Open-Meteo API
meteo agent→hosting· GET /mcp (or POST tools/list)hosting→api· Rewrite /mcp to Gen-2api→agent· Tool schemas + protocol 2025-03-26agent→hosting· POST /mcp tools/call + Bearer ska_live_...hosting→api· Forward request headers & bodyapi→db· Lookup api_keys/{sha256} & entitlements/{uid}db→api· Valid key + active Pro statusapi→meteo· GET cloud_cover at rounded lat/lon (0.1 deg)meteo→api· Hourly cloud cover %api→db· Read objects & rollups/overviewdb→api· Targets & ephemeridesapi→agent· Ranked J2000 JSON / N.I.N.A. CSV
What 11 Cloud Functions and deploy guardrails run in production?
All serverless work lives inside one functions/ codebase running Python 3.12 Gen-2 Functions with per-function memory and timeout isolation.513
| Function Name | Trigger | Memory / Timeout | Responsibility |
|---|---|---|---|
daily_ingest_and_identify | on_schedule (17 6 * * * UTC) | 512 MiB / 540 s | Ingests ALeRCE, SkyBoT, bright targets, Horizons, pushes |
weekly_digest_and_broadcast | on_schedule (23 14 * * 0 UTC) | 256 MiB / 180 s | Builds weekly dispatch markdown, audio script, email, FCM |
trigger_ingest | on_call (Admin + audit) | 512 MiB / 540 s | On-demand daily pipeline rerun for LSST/ZTF |
trigger_identify | on_call (Admin + audit) | 256 MiB / 180 s | Manual SkyBoT pass + rollup recompute |
preview_digest / send_digest | on_call (Admin + audit) | 256 MiB / 120–180 s | Dry-run preview or live Resend + FCM broadcast |
create_pro_api_key | on_call (Pro / Owner) | 256 MiB / 30 s | Issues salted ska_live_... key; stores SHA-256 hash |
list_pro_api_keys / revoke_pro_api_key | on_call (Signed-in user) | 256 MiB / 30 s | Lists non-secret key metadata or revokes immediately |
skyalerts_api | on_request (/mcp, /api/**) | 512 MiB / 60 s | Serves /api/v1/health, REST JSON, and Streamable MCP |
revenuecat_webhook | on_request (/webhooks/revenuecat) | 256 MiB / 30 s | Syncs RevenueCat billing events into entitlements/{uid} |