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-flashin 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:
- Gated Firebase Initialization (
src/firebase.ts): Initializedapp,appCheck,auth,db(withpersistentLocalCacheandpersistentMultipleTabManager),remoteConfig, andai(GoogleAIBackend), while validating required environment keys (isFirebaseConfiguredandmissingFirebaseKeys) and gating debug tokens behindimport.meta.env.DEV. - Hybrid Inference Engine (
src/aiService.ts): Mapped configuration modes (ONLY_ON_DEVICE,PREFER_ON_DEVICE,PREFER_IN_CLOUD,ONLY_IN_CLOUD) to Firebase AI LogicInferenceModevalues, passedinCloudParamsandonDeviceParams(includingexpectedOutputsand system prompts), checked localLanguageModelavailability for strict local-only requests, and measured execution latency in milliseconds. - 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 underusers/{uid}/notesbacked by deployedfirestore.rulesandfirebase.jsonHosting 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_DEVICEversusInferenceSource.IN_CLOUDtaught 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 infirebase.json(no-cacheon/index.htmlversus 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 toexchangeRecaptchaEnterpriseTokenhit400 (Bad Request)(FAILED_PRECONDITION) andappCheck/throttledstates 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.tssurfaced missing-exportSyntaxErrormessages (appCheckErrorEventName,isFirebaseConfigured,missingFirebaseKeys) and event payload type mismatches (string | nullvs. structured error objects) acrossuseAuth.tsandApp.tsx, which were resolved by aligning exports, types, anduseEffectcleanup listeners. - Hosting CLI & Network Quirks: Deploying to
web-app-3b030required fixing hosting target configuration infirebase.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