{"slug": "building-sanctuary-ai-a-privacy-first-ai-journal-with-gemini-and-google-cloud", "title": "Building Sanctuary AI: A Privacy-First AI Journal with Gemini and Google Cloud Run", "summary": "A developer built Sanctuary AI, a privacy-first AI journaling application using Google Cloud Run, Firebase Authentication, Cloud Firestore, and Google Gemini. The app allows users to write or voice-record reflections, analyze them with Gemini, and engage with AI personas for Socratic questioning and cognitive reframing, with user data isolated via user-scoped Firestore collections and security rules.", "body_md": "Personal journaling is useful, but it can be difficult to turn a collection of thoughts into meaningful insights or actionable goals.\n\nI wanted to experiment with a different approach: what if an AI could act as a reflection companion while keeping each user's journal data isolated and securely managed?\n\nThat idea became Sanctuary AI, a cloud-native personal reflection and journaling application built with Google Cloud Run, Firebase Authentication, Cloud Firestore, and Google Gemini.\n\nThe core workflow is simple:\n\nReflect → Understand → Act → Review\n\nWhat does Sanctuary AI do?\n\nSanctuary AI allows an authenticated user to:\n\n✍️ Write and save personal reflections\n\n🎙️ Create reflections using voice\n\n🧠 Analyze reflections with Gemini\n\n💭 Explore thoughts using Socratic questions\n\n🔄 Get alternative perspectives and cognitive reframing\n\n🤝 Chat with different AI Companion personas\n\n🔎 Ask questions about previous journal entries\n\n🎯 Convert insights into actionable goals\n\n✅ Track goals and tasks\n\n📊 Review recurring themes and insights\n\n📦 Export personal data\n\n🗑️ Delete their account and associated data\n\nThe idea is not to replace personal reflection with AI.\n\nInstead, AI is used as a tool to help the user think more deeply about their own experiences.\n\nArchitecture\n\nThe application uses Google Cloud services for authentication, storage, backend processing, and AI.\n\n```\n               Sanctuary AI\n                    │\n                    ▼\n            ┌───────────────┐\n            │   Web Client  │\n            └───────┬───────┘\n                    │\n                    ▼\n            Firebase Auth\n                    │\n               ID Token\n                    │\n                    ▼\n            ┌───────────────┐\n            │   Cloud Run   │\n            │    Backend    │\n            └───────┬───────┘\n                    │\n         ┌──────────┴──────────┐\n         ▼                     ▼\n  Cloud Firestore          Gemini API\n   User Data                 AI\n         │\n         ▼\n  User-scoped data\n```\n\nCloud Run handles the backend logic while Firestore stores application data.\n\nGemini provides the AI capabilities.\n\nFirebase Authentication provides the identity layer.\n\nKeeping User Data Isolated\n\nBecause this application deals with personal reflections, data isolation was one of the most important design considerations.\n\nUser data is organized using user-scoped Firestore collections:\n\n/users/{userId}/journals\n\n/users/{userId}/goals\n\n/users/{userId}/insights\n\n/users/{userId}/conversations\n\n/users/{userId}/messages\n\nFirestore security rules enforce ownership:\n\nrequest.auth.uid == userId\n\nThe backend also validates the Firebase ID token and derives the authenticated user's identity from the token instead of trusting a user-provided user ID.\n\nThis creates a clear boundary between users.\n\nNote: Firestore security rules provide authorization and data isolation. They should not be confused with end-to-end encryption.\n\nGemini-Powered Reflection\n\nOne of the main challenges was deciding how Gemini should actually be useful inside a journal.\n\nInstead of creating only a general-purpose chatbot, I created focused AI workflows.\n\nA reflection can be processed to generate:\n\nKey themes\n\nSocratic questions\n\nAlternative perspectives\n\nSummaries\n\nPotential action items\n\nGoal suggestions\n\nFor example, instead of simply telling the user what to do, the Socratic workflow can encourage deeper thinking by asking questions about assumptions, evidence, and possible alternatives.\n\nThis keeps the user involved in the reflection process.\n\nAI Companion\n\nSanctuary AI also includes multiple interaction styles.\n\nSocratic Guide\n\nDesigned to encourage deeper thinking through questions.\n\nCompassionate Empath\n\nDesigned for supportive and empathetic reflection.\n\nExecution Coach\n\nFocused more on practical next steps and execution.\n\nThe purpose is to make the AI interaction more useful depending on what the user needs at that moment.\n\nAsk My Journal\n\nOne of the features I particularly wanted to build was Ask My Journal.\n\nInstead of asking Gemini general questions, the user can ask questions about their own previous reflections.\n\nFor example:\n\n\"What topics have I been thinking about repeatedly?\"\n\n\"What goals have I mentioned recently?\"\n\n\"What patterns appear across my reflections?\"\n\n\"What did I write about this topic previously?\"\n\nThe system uses the user's journal history to help answer these questions and can reference relevant reflection dates.\n\nThis turns the journal from a collection of individual entries into something that can be explored over time.\n\nVoice Journaling\n\nSometimes writing isn't the easiest way to capture an idea.\n\nSanctuary AI supports voice journaling using browser speech capabilities.\n\nThe flow is:\n\nSpeak\n\n↓\n\nSpeech Recognition\n\n↓\n\nJournal Text\n\n↓\n\nSave Reflection\n\n↓\n\nAI Analysis\n\nThis makes it easier to capture thoughts quickly.\n\nFrom Reflection to Action\n\nAnother important part of the application is connecting reflection with action.\n\nAn insight can be converted into a goal containing tasks, priority, and progress.\n\nGoal\n\n├── Priority\n\n├── Progress\n\n├── Task 1\n\n├── Task 2\n\n└── Completion Status\n\nThis creates a bridge between:\n\n\"I realized something\"\n\nand\n\n\"I am going to do something about it.\"\n\nInsights and Periodic Reviews\n\nThe application also looks beyond individual journal entries.\n\nOver time, users can review recurring themes and insights from their reflections.\n\nThe workflow becomes:\n\nReflections\n\n↓\n\nAI Analysis\n\n↓\n\nRecurring Themes\n\n↓\n\nInsights\n\n↓\n\nGoals\n\n↓\n\nPeriodic Review\n\nThis is where the Reflect → Understand → Act → Review model becomes useful.\n\nUsing Google AI Studio\n\nI used Google AI Studio while developing and refining the AI workflows.\n\nThe development process looked roughly like this:\n\nIdea\n\n↓\n\nPrompt Design\n\n↓\n\nTest in AI Studio\n\n↓\n\nEvaluate Response\n\n↓\n\nRefine Instructions\n\n↓\n\nIntegrate into Application\n\nThis was especially useful for experimenting with the different AI Companion personas and reflection workflows before integrating them into the application.\n\nHandling AI Reliability\n\nAI APIs can occasionally experience latency or failures.\n\nFor that reason, I designed the AI integration with resilience in mind, including fallback and timeout/circuit-breaker concepts.\n\nThe basic idea is:\n\nPrimary Model\n\n↓\n\nFailure / Timeout?\n\n↓\n\nFallback Model\n\n↓\n\nFailure?\n\n↓\n\nNext Fallback\n\nThis helps prevent a temporary AI service problem from making the entire application unavailable.\n\nSecurity and Privacy\n\nPrivacy was considered throughout the application architecture.\n\nSome of the key decisions include:\n\nFirebase Authentication for user identity\n\nUser-scoped Firestore data\n\nOwnership-based Firestore security rules\n\nServer-side handling of Gemini credentials\n\nGoogle Cloud Secret Manager for sensitive configuration\n\nBackend token validation\n\nUser data export\n\nAccount/data deletion\n\nThere are also areas I would like to improve further, particularly around stronger encryption and minimizing sensitive information sent to external AI services.\n\nWhy Cloud Run?\n\nCloud Run provides a simple way to deploy the backend as a containerized service without managing traditional servers.\n\nFor this project, it fits well because the application needs a backend that can:\n\nAuthenticate requests\n\nCommunicate with Firestore\n\nCommunicate with Gemini\n\nManage application logic\n\nScale with demand\n\nRun securely behind a public HTTPS endpoint\n\nThe deployment flow is essentially:\n\nApplication\n\n↓\n\nContainer\n\n↓\n\nCloud Run\n\n↓\n\nHTTPS Service\n\nWhat I Learned\n\nThe biggest lesson from this project was that building an AI application is not just about calling an LLM API.\n\nThe surrounding engineering is equally important:\n\nAuthentication\n\nAuthorization\n\nData isolation\n\nPrompt engineering\n\nSecret management\n\nAI reliability\n\nBackend architecture\n\nUser experience\n\nData ownership\n\nGemini is one component of the application, not the entire application.\n\nThe final system combines:\n\nFirebase Authentication\n\n+\n\nCloud Firestore\n\n+\n\nCloud Run\n\n+\n\nGemini\n\n+\n\nGoogle AI Studio\n\n+\n\nPrivacy & Security\n\n↓\n\nSanctuary AI\n\nTry the Application\n\n🌐 Live Demo:\n\n[https://private-ai-journal-reflection.ai.studio](https://private-ai-journal-reflection.ai.studio)\n\n💻 Source Code:\n\n[https://github.com/KVedang/Stability-AI](https://github.com/KVedang/Stability-AI)\n\nThe project is also part of my participation in the Accelerate AI with Cloud Run challenge.\n\nWhat's Next?\n\nSome improvements I would like to explore include:\n\nMore advanced semantic retrieval\n\nBetter long-term journal analysis\n\nAdditional privacy controls\n\nImproved personalization\n\nMore sophisticated insights\n\nStronger encryption options\n\nImproved goal analytics\n\nFinal Thoughts\n\nSanctuary AI started with a simple question:\n\nCan AI help people understand their own reflections without taking the reflection away from them?\n\nThe result is a platform built around:\n\nReflect → Understand → Act → Review\n\nThe goal isn't to have AI make decisions for the user.\n\nIt's to provide a private space where AI can help users ask better questions, discover patterns, and turn their own reflections into meaningful actions.", "url": "https://wpnews.pro/news/building-sanctuary-ai-a-privacy-first-ai-journal-with-gemini-and-google-cloud", "canonical_source": "https://dev.to/kvedang/building-sanctuary-ai-a-privacy-first-ai-journal-with-gemini-and-google-cloud-run-2ee6", "published_at": "2026-09-04 08:44:15+00:00", "updated_at": "2026-09-04 08:53:51.445630+00:00", "lang": "en", "topics": ["artificial-intelligence", "generative-ai", "ai-products", "ai-tools", "developer-tools"], "entities": ["Sanctuary AI", "Google Cloud Run", "Firebase Authentication", "Cloud Firestore", "Google Gemini"], "alternates": {"html": "https://wpnews.pro/news/building-sanctuary-ai-a-privacy-first-ai-journal-with-gemini-and-google-cloud", "markdown": "https://wpnews.pro/news/building-sanctuary-ai-a-privacy-first-ai-journal-with-gemini-and-google-cloud.md", "text": "https://wpnews.pro/news/building-sanctuary-ai-a-privacy-first-ai-journal-with-gemini-and-google-cloud.txt", "jsonld": "https://wpnews.pro/news/building-sanctuary-ai-a-privacy-first-ai-journal-with-gemini-and-google-cloud.jsonld"}}