HybridNote AI: Project Story

About the Project

HybridNote AI ([https://web-app-3b030.web.app](https://web-app-3b030.web.app)) is a hybrid-intelligence note-taking and productivity web application built with React, TypeScript, and Vite, backed by five integrated Firebase services: Firebase AI Logic, Firebase App Check, Firebase Authentication, Cloud Firestore, and Firebase Remote Config. Instead of forcing every request through a remote server or locking features behind a single runtime, HybridNote AI pairs local on-device inference (Gemini Nano via Chrome's Prompt API) with cloud fallback (gemini-2.5-flash), tracks real-time execution latency, persists user notes per account in Firestore, and lets configuration parameters like inference_mode and system_prompt evolve dynamically through Remote Config.


What Inspired Me

Modern AI note tools often face a trade-off between privacy and latency on one side and model capability and availability on the other. Sending every draft note to a cloud endpoint adds network round-trip overhead and exposes sensitive text, while relying strictly on local browser models can fail on devices that lack model weights or browser support.

I wanted to build a practical productivity workspace where:

  • Routine transformations (summarizing, extracting action items, rewriting, or running custom instructions) can run locally on-device when available, or fall back seamlessly to gemini-2.5-flash in the cloud.
  • Sensitive notes can be guarded with a strict local-only mode so text is blocked rather than silently uploaded if on-device inference is unavailable.
  • Production security and configuration are treated as first-class engineering concerns rather than afterthoughts.

How I Built It

I structured the application around clean modular boundaries across configuration, AI orchestration, state synchronization, and cloud persistence:

  1. Gated Firebase Initialization (src/firebase.ts): Initialized app, appCheck, auth, db (with persistentLocalCache and persistentMultipleTabManager), remoteConfig, and ai (GoogleAIBackend), while validating required environment keys (isFirebaseConfigured and missingFirebaseKeys) and gating debug tokens behind import.meta.env.DEV.
  2. Hybrid Inference Engine (src/aiService.ts): Mapped configuration modes (ONLY_ON_DEVICE, PREFER_ON_DEVICE, PREFER_IN_CLOUD, ONLY_IN_CLOUD) to Firebase AI Logic InferenceMode values, passed inCloudParams and onDeviceParams (including expectedOutputs and system prompts), checked local LanguageModel availability for strict local-only requests, and measured execution latency in milliseconds.
  3. Authentication, Remote Config & Firestore Persistence: Connected Google Sign-In and guest sign-in flows (useAuth.ts), configured Remote Config defaults and live refresh intervals, and persisted generated notes under users/{uid}/notes backed by deployed firestore.rules and firebase.json Hosting rewrites and cache headers.

When evaluating routing and latency trade-offs between local execution and cloud fallback, total end-to-end latency $T_{\text{total}}$ can be modeled as:

$$T_{\text{total}} = T_{\text{prep}} + \mathbb{I}{\text{cloud}} \cdot (T{\text{net}} + T_{\text{appcheck}}) + T_{\text{infer}}$$

where $T_{\text{prep}}$ is prompt/input preparation time, $\mathbb{I}{\text{cloud}} \in {0, 1}$ indicates cloud execution, $T{\text{net}}$ is network round-trip time, $T_{\text{appcheck}}$ is App Check token retrieval/verification overhead, and $T_{\text{infer}}$ is model generation time.


What I Learned

  • Hybrid AI Requires Explicit Fallbacks: Designing for InferenceSource.ON_DEVICE versus InferenceSource.IN_CLOUD taught me how to handle browser capability differences gracefully—especially on public hosted origins where local model availability differs from local development environments.
  • Security Is a Distributed Handshake: App Check is not just a client flag; it requires alignment across the frontend bundle (VITE_RECAPTCHA_SITE_KEY), Google Cloud Fraud Defense (reCAPTCHA Enterprise domain allowlists and enabled APIs), Firebase App Check app configuration, and Firestore/AI enforcement.
  • Build & Cache Discipline Matters: Vite bakes VITE_* environment variables at build time, and browser caching rules in firebase.json (no-cache on /index.html versus immutable cache headers on hashed assets) directly affect whether users run fresh code after a deploy.

Challenges I Faced

  • App Check 400 & Throttling Loops in Production: Token exchange requests to exchangeRecaptchaEnterpriseToken hit 400 (Bad Request) (FAILED_PRECONDITION) and appCheck/throttled states when API enablement, site-key registration, and hosted domains weren't synchronized across Google Cloud, Firebase Console, and the built bundle—requiring careful inspection of DevTools responses, clearing browser storage to reset backoff timers, and rebuilding/redeploying Hosting.
  • Module Export & Type Mismatches During Rapid Iteration: Refactoring src/firebase.ts surfaced missing-export SyntaxError messages (appCheckErrorEventName, isFirebaseConfigured, missingFirebaseKeys) and event payload type mismatches (string | null vs. structured error objects) across useAuth.ts and App.tsx, which were resolved by aligning exports, types, and useEffect cleanup listeners.
  • Hosting CLI & Network Quirks: Deploying to web-app-3b030 required fixing hosting target configuration in firebase.json ("site": "web-app-3b030") and separating real application issues from external browser extension logs (enable_copy.js) and transient QUIC/network hiccups (ERR_QUIC_PROTOCOL_ERROR).

Built With

  • ai
  • chrome-prompt-api
  • cloud-firestore
  • css3
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-auth
  • firebase-hosting
  • firebase-remote-config
  • gemini-2.5-flash
  • gemini-nano
  • google-cloud
  • html5
  • hybrid-ai
  • javascript
  • on-device-ai
  • productivity
  • react
  • recaptcha-enterprise
  • tailwindcss
  • typescript
  • vite
  • web-app
Share this project:

Updates

Submission history