Skip to content

Conversation

@peterfriese
Copy link
Contributor

@peterfriese peterfriese commented Nov 15, 2025

This pull request modernizes the iOS quickstart project, building upon the significant restructuring work initiated by Young Hypo. The primary goal is to create a more modular, scalable, and maintainable codebase that aligns with modern Swift and SwiftUI best practices.

Initial Refactoring (by Young Hypo):

  • A major effort was undertaken to deconstruct the monolithic project into a more organized and modular structure.

Refinements and Additions in this PR:

  • Logical Folder Structure: The folder organization was further refined to logically group files by feature (Features) and shared components (Shared), improving clarity and navigation.
  • Code Cleanup & Best Practices:
    • Addressed security concerns by removing hardcoded API key initialization and adopting the recommended FirebaseAI.firebaseAI(backend:) factory method.
    • Centralized shared models (like BackendOption) and UI components (ProgressOverlay, ErrorDetailsView) to eliminate redundancy and fix compilation errors.
  • New 'Hello World (with template)' Sample:
    • Added a new, simple example (GenerateContentFromTemplateScreen) to demonstrate server-side template functionality with the apple-qs-greeting template. This provides a clear and minimal entry point for users.

Overall, these changes make the project easier to understand, maintain, and extend, providing a better foundation for developers exploring Firebase AI features.

YoungHypo and others added 5 commits November 15, 2025 12:06
* feat: refactor main menu layout and clean up chat-related components
* Some minor layout fixes
* iterate over all TextParts
* add navRoute in Sample
* fix style in light/dark mode
* change Hstack to Label for multi-lines
* add .inline for navigationTitleMode
* integrate conversationkit to firebaseai

* refract functioncalling logic

* remove fatalError

* change preview for screens

* ♻️ Use ConversationKit

* ♻️ Refactor error handling

* ✨ Bring back pre-filled user messages

* 🧹Cleanup

* ⬆️ Use latest ConversationKit version

* fix style check

* add errordetailview for imagenexample

* ✏️ Fix typo

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* ✏️ Fix typo

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* ✏️ Fix typo

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* ✏️ Fix typo

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* fix style and change ci

---------

Co-authored-by: Peter Friese <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
… Feature

This commit introduces a significant refactoring of the iOS project, reorganizing the codebase into a more modular and maintainable structure. All feature-specific code has been moved into a new `Features` directory, while shared components (Models, Views) are now centralized under a `Shared` directory.

Key changes include:

- **Project Structure Reorganization**:
    - Created `FirebaseAIExample/Features` to house individual feature modules (e.g., `Chat`, `FunctionCalling`, `GenerativeAIText`, `Grounding`, `Imagen`, `Multimodal`).
    - Created `FirebaseAIExample/Shared` for common models, views, and utilities.
    - Updated `FirebaseAIExample.xcodeproj/project.pbxproj` to reflect the new file paths and group structure.

- **New Feature: 'Hello world (with template)'**:
    - Implemented `GenerateContentFromTemplateScreen` and `GenerateContentFromTemplateViewModel` under `Features/GenerativeAIText`.
    - This feature demonstrates server-side template generation using the `apple-qs-greeting` template.
    - Registered the new feature in `ContentView` and added a corresponding `Sample` entry in `Sample.swift` with the title "Hello world (with template)".

- **Bug Fixes and Best Practices**:
    - **Security Fix**: Replaced insecure API key initialization in `GenerateContentFromTemplateViewModel` with the secure `FirebaseAI.firebaseAI(backend:)` factory method.
    - **Compile Error Resolution**: Moved shared UI components (`ProgressOverlay.swift`, `ErrorDetailsView.swift`) into `FirebaseAIExample/Shared/Views` to resolve compile errors and ensure global accessibility.
    - **Centralized BackendOption**: Extracted the `BackendOption` enum into its own file (`FirebaseAIExample/Shared/Models/BackendOption.swift`) for better code organization and reusability.

This refactoring significantly improves the project's scalability, readability, and adherence to modern Swift/SwiftUI architectural patterns.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @peterfriese, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a comprehensive refactoring of the iOS project, aiming to enhance its modularity, maintainability, and scalability. The changes involve a complete overhaul of the project's directory structure, the introduction of a new templated content generation feature, and a significant upgrade to the user interface by adopting the ConversationKit framework. These improvements streamline development, centralize common components, and lay a robust foundation for future feature expansion.

Highlights

  • Project Structure Reorganization: The project codebase has been significantly refactored into Features (for feature-specific modules) and Shared (for common models, views, and utilities) directories, improving modularity and maintainability.
  • New 'Hello world (with template)' Feature: A new feature demonstrating server-side template generation using apple-qs-greeting has been added under Features/GenerativeAIText.
  • Enhanced UI/UX with ConversationKit: The UI components for chat and multimodal interactions have been migrated to use the ConversationKit framework, providing a more streamlined and feature-rich conversational interface.
  • Security and Best Practices: Insecure API key initialization has been replaced with a secure factory method, and shared UI components were moved to a centralized location to resolve compile errors and improve accessibility.
  • Centralized Backend Configuration: The BackendOption enum has been extracted into its own file for better organization and reusability across the application.
  • Updated Xcode Project Settings: The project's deployment target has been updated, and Swift Package Manager dependencies have been revised to align with the new modular structure and introduced frameworks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a significant and well-executed refactoring of the iOS project. The move to a feature-based architecture, centralization of shared components, and adoption of ConversationKit greatly improve the project's structure, maintainability, and scalability. The new Sample-driven approach for showcasing examples is also a fantastic improvement.

I've identified a couple of critical issues, primarily a merge conflict in a script and an invalid build setting, that must be addressed. I also have a high-severity suggestion regarding dependency pinning for better build stability and a medium-severity suggestion to improve the new navigation routing logic. Overall, this is excellent work.

Comment on lines 365 to 368
requirement = {
kind = revision;
revision = 7aff8d1b31148d32c5933d75557d42f6323ee3d1;
branch = main;
kind = branch;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The ConversationKit dependency is pinned to the main branch. This can lead to non-reproducible builds as the main branch can change at any time. It's recommended to pin dependencies to a specific version tag or commit hash to ensure build stability.

-            requirement = {
-                branch = main;
-                kind = branch;
-            };

Comment on lines +98 to 115
switch sample.navRoute {
case "ChatScreen":
ChatScreen(backendType: selectedBackend, sample: sample)
case "ImagenScreen":
ImagenScreen(backendType: selectedBackend, sample: sample)
case "ImagenFromTemplateScreen":
ImagenFromTemplateScreen(backendType: selectedBackend, sample: sample)
case "GenerateContentFromTemplateScreen":
GenerateContentFromTemplateScreen(backendType: selectedBackend, sample: sample)
case "MultimodalScreen":
MultimodalScreen(backendType: selectedBackend, sample: sample)
case "FunctionCallingScreen":
FunctionCallingScreen(backendType: selectedBackend, sample: sample)
case "GroundingScreen":
GroundingScreen(backendType: selectedBackend, sample: sample)
default:
EmptyView()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The navigation logic in destinationView(for:) relies on string matching for sample.navRoute. This is fragile and prone to typos. Consider using an enum for the navigation routes to make this more robust and type-safe.

For example:

// In Sample.swift
enum NavRoute {
    case chatScreen
    case imagenScreen
    // ... other cases
}

// In ContentView.swift
@ViewBuilder
private func destinationView(for sample: Sample) -> some View {
  switch sample.navRoute {
  case .chatScreen:
    ChatScreen(backendType: selectedBackend, sample: sample)
  // ... other cases
  }
}

@peterfriese peterfriese changed the title feat: Major Project Refactoring and New 'Hello World (with template)' Feature refactor: Modernize Project Structure and Refine Codebase Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants