# rudradudhat2509/gemma4-starter architecture

> Architecture diagram of the GitHub repository rudradudhat2509/gemma4-starter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rudradudhat2509/gemma4-starter
- Repository: https://github.com/rudradudhat2509/gemma4-starter

## Overview

Gemma 4 Starter is both a set of runnable learning examples and a copyable Gradio app foundation. The principal app workflow takes a user question—with an optional image—through the app’s handler to Gemma, or through an agent that can dispatch model-requested tools and return their results. The shared client handles model requests, chat and image inputs, caching, and call limits. The README also documents standalone examples for system instructions and function calling. Edges are limited to relationships visible in the excerpts or README; unsampled implementation details are not inferred.

Main entry points: [`gemma_client.py`](https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py) (Gemma client), [`app_template/app.py`](https://github.com/rudradudhat2509/gemma4-starter/blob/main/app_template/app.py) (Gradio app), [`harness/agent.py`](https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/agent.py) (Agent loop), [`harness/tools.py`](https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/tools.py) (Built-in tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Starter app"]
  node_app_ui["Gradio app<br/>[app.py]"]
end

subgraph group_model["Gemma access"]
  node_gemma_client["Gemma client<br/>[gemma_client.py]"]
  node_text_calls["Text generation<br/>[gemma_client.py]"]
  node_image_calls["Image questions<br/>[gemma_client.py]"]
  node_chat_memory["Chat memory<br/>[gemma_client.py]"]
  node_cache[("Response cache<br/>[gemma_client.py]")]
  node_usage[("Usage counter<br/>[gemma_client.py]")]
end

subgraph group_agent["Tool agent"]
  node_agent["Agent loop<br/>[agent.py]"]
  node_tool_registry["Tool registry<br/>[tools.py]"]
  node_built_in_tools["Built-in tools<br/>[tools.py]"]
  node_notes[("Notes file<br/>[tools.py]")]
end

subgraph group_examples["Learning examples"]
  node_hello["First request<br/>[01_hello.py]"]
  node_instructions["System instructions"]
  node_chat_example["Chat example<br/>[03_chat.py]"]
  node_image_example["Image example<br/>[04_image.py]"]
  node_function_example["Function calling"]
end

node_user(("App user"))
node_gemini{{"Gemini API"}}

node_user -->|"asks"| node_app_ui
node_app_ui -->|"asks about image"| node_image_calls
node_app_ui -->|"asks text"| node_text_calls
node_app_ui -->|"runs agent"| node_agent
node_image_calls -->|"delegates to"| node_gemma_client
node_text_calls -->|"delegates to"| node_gemma_client
node_agent -->|"generates with"| node_gemma_client
node_agent -->|"gets declarations"| node_tool_registry
node_agent -->|"runs requested"| node_built_in_tools
node_built_in_tools -->|"appends note"| node_notes
node_gemma_client -->|"calls API"| node_gemini
node_gemma_client -->|"reads and writes"| node_cache
node_gemma_client -->|"records calls"| node_usage
node_hello -->|"asks text"| node_gemma_client
node_instructions -->|"asks with rules"| node_gemma_client
node_chat_example -->|"starts chat"| node_gemma_client
node_image_example -->|"asks with image"| node_gemma_client
node_function_example -->|"requests generation"| node_gemma_client

click node_app_ui "https://github.com/rudradudhat2509/gemma4-starter/blob/main/app_template/app.py"
click node_gemma_client "https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py"
click node_text_calls "https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py"
click node_image_calls "https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py"
click node_chat_memory "https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py"
click node_cache "https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py"
click node_usage "https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py"
click node_agent "https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/agent.py"
click node_tool_registry "https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/tools.py"
click node_built_in_tools "https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/tools.py"
click node_notes "https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/tools.py"
click node_hello "https://github.com/rudradudhat2509/gemma4-starter/blob/main/01_hello.py"
click node_instructions "https://github.com/rudradudhat2509/gemma4-starter/blob/main/02_system_instruction.py"
click node_chat_example "https://github.com/rudradudhat2509/gemma4-starter/blob/main/03_chat.py"
click node_image_example "https://github.com/rudradudhat2509/gemma4-starter/blob/main/04_image.py"
click node_function_example "https://github.com/rudradudhat2509/gemma4-starter/blob/main/05_function_calling.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_ui,node_user toneBlue
class node_gemma_client,node_text_calls,node_image_calls,node_chat_memory,node_cache,node_usage toneAmber
class node_agent,node_tool_registry,node_built_in_tools,node_notes,node_gemini toneMint
class node_hello,node_instructions,node_chat_example,node_image_example,node_function_example toneRose
```

## Components

### Starter app

- [Gradio app](https://github.com/rudradudhat2509/gemma4-starter/blob/main/app_template/app.py): `app_template/app.py`

### Gemma access

- [Gemma client](https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py): `gemma_client.py`
- [Text generation](https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py): `gemma_client.py`
- [Image questions](https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py): `gemma_client.py`
- [Chat memory](https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py): `gemma_client.py`
- [Response cache](https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py): `gemma_client.py`
- [Usage counter](https://github.com/rudradudhat2509/gemma4-starter/blob/main/gemma_client.py): `gemma_client.py`

### Tool agent

- [Agent loop](https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/agent.py): `harness/agent.py`
- [Tool registry](https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/tools.py): `harness/tools.py`
- [Built-in tools](https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/tools.py): `harness/tools.py`
- [Notes file](https://github.com/rudradudhat2509/gemma4-starter/blob/main/harness/tools.py): `harness/tools.py`

### Learning examples

- [First request](https://github.com/rudradudhat2509/gemma4-starter/blob/main/01_hello.py): `01_hello.py`
- [System instructions](https://github.com/rudradudhat2509/gemma4-starter/blob/main/02_system_instruction.py): `02_system_instruction.py`
- [Chat example](https://github.com/rudradudhat2509/gemma4-starter/blob/main/03_chat.py): `03_chat.py`
- [Image example](https://github.com/rudradudhat2509/gemma4-starter/blob/main/04_image.py): `04_image.py`
- [Function calling](https://github.com/rudradudhat2509/gemma4-starter/blob/main/05_function_calling.py): `05_function_calling.py`

### Other components

- **App user**
- **Gemini API**

## Connections

- App user → Gradio app: asks (evidence: `app_template/app.py`)
- Gradio app → Image questions: asks about image (evidence: `app_template/app.py`)
- Gradio app → Text generation: asks text (evidence: `app_template/app.py`)
- Gradio app → Agent loop: runs agent (evidence: `app_template/app.py`)
- Image questions → Gemma client: delegates to (evidence: `app_template/app.py`)
- Text generation → Gemma client: delegates to (evidence: `app_template/app.py`)
- Agent loop → Gemma client: generates with (evidence: `harness/agent.py`)
- Agent loop → Tool registry: gets declarations (evidence: `harness/agent.py`)
- Agent loop → Built-in tools: runs requested (evidence: `harness/agent.py`)
- Built-in tools → Notes file: appends note (evidence: `harness/tools.py`)
- Gemma client → Gemini API: calls API (evidence: `gemma_client.py`)
- Gemma client → Response cache: reads and writes (evidence: `gemma_client.py`)
- Gemma client → Usage counter: records calls (evidence: `gemma_client.py`)
- First request → Gemma client: asks text (evidence: `01_hello.py`)
- System instructions → Gemma client: asks with rules (evidence: `02_system_instruction.py`)
- Chat example → Gemma client: starts chat (evidence: `03_chat.py`)
- Image example → Gemma client: asks with image (evidence: `04_image.py`)
- Function calling → Gemma client: requests generation (evidence: `05_function_calling.py`)
