Build AI apps with the Google ecosystem

11 minutes read

From a hand-drawn sketch to a deployed AI app

This post is my walkthrough of the Google codelab Build AI apps with the Google ecosystem, written by Marina Coelho (last updated Oct 26, 2026). I kept the same section titles as the codelab, so you can follow both side by side.

The goal is to build a complete app almost without writing code by hand. Each tool takes care of one part:


1. Before you begin

The app is called Decide For Me. It’s a decision assistant for indecisive people: you write down your priorities in life, then give it two options (buy or keep renting, change careers or stay, etc.). The AI picks the one that minimizes long-term regret and gives you a concrete first step to take.

What you need:

What you’ll learn


2. Design the UI with Stitch

The codelab provides a hand-drawn mockup of the app. Download it here (DecideForMeScreen.jpeg) and save it somewhere you can find it.

Go to Stitch and select the Web option in the input field. Stitch can also generate mobile screens, but this codelab only covers the web version.

Upload the mockup:

+ > Upload Files > DecideForMeScreen.jpeg

Since it’s a hand-drawn sketch, it’s a good test of how well Stitch understands images.

Next, copy the following prompt and paste it into the input field:

# General Guidance
Create a modern, clean, and highly polished UI for a web application called
"Decide For Me" - a hyper-rational decision assistant.

CRITICAL: Replicate the exact layout, structure, and element placement shown in
the hand-drawn mockup file DecideForMeScreen.jpeg. Do not add any extra menus,
sidebars, buttons, or top/bottom navigation bars that are not explicitly drawn
in the file. Stick strictly to the skeleton provided in the mockup.

# Layout & Structure
- Two-Column Split Screen:
  - Left Side (Main Chat Area): Takes up roughly 70-75% of the screen width. It
    should feel like a premium, focused workspace.
  - Right Side (Configuration Panel): A sidebar taking up 25-30% of the screen
    width with a distinct, subtle background color to separate it from the
    chat.

# Right Panel: Configuration Screen
- Header: Title it "My Priorities" with a clean, minimalist typography.
- Content Card: A styled card containing a text box or paragraph area
  showcasing the user's priorities.
- Interactions: Include a clear "Edit Priorities" button. When clicked, this
  area should visually toggle into an editable textarea or input field.

# Left Panel: Chat & Dilemma Decision Screen
- Chat History: A clean vertical flow of message bubbles.
  - The first message bubble must be aligned to the left (system message) and
    say: "Tell me your dilemma". Use a friendly, neutral background color for
    this bubble.
- Bottom Input Area: Instead of a traditional single-line chat bar, create a
  unified, beautiful "Decision Submission" layout positioned at the bottom:
  - Dual Input Fields: Place two horizontal or cleanly stacked input fields.
    - Input 1 label: "Option A"
    - Input 2 label: "Option B"
  - Action Button: A prominent, styled "Go" action button to trigger the
    reasoning loop.

# Theme & Aesthetic
- Vibe: Hyper-rational, clean, trustworthy, and modern. Use a sophisticated
  color palette (e.g., deep slates, clean whites/grays, and a sharp accent
  color like a subtle indigo or teal for active states and buttons).
- Spacing & Typography: Use generous whitespace, soft rounded corners
  (border-radius) for cards and buttons, and a highly legible sans-serif font.

Click the generate arrow in the bottom-right corner of the input field. Stitch generates the screen and also a full design system: color palette, fonts, icons and the general style of the UI elements.

If it takes more than 5 minutes to generate the screen, reload the page and submit the prompt again.

You can download the design Stitch generated for me here. It contains the screen (screen.png), its HTML (code.html) and the design system (DESIGN.md).


3. Build the app with Google AI Studio

First, create a Firebase project:

  1. Sign in to the Firebase console with the same Google Account you used for Stitch.
  2. Create a new project and give it a name, for example Decider App.
  3. Click Continue and accept the Firebase terms if prompted.
  4. Optionally, enable Gemini in Firebase (AI assistance inside the console).
  5. Turn off Google Analytics, it’s not needed here.
  6. Click Create project, wait until it’s ready and click Continue.

Write down the project ID shown below the project name. You’ll need it in the prompt below. If you lose it, it’s also in Project Settings.

Now export the Stitch design to Google AI Studio:

Click the generated design > Export (top-right corner) > Google AI Studio > Description field

Copy the following prompt and paste it into the Description field. Replace [FIREBASE_PROJECT_ID] with your project ID.

# General Guidance
Build the "Decide For Me" app: A hyper-rational decision assistant for
chronically indecisive people facing life choices (moving apartments, changing
careers, picking a hobby). The user enters a dilemma and their top priorities
in life. The app will help with the decision. Follow the instructions below to
build it:

# UI Instructions
Using the design artifacts exported from Stitch (the PNG image and HTML file),
build a fully functional web application that accurately mirrors the design and
layout.

# App Architecture & Initialization Instructions
- Initialize the latest Firebase JS SDK for client-side services. Use the
  Firebase project with ID [FIREBASE_PROJECT_ID].
- Enable Firebase Authentication in this project using the Google provider.
  If a user is not logged in, show a clean, minimalist sign-in state. If the
  user is logged in, take them directly to the dilemma decision screen.
- Initialize Firebase App Check in debug mode with the following code:
  `self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;`
  `initializeAppCheck(app, { /* App Check options */ });`


# State & Database Management Instructions
- User Priorities:
  - Once authenticated, pull the user's saved priorities from Firebase
    Firestore at the path: `users/{userId}`. Each document should contain one
    string field: 'priorities'.
  - Bind this data to the Right Panel ("My Priorities").
  - When the user clicks the "Edit" button, toggle the view to a textarea, with
    a 'save' button. When saved, write the updated string back to
    `users/{userId}`.
  - Make sure to implement and deploy strong Security Rules for Firestore.

# UI Stream Update & Display Instructions
- Once the user submits option A and option B in the dilemma decision screen,
  display both options as a single message on the user side of the chat. Then,
  display a sleek loading state in the main chat panel. Leave the app in this
  "loading" state and do nothing else, we will process both options and build
  the server-side thinking later.

Click Build with Google AI Studio. It opens Google AI Studio in a new tab with the design files and the prompt. Check that the whole prompt was carried over; if only part of it shows up, paste it again.

Click Build. While it generates the app, Google AI Studio suggests alternative UI designs. You can ignore them for this codelab. When it asks you to enable Firebase, click Enable.

When it finishes, inspect the result:

Google AI Studio also sets up a Firebase project with Firebase Authentication and Firestore enabled, and adds the Firebase configuration to the code. We’ll work with that project in the next step.

If generating the app takes more than 10 minutes, close the tab, go back to Stitch and start again from the Export step.


4. Register your App Check debug token

Google AI Studio connected the app to a Firebase project. Now we need to find that project and register our development environment in Firebase App Check.

Access your Firebase project

Find the project ID that Google AI Studio is actually using:

Code tab > firebase-applet-config.json > copy the value of projectId

Then search for that ID in the Firebase console. Don’t assume it’s the project you created in step 3, check the ID.

If this is your first Firebase project, there’s only one project in the list: the one created by Google AI Studio.

If firebase-applet-config.json doesn’t exist, or the project isn’t in the console, the project wasn’t created. Ask Google AI Studio: “Please add Firebase Auth and Firestore to this app.”

Register your debug token

App Check protects your backend and AI models from abuse by making sure requests come from your real app, not from a script calling your APIs directly.

Initializing App Check or registering a debug token doesn’t protect anything on its own. You have to enforce App Check for each service you want to protect. Firebase AI Logic gets enforced later in this post. For Firestore, you can enforce it in the App Check settings once you’ve verified the incoming traffic.

The app runs inside the Google AI Studio preview, so it uses the App Check debug provider (self.FIREBASE_APPCHECK_DEBUG_TOKEN = true). When the app loads, Firebase prints a debug token in the browser console.

Open the developer tools while viewing the preview:

Look for a message like this one:

AppCheck debug token: "123a4567-b89c-12d3-e456-789012345678".
You will need to safelist it in the Firebase console for it to work.

Copy the token without the quotes and register it in the Firebase console:

Security > App Check > Apps tab > ⋮ on your web app > Manage debug tokens > Add debug token

Paste the token, give it a name like Google AI Studio Preview and click Save.

If the token doesn’t appear in the console, refresh the preview or ask the Google AI Studio agent: “Please ensure Firebase App Check is initialized in debug mode using self.FIREBASE_APPCHECK_DEBUG_TOKEN = true.”


5. Test the app

With the project connected and the debug token registered, let’s test the basics: Authentication and Firestore.

In the app preview inside Google AI Studio:

  1. Sign in with a Google Account.
  2. Save your priorities in the My Priorities panel.

Then check the Firebase console:

If there are no documents in Firestore, open the Rules tab. If the rules are empty or return false for every request, the app can’t write anything. Go back to Google AI Studio and ask it to deploy strong security rules for the app.

For reference, a minimal rule where each user can only read and write their own document looks like this:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
  }
}

6. Build an AI-powered Decider flow using Firebase

Now for the interesting part: the AI that makes the decision. We’ll build it in Firebase.

Set up Firebase AI Logic

Open Firebase AI Logic in the Firebase console, click Get started, select Gemini Developer API and follow the steps to enable it.

At this point App Check is enforced automatically for Firebase AI Logic. That’s why we registered the debug token before: without it, requests from the Google AI Studio preview would be rejected.

Then, in the Settings tab, set both options to Enforced:

Create a server prompt template

Instead of writing the prompt in the client code, we’ll store it in Firebase as a server prompt template. This has three advantages:

Create the template:

Prompt templates tab > Create template > Blank template

Configuration (frontmatter): the model, the input variables and the JSON output schema.

model: "gemini-3.5-flash-lite"
input:
  schema:
    priorities: "string, user's core priorities"
    optionA: "string, option A under consideration"
    optionB: "string, option B under consideration"
output:
  format: json
  schema:
    verdict: string
    justification: string
    firstStep: string

Prompt and system instructions: the system part defines the “Decider Agent” persona, and the user part receives the three inputs and reasons through three phases.

{{role "system"}}
You are the Decider Agent, a multi-stage reasoning engine that
combines the roles of an honest and polite behavioral economist, a
long-term strategic forecaster, and an executive decision coach.
Your job is to take a user's dilemma and their core priorities, run
them through a rigorous, adversarial 3-phase thinking process, and
output a highly analytical, reasoning-backed final verdict. You must be
direct, sharp, and realistic. Do not give generic platitudes or claim
that "both options are great." You must force a clear choice.

{{role "user"}}
# Context & Inputs
You are analyzing a critical life decision for the user. Base your
entire multi-phase reasoning flow strictly on these three specific
inputs:
- User's Core Priorities: {{priorities}}
- Option A under consideration: {{optionA}}
- Option B under consideration: {{optionB}}

Execute your reasoning flow through the following three phases:

# Phase 1: Cynical Breakdown (Input-Driven Analysis)
Analyze {{optionA}} and {{optionB}} strictly through the lens of the
user's explicit {{priorities}}. Do not evaluate them in a vacuum.
- Identify the hidden flaws, compromises, and psychological costs
  embedded in both choices.
- Pinpoint exactly how {{optionA}} could directly conflict with or
  undermine their {{priorities}}.
- Pinpoint exactly how {{optionB}} could directly conflict with or
  undermine their {{priorities}}.
- Uncover any cognitive biases (like status quo bias or loss aversion)
  the user might be falling for in either option.

# Phase 2: Long-Term Regret Projection
Project the user 5 years into the future. Apply the Regret Minimization
Framework to both paths:
- The {{optionA}} Timeline: Quantify the absolute worst-case, deep,
  structural 5-year regret of choosing this path. Focus heavily on
  failures of courage vs. failures of action based on their
  {{priorities}}.
- The {{optionB}} Timeline: Quantify the matching 5-year regret for
  this path.
- Contrast these two timelines. Which option carries the kind of regret
  that fundamentally breaks the user's {{priorities}}?

# Phase 3: Final Recommendation & Action Step
Synthesize the cynical critiques and long-term regret scores.
Weigh them against the user's {{priorities}} to determine which
choice minimizes long-term disappointment.
- Verdict: You must declare either {{optionA}} or {{optionB}} as the
  definitive winner. No compromise, no "it depends," and no hybrid
  options.
- Justification: Provide a sharp, reasoning-backed explanation showing why
  the losing option was eliminated based on the Phase 1 and Phase 2
  analysis.
- First Step: Give one microscopic, low-friction task the user can
  execute within the next 15 minutes to commit to or move toward the
  chosen verdict.

The roles need double braces: {{role "system"}} and {{role "user"}}. The codelab displays them with single braces ({role "system"}) and asks you to add the extra pair; the prompt above already has them.

Test input:

{
  "priorities": "Be financially stable, have a good work-life balance where I can travel twice a year",
  "optionA": "Buy a house for 615000 British pounds with a mortgage of 2800 per month for the next 35 years",
  "optionB": "Keep renting for 2400 per month for the foreseeable"
}

Click Save template, then Run prompt test. Check that the Test response contains all three fields: verdict, justification and firstStep.

If everything looks right, lock the template with the lock icon in the top-right corner. This keeps the version stable and prevents accidental changes.

The template is ready to be used by the app.


7. Use the Decider prompt template in the app

Go back to the app in Google AI Studio, copy the following prompt into the chat and click Send:

Now let's implement the "Decide For Me" button action. When clicked, it
should call the Firebase AI Logic SDK using a Template Generative Model.
The prompt is stored in a prompt template with the id "decider-flow". When
calling the API, pass the following variables as the input payload object:
- priorities
- optionA
- optionB

The API will return a JSON object. Handle the response asynchronously and
extract:
- verdict
- justification
- firstStep

Once the data is received, update the UI state to append a new message to
the chat array. Ensure it renders as a system chat bubble positioned on
the left side of the chat screen, mapping these three fields clearly into
the bubble's layout.

Please provide the necessary front-end component state updates and the
Firebase SDK call.

Wait until Google AI Studio finishes adding Firebase AI Logic to the app.

Before testing, open the Code tab and check that firebase-applet-config.json contains an API key. If it’s missing, ask Google AI Studio to import it.

Then go to the Preview tab, fill in Option A and Option B, and check that the AI returns the verdict, the justification and the first step.

If the call still fails with the API key in place, ask the Google AI Studio agent to fix it with this prompt:

“Please make sure the Firebase AI Logic call uses getAI(app) and getTemplateGenerativeModel(aiInstance) with the decider-flow template, parses the JSON response correctly into verdict, justification, and firstStep, and doesn’t contain any timeout constraints or unnecessary function checks.”

For reference, the code generated by Google AI Studio should look similar to this:

const aiInstance = getAI(app);
const templateModel = getTemplateGenerativeModel(aiInstance);

const result = await templateModel.generateContent('decider-flow', {
  priorities: priorities,
  optionA: optA,
  optionB: optB
});

const rawText = result.response.text();

// Parse response text to extract fields
const cleaned = rawText.replace(/```json|```/g, '').trim();
const parsedData: { verdict?: string; justification?: string; firstStep?: string } = JSON.parse(cleaned);

const verdict = parsedData.verdict;
const justification = parsedData.justification;
const firstStep = parsedData.firstStep;

Debug and monitor requests

If something fails, or you just want to see what’s going on, Firebase AI Logic has built-in monitoring:

AI Services > AI Logic > AI monitoring tab

The dashboard shows:

Click a request in the traces table to inspect it:

If you find an error in a trace (malformed JSON, a missing parameter…), copy the message or payload, paste it into Google AI Studio and ask it to fix the code.


8. Optional: Deploy the app

The app works in preview, so let’s put it in production.

The debug token only works for our own development environment. In production, App Check needs a real attestation provider. This codelab uses reCAPTCHA v3.

We deploy first because we need the exact live URL. That way we register only our domain in reCAPTCHA, instead of allowing every ai.studio app.

1. Deploy the app with Google AI Studio

Publish (top bar) > Get started > review the name and description > Publish your app

It takes 1-2 minutes. Copy the generated URL (for example https://decide-for-me-123.ai.studio) and note its domain (decide-for-me-123.ai.studio).

2. Create the reCAPTCHA v3 keys

In the Google reCAPTCHA Admin Console:

Accept the terms and click Submit. Keep the tab open: you’ll need the Site Key (public, used by the client) and the Secret Key (private, used by the server).

3. Register the secret key in Firebase

App Check > Apps tab > your web app (or ⋮) > reCAPTCHA v3

Paste the Secret Key and click Save.

4. Switch the client to ReCaptchaV3Provider

In the Google AI Studio chat, ask the assistant to update the App Check configuration for production:

Please update our Firebase App Check initialization to use
ReCaptchaV3Provider with the reCAPTCHA site key "YOUR_RECAPTCHA_SITE_KEY",
while retaining support for debug tokens in non-production environments.

If you check the Code tab, the App Check initialization should match this structure:

import { initializeAppCheck, ReCaptchaV3Provider } from "firebase/app-check";

const appCheck = initializeAppCheck(app, {
  provider: new ReCaptchaV3Provider("YOUR_RECAPTCHA_SITE_KEY"),
  isTokenAutoRefreshEnabled: true
});

Then publish the app again so the live site gets the new configuration.

5. Verify production traffic

Open the live URL in an incognito window, sign in with Google and submit a dilemma. Then go back to App Check and check the APIs and Monitoring tabs: requests to Firestore and Firebase AI Logic should show up as verified.

App Check is already enforced for Firebase AI Logic. Once you see that 100% of legitimate traffic is verified, you can also set Firestore to Enforce so unverified requests are rejected automatically.


9. Conclusion

That’s it! We went from a hand-drawn sketch to a deployed app with sign-in, a database and an AI feature, and AI did most of the coding. As a bonus, you end up with a Firebase and Google Cloud project you can keep exploring.

Some links to keep going:


This post is adapted from the codelab Build AI apps with the Google ecosystem by Marina Coelho, licensed under CC BY 4.0. The prompts, code samples and the DecideForMeScreen.jpeg mockup come from the codelab; code samples are under the Apache 2.0 License.

Thank you for reading. <3