Security-first implementation for the Gen AI Academy APAC Ideathon.
Browser โ Firebase Authentication โ Firebase ID token โ Cloud Run API โ Google Secret Manager โ Gemini API
Browser โ Firebase Authentication โ Cloud Firestore (owner-only rules)
- Firebase/Google Authentication client
- Authenticated multi-turn Gemini endpoint
- Firestore persistence under
users/{uid}/journals - Server-side Gemini API key retrieval from Secret Manager
- Original Insight Loop: Gemini creates a structured summary, insights, and next actions
- Firestore owner-isolation rules
- Docker/Cloud Run deployment configuration
- Firebase Hosting configuration
- Create a Firebase project and register a Web App.
- Enable Firebase Authentication โ Google provider.
- Create Cloud Firestore in production mode.
- Deploy
firestore.rules. - Enable the required Gemini API/Google AI service for the project.
- Create Secret Manager secret
GEMINI_API_KEYcontaining the Gemini API key. Never put this value in GitHub or browser code. - Grant the Cloud Run runtime service account Secret Manager Secret Accessor access to that secret.
- Set
GOOGLE_CLOUD_PROJECTon the backend. - Populate the browser Firebase values from
.env.exampleas environment variables during the frontend build.
npm install
cp .env.example .env
npm run devRun the API separately with Google Application Default Credentials:
gcloud auth application-default login
npm run serverBuild and deploy the SPA to Firebase Hosting:
npm run build
firebase deploy --only hostingDeploy Firestore rules:
firebase deploy --only firestore:rulesBuild and deploy the API to Cloud Run:
gcloud builds submit --tag REGION-docker.pkg.dev/PROJECT_ID/journal/api
gcloud run deploy personal-gemini-journal-api --image REGION-docker.pkg.dev/PROJECT_ID/journal/api --region REGION --set-env-vars GOOGLE_CLOUD_PROJECT=PROJECT_IDThen set VITE_API_URL to the Cloud Run HTTPS URL, rebuild the frontend, and redeploy Hosting.
Firebase Hosting provides CDN-backed HTTPS hosting for static/SPAs, while Cloud Run provides the trusted server boundary for Gemini and Secret Manager. Firebase App Hosting is another option for supported full-stack frameworks and GitHub-connected rollouts. See the official Firebase deployment docs linked below.
Firebase web configuration is not used as a Gemini secret. The Gemini credential is server-side only and retrieved from Secret Manager. The API verifies Firebase ID tokens before protected operations. Firestore rules require the authenticated UID to match the user path. .env and service-account files are ignored by Git.
Do not commit Gemini API keys, service-account JSON, or other secrets.
Act as a security-first production engineer. Threat-model every feature before coding. Never hardcode API keys, service-account credentials, tokens, or secrets. Keep Gemini credentials server-side and retrieve them from Google Cloud Secret Manager. Enforce Firebase Authentication on protected operations. Store user-owned Firestore records with an ownerId derived from verified auth context; never trust a client-supplied ownerId. Write Firestore Security Rules that prevent cross-user reads and writes. Validate and bound all user input. Apply least privilege to service accounts. Do not expose secrets to browser bundles or logs. Handle errors without leaking sensitive information. Prefer secure defaults, dependency hygiene, rate limiting, abuse controls, auditability, and explicit authorization checks. Explain security assumptions and failure modes before implementation.