This guide shows you how to use the App Prototyping agent to rapidly develop and publish a full-stack app with the help of Gemini in Firebase. You'll use a natural-language prompt to generate a Next.js app that identifies food items from a picture or in-browser camera provided by a logged-in user and generates a recipe that contains the identified ingredients. Users can then choose to store the recipe in a searchable database.
You'll then refine and improve the app, before ultimately publishing to Firebase App Hosting.
Other technologies you'll use as you proceed through this guide include:
- a Firebase Studio workspace
- a Firebase project
- Firebase App Hosting
- Cloud Firestore
- Firebase Authentication
- Firebase App Check
Step 1: Generate your app
Log into your Google Account and open Firebase Studio.
In the Prototype an app with AI field, enter the following prompt, which will create an image-based recipe app that uses the browser camera and generative AI.
For example, you could enter a prompt like the following to create a recipe generation app:
Use secure coding practices to create an error-free web app that lets users upload a photo or take a picture with their browser camera. The app identifies the food in the picture and generates a recipe and accompanying image that includes that food. If no food product is identified, generate a random dessert recipe.
Optionally, upload an image to accompany your prompt. For example, you can upload an image that contains the color scheme you want your app to use and tell Firebase Studio to use it. Images must be less than 3 MiB.
Click Prototype with AI.
The App Prototyping agent generates an app blueprint based on your prompt, returning a proposed app name, required features, and style guidelines.
Review the blueprint. If necessary, make a few changes. For example, you could change the proposed app name or color scheme using one of these options:
Click
Customize and edit the blueprint directly. Make your changes and click Save.In the Describe... field in the chat pane, add clarifying questions and context. You can also upload additional images.
Click Prototype this app.
The App Prototyping agent begins coding your app.
- Because your app uses AI, you're prompted to add or generate a Gemini API key. If you click Auto-generate, the App Prototyping agent provisions a Firebase project and a Gemini API key for you.
Step 2: Test, refine, debug, and iterate
After the initial app is generated, you can test, refine, debug, and iterate.
Review and interact with your app: After code generation completes, a preview of your app appears. You can interact with the preview directly to test it. Learn more at Preview your app.
Add Cloud Firestore and Firebase Authentication: During the iteration phase, you can ask the App Prototyping agent to add user authentication and a database using Cloud Firestore and Firebase Authentication. For example, give users the ability to save and download recipes with a prompt like the following:
Add user authentication to the app. Authenticated users can: - Download the recipe and its generated image as a PDF (Print). - Save the recipe as public or private and make accessible to a search feature. For now, just save the text, not the image, to the database. Important: Only authenticated users can download the PDF.
Fix any errors as they occur: In most cases, the App Prototyping agent prompts you to fix any errors that arise. Click Fix Error to allow it to attempt a fix.
If you receive errors that you're not prompted to fix automatically, copy the error and any relevant context (for example, "Can you fix this error in my Firebase initialization code?") into the chat window and send it to Gemini.
Test and iterate using natural language: Test your app thoroughly and work with the App Prototyping agent to iterate on the code and blueprint until you're happy with it.
While in Prototyper view, you can also use the following features:
Click
Annotate to draw directly on the Preview window. Use the available shape, image, and text tools, along with an optional text prompt, to visually describe what you want the App Prototyping agent to change.
Click
Select to select a specific element and enter instructions for the App Prototyping agent. This lets you quickly target a specific icon, button, piece of text, or other element. When you click an image, you also have the option of searching for and selecting a stock image from Unsplash.
Optionally, you can click
Share preview link to share your app publicly and temporarily using Firebase Studio public previews.
Create a Firebase project: The App Prototyping agent provisions a Firebase project on your behalf when you:
- Auto-generate a Gemini API key
- Ask to connect your app to a Firebase project
- Ask for help connecting your app to Firebase services, such as Cloud Firestore or Firebase Authentication
- Click the Publish button and set up Firebase App Hosting
To change the Firebase project connected to your workspace, prompt the App Prototyping agent with the project ID you want to use instead. For example, "Switch to Firebase project with ID
<your-project-id>
."Test the app and verify Cloud Firestore database rules: In the app preview pane, upload an image that shows different foods to test your app's ability to identify the ingredients and generate and save recipes.
Sign in as different users and generate recipes: make sure that authenticated users can see their private recipes and recipes and that all users see public recipes.
When you ask the App Prototyping agent to add Cloud Firestore, it writes and deploys Cloud Firestore database rules for you. Review the rules in the Firebase console.
Debug and iterate directly in the code: Click
Switch to Code to open Code view, where you can see all of your app's files and modify your code directly. You can switch back to Prototyper mode at any time.
While in Code view, you can also use the following helpful features:
Firebase Studio's built-in debugging and reporting features to inspect, debug, and audit your app.
AI assistance using Gemini either inline within your code or using Gemini interactive chat (both are available by default). Interactive chat can diagnose issues, provide solutions, and run tools to help fix your app faster. To access chat, click sparkGemini at the bottom of the workspace.
Access the Firebase Local Emulator Suite to view database and authentication data. To open the emulator in your workspace:
Click
Switch to Code and open the Firebase Studio extension (
Ctrl+',Ctrl+'
, orCmd+',Cmd+'
on MacOS).Scroll to Backend ports and expand it.
In the Actions column that corresponds to Port 4000, click Open in new window.
Test and measure your generative AI feature performance: You can use the Genkit Developer UI to run your Genkit AI flows, test, debug, interact with different models, refine your prompts, and more.
To load your Genkit flows in the Genkit Developer UI and start testing:
From the terminal in your Firebase Studio workspace, run the following command to source your Gemini API key and start the Genkit server:
npm run genkit:watch
Click the Genkit Developer UI link. The Genkit Developer UI opens in a new window with your flows, prompts, embedders, and a selection of different available models.
Learn more about the Genkit Developer UI at Genkit Developer Tools.
(Optional) Step 3: Publish your app with App Hosting
After you've tested your app and are satisfied with it in your workspace, you can publish it to the web with Firebase App Hosting.
When you set up App Hosting, Firebase Studio creates a Firebase project for you (if one was not already created by auto-generating a Gemini API key or other backend services) and guides you through linking a Cloud Billing account.
To publish your app:
Click Publish to set up your Firebase project and publish your app. The Publish your app pane appears.
In the Firebase project step, the App Prototyping agent displays the Firebase project associated with the workspace. If a Firebase project doesn't already exist, the App Prototyping agent creates a new project for you. Click Next to proceed.
In the Link Cloud Billing account step, choose one of the following:
Select the Cloud Billing account that you want to link to your Firebase project.
If you don't have a Cloud Billing account or want to create a new one, click Create a Cloud Billing account. This opens the Google Cloud console, where you can create a new self-serve Cloud Billing account. After you create the account, return to Firebase Studio and select the account from the Link Cloud Billing list.
Click Next. Firebase Studio links the billing account to the project associated with your workspace, created either when you auto-generated a Gemini API key or when you clicked Publish.
Click Set up services. The App Prototyping agent begins provisioning Firebase services.
Click Publish now. Firebase Studio sets up Firebase services and then launches the App Hosting rollout. This can take up to several minutes to complete. To learn more about what's happening behind the scenes, see The App Hosting build process.
When the publish step completes, the App overview appears with a URL and app insights powered by App Hosting observability. To use a custom domain (like example.com or app.example.com) instead of the Firebase-generated domain, you can add a custom domain in the Firebase console.
For more information about App Hosting, see Understand App Hosting and how it works.
(Recommended) Step 4: Test your published app
When publishing is complete and your app is deployed to Firebase, Cloud Firestore and Firebase Authentication are ready to test in production.
View Cloud Firestore and Firebase Authentication data in the Firebase console
You can view live data from your app in the Firebase console after publishing.
To view your live Cloud Firestore database, open the Firebase console and choose Build > Firestore Database from the navigation menu.
From here, you can inspect stored data, view and test your security rules, and create indexes. Learn more at Cloud Firestore.
To view your live Firebase Authentication data, open the Firebase console and choose Build > Authentication from the navigation menu.
From here, you can inspect your authentication configuration and app users. Learn more at Firebase Authentication.
Test Cloud Firestore rules in production
After publishing your app, you should test your Cloud Firestore security rules again, against your production environment. This helps to ensure that your data is accessible to authorized users and protected from unauthorized access.
You can test your rules using all of the following methods:
Application Testing: Interact with your deployed application, performing operations that trigger various data access patterns (reads, writes, deletes) for different user roles or states. This real-world testing helps confirm that your rules are correctly enforced in practice.
Rules Playground: For targeted checks, use the Rules Playground in the Firebase console. This tool lets you simulate requests (reads, writes, deletes) against your Cloud Firestore database using your production rules. You can specify the user authentication state, the path to the data, and the type of operation to see if your rules permit or deny access as intended.
Unit Testing: For more comprehensive testing, you can write unit tests for your security rules. The Firebase Studio preview backend powered by the Firebase Local Emulator Suite lets you run these tests locally, simulating the behavior of your production rules. This is a robust way to verify complex rule logic and confirm coverage for various scenarios. After deployment, you should double-check that your unit tests using the emulator work as expected and cover all scenarios.