<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jesica on Medium]]></title>
        <description><![CDATA[Stories by Jesica on Medium]]></description>
        <link>https://medium.com/@jesica.s.suthar?source=rss-23fc081d3d80------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*P2WeC0_IZHCGbkOSIogZlQ.jpeg</url>
            <title>Stories by Jesica on Medium</title>
            <link>https://medium.com/@jesica.s.suthar?source=rss-23fc081d3d80------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:09:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jesica.s.suthar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Luminary: An Isolated, Authenticated AI Journal Powered by Gemini and Cloud Run]]></title>
            <link>https://medium.com/@jesica.s.suthar/building-luminary-an-isolated-authenticated-ai-journal-powered-by-gemini-and-cloud-run-b8a4b696cb04?source=rss-23fc081d3d80------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8a4b696cb04</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[accelerateaiwithcloudrun]]></category>
            <category><![CDATA[genapac]]></category>
            <category><![CDATA[cohort-3]]></category>
            <dc:creator><![CDATA[Jesica]]></dc:creator>
            <pubDate>Sun, 06 Sep 2026 17:55:54 GMT</pubDate>
            <atom:updated>2026-09-06T18:02:23.073Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A submission for the Gen AI APAC Ideathon Challenge — Personal Gemini Journal</em></p><p><strong>The Problem with AI-Generated Apps</strong></p><p>Most AI-created apps look excellent when demonstrated. If you ask any AI model to “build me a journal app with AI chat”, you’ll soon have a working prototype featuring a sign-in screen, a chat window, and possibly an attractive user interface. However, on closer examination, you’ll discover structural flaws — such as an API key left exposed in the client bundle, a database lacking real access restrictions, or an admin panel that could be compromised with just a single guess.</p><p>The real challenge in the GenAI APAC Ideathon is not “Can you get Gemini to respond to a prompt?” but “Can you set up Google AI Studio so that it thinks like a security engineer before it writes a single line of code?” I decided to find out and therefore created <strong>Luminary</strong>, a personal AI journaling app, as a proof of concept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6ZSf-6MeLIsJkDvAjXDeA.png" /><figcaption>Landing Page</figcaption></figure><p><strong>Phase 1: Writing the Playbook Before Writing Any Code</strong></p><p>Before touching the app itself, I configured Google AI Studio with custom system instructions — an architectural “playbook” that every subsequent code-generation turn had to enforce. The goal was to bake in defence-in-depth principles that usually get skipped under demo-day time pressure.</p><p>Instead of treating security as a post-build polish step, the playbook established seven non-negotiable directives across identity, data boundary, and API lifecycle controls:</p><ul><li><strong>Cryptographic Identity Binding:</strong> Every data path and document route is explicitly scoped to the authenticated user’s session claims (<em>/users/{uid}/*</em>), eliminating implicit “current user” assumptions.</li><li><strong>Principle of Least Privilege (RBAC):</strong> Strict separation across four distinct roles (<em>guest</em>, <em>user</em>, <em>admin</em>, <em>super admin</em>) regulating both UI rendering and database access.</li><li><strong>Zero-Knowledge Data Partitioning:</strong> No administrative role, background worker, or shared query path can ever query or expose raw journal contents across user boundaries.</li><li><strong>Adversarial Injection &amp; Prompt Screening:</strong> Incoming user inputs pass through a pre-execution sanitization layer targeting prompt injection primitives (e.g., “ignore previous instructions”, “dump system prompts”).</li><li><strong>Strict Schema &amp; Output Sanitization:</strong> Incoming client payloads pass Zod schema validation before hitting business logic. At the same time, all Gemini-generated Markdown/HTML responses undergo DOM sanitization before rendering to neutralize model-reflected stored XSS attacks.</li><li><strong>Per-User Rate Limiting &amp; Wallet Defense:</strong> Multi-tier token-bucket rate limiting enforced at the server proxy layer (by IP and authenticated userId) to prevent API quota exhaustion or denial-of-wallet attacks.</li><li><strong>Immutable &amp; Privacy-Safe Audit Logging:</strong> Privilege elevation attempts, prompt-guard triggers, and administrative actions are committed to an append-only audit trail that logs metadata <em>without</em> storing sensitive raw entry text.</li></ul><p>Here is the actual directive passed to Google AI Studio:</p><p>Luminary Security Directive v1- Enforced on all code generation tasks</p><p>1. Identity &amp; Access: Scope all user resources to<em> /users/{uid}/*</em>. Enforce strict RBAC across guest, user, admin, and super admin roles.</p><p>2. Data Privacy: Implement zero-knowledge partitioning. Raw user journal data must be unreadable by cross-tenant or admin queries.</p><p>3. Input/Output Hygiene: Validate all incoming payloads against rigid schemas (Zod). Sanitize all model-generated Markdown/HTML before rendering.</p><p>4. Prompt Defence: Screen inputs for adversarial injection patterns before dispatching to the Gemini API.</p><p>5. Availability &amp; Audit: Enforce per-user proxy rate limiting. Write all security events to an append-only, privacy-preserving audit log.</p><p>The interesting part wasn’t just defining these rules; it was observing how drastically they altered code synthesis. Left to its default behaviors, an LLM will naturally generate open rules like <em>allow read, write: if true</em>; because they “just work” during initial testing. Establishing security directives as standing instructions forces the model to construct verified boundary checks from the very first file.​</p><p><strong>Phase 2: Building the Core Application</strong></p><p>With the playbook in place, I used AI Studio to build out the four required pillars. Here’s how the pieces fit together before I walk through each one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9elMP4zXhD3zQR1qa43QQ.png" /><figcaption>Architecture diagram</figcaption></figure><p><strong>1. User Authentication</strong></p><p>Firebase Authentication handles sign-in and issues a verified identity token for every session, ensuring no custom auth logic and no guessing who is making a request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*N6AMOa1tZ_uq5keO.png" /><figcaption>sign in screen</figcaption></figure><p><strong>2. Multi-Turn AI Interaction</strong></p><p>Journal conversations run through the <em>@google/genai SDK</em> against <strong>Gemini 2.5 Flash</strong>. Entries are automatically summarized into a concise title, an emotional sentiment analysis, and key takeaways. Users can select reflection styles — <em>Socratic</em>, <em>Stoic</em>, <em>Poetic</em>, or <em>Analytical </em>from a prompt library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*tRDlD_0ukMV-twHS.png" /><figcaption>Gemini companion chat mid-conversation</figcaption></figure><p><strong>3. Isolated Data Storage</strong></p><p>Every entry, conversation, and piece of memory metadata lives under /users/{userId}/… in Cloud Firestore. Catching and fixing the database access policy was one of the most valuable parts of the build: my first pass at firestore. rules had the isolation described in the documentation but allowed open read/write access. The corrected rules check request.auth.uid against the document path on every request and deny everything else by default:</p><p>rules_version = ‘2’;<br>service cloud.firestore {<br> match /databases/{database}/documents {<br> <br> // User data isolation rule<br> function isOwner(userId) {<br> return request.auth != null &amp;&amp; request.auth.uid == userId;<br> }</p><p>match /users/{userId}/{document=**} {<br> allow read, write: if isOwner(userId);<br> }</p><p>// Default-deny fallback rule<br> match /{document=**} {<br> allow read, write: if false;<br> }<br> }<br>}</p><p><strong>4. Secure Key Management with Cloud Run</strong></p><p>The Gemini API key never touches the browser client. All calls are proxied through an Express server running in a <strong>Cloud Run</strong> container, with the key retrieved dynamically from <strong>Google Cloud Secret Manager</strong>.</p><p>// Express server proxy running on Cloud Run<br>import { GoogleGenAI } from ‘<a href="http://twitter.com/google/genai">@google/genai</a>’;<br>import express from ‘express’;</p><p>const app = express();<br>app.use(express.json());</p><p>// Initialize SDK with key backed by Secret Manager<br>const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });</p><p>app.post(‘/api/chat’, async (req, res) =&gt; {<br> const { prompt } = req.body;<br> if (!req.headers.authorization) {<br> return res.status(401).json({ error: ‘Unauthorized session’ });<br> }</p><p>try {<br> const response = await ai.models.generateContent({<br> model: ‘gemini-2.5-flash’,<br> contents: prompt,<br> });<br> return res.json({ text: response.text });<br> } catch (error) {<br> return res.status(500).json({ error: ‘Proxy communication error’ });<br> }<br>});</p><p><strong>Phase 3: Going Beyond the Spec</strong></p><p>To expand beyond a standard journaling app, Luminary includes several unique features:</p><ul><li><strong>Chrono-Adaptive Theme Engine:</strong> The UI dynamically adjusts its palette and lighting across five solar phases (<em>Dawn, Midday, Golden Hour, Twilight, Midnight</em>) based on the user’s local time.</li><li><strong>Constellation of Thoughts:</strong> A 3D interactive canvas that maps journal entries into a node-connected star graph, visually clustering entries by semantic similarity and emotional mood.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*_6Mzd8_0Cxm5ZW0O.png" /><figcaption>Constellation of Thoughts view</figcaption></figure><ul><li><strong>Scrapbook Memories:</strong> In-browser voice dictation featuring live waveform visuals, polaroid-style photo attachments, and optional geolocation tagging.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*KfKy5S8g57XrVjHO.png" /><figcaption>Photo attachments and geoloaction tagging</figcaption></figure><ul><li><strong>Admin Overseer Console &amp; RBAC Simulator:</strong> Real-time system performance metrics, prompt-guard telemetry logs, and an interactive tool that tests prompts against all four user roles to verify permission boundaries.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*yXSr0VKUA97nF4Bg.png" /><figcaption>Admin dashboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7z02pU2eU7bqxcsG9hhdWA.png" /><figcaption>Security &amp; RBAC Architecture Walkthrough</figcaption></figure><p><strong>What I ctually Learned</strong></p><ol><li><strong>Security must be a continuous process rather than a final checklist, as the difference between “generate a journaling app” and “generate a journaling app under this playbook”</strong> has a fundamental impact on the architecture of the synthesised code.</li><li><strong>“Looks isolated” vs. “Is isolated”:</strong> My initial documentation outlined zero-knowledge data partitioning while my database rules remained unrestricted. Catching this required verifying security claims with explicit tests rather than assuming they were active.</li><li><strong>Where you keep secrets matters:</strong> Routing the Gemini API key through Secret Manager and a Cloud Run server-side proxy ensures client-side bundle inspections reveal zero credentials.</li><li><strong>Deny-by-default is cheap insurance:</strong> Adding <em>match /{document=**} { allow read, write: if false; }</em> costs nothing when every real collection already has an explicit rule but it means any collection you forget to secure later fails closed instead of open.</li></ol><p><strong>Try It &amp; Links</strong></p><ul><li><strong>Live App URL: </strong><a href="https://ais-dev-gcpkqgpbslwq245vnfv7mf-993816265377.asia-southeast1.run.app/"><strong>https://ais-dev-gcpkqgpbslwq245vnfv7mf-993816265377.asia-southeast1.run.app/</strong></a></li><li><strong>GitHub Repository:</strong><a href="https://github.com/jesicasuthar/luminary-journal"> https://github.com/jesicasuthar/luminary-journal</a></li><li><strong>Architecture &amp; Playbook Documentation:</strong> Detailed in the repository README.me</li></ul><p><em>Built for the GenAPAC AI Ideathon Challenge.</em> #AccelerateAIwithCloudRun #genapacai #cohort3</p><p>​</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8a4b696cb04" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>