# geshan/ollama-cloud-run architecture

> Architecture diagram of the GitHub repository geshan/ollama-cloud-run, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/geshan/ollama-cloud-run
- Repository: https://github.com/geshan/ollama-cloud-run

## Overview

##### Main Components

a) Client Layer:
- HTTP Clients (cURL or other API consumers)
- REST API endpoints (/api/generate)

b) Google Cloud Platform Layer:
- Cloud Run Service (Primary Component)
- Container Instance(s) with specifications:
- 32GB RAM
- 8 vCPUs
- OLLAMA_NUM_PARALLEL=4
- Cloud Build
- Artifact Registry

c) Model Layer:
- Ollama Runtime
- Gemma 9B Model

##### Flow Representation

**[Development] → [Build/Deploy] → [Runtime]**

**Development:**
- GitHub Repository
- ↓
**Build/Deploy:**
- Cloud Build → Artifact Registry
- ↓
**Runtime:**
- Client → Cloud Run → Ollama → Gemma Model

##### Important Details to Highlight

- Container Specifications:
- Resource allocations
- Concurrent request limit (4)
- Timeout setting (600s)

- Scaling Configuration:
- Min/max instances (≥4)
- CPU always allocated
- Startup CPU boost enabled

##### Data Flow Patterns

- Two distinct paths:
- Streaming response flow
- Non-streaming response flow

##### Performance Indicators

- Average response time: ~7.73s (as per README example)
- Image size: 5.4GB

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        HTTP[HTTP Clients]
        API["/api/generate"]
    end

    %% GCP Layer
    subgraph "Google Cloud Platform"
        direction TB
        subgraph "Build Pipeline"
            direction TB
            CB[Cloud Build]:::gcp
            AR[(Artifact Registry)]:::gcp
        end

        subgraph "Cloud Run Service"
            direction TB
            CR[Cloud Run]:::gcp
            subgraph "Container Instance"
                direction TB
                CONFIG["Container Config
                32GB RAM | 8 vCPUs
                OLLAMA_NUM_PARALLEL=4
                Timeout: 600s"]:::config
                OLLAMA[Ollama Runtime]:::runtime
                GEMMA[Gemma 9B Model]:::model
            end
        end
    end

    %% Flow Connections
    HTTP --> API
    API --> CR
    CB --> AR
    AR --> CR
    CR --> OLLAMA
    OLLAMA --> GEMMA

    %% Performance Metrics
    subgraph "Performance"
        METRICS["Avg Response: ~7.73s
        Image Size: 5.4GB"]:::metrics
    end

    %% Component Mappings with Click Events
    click CONFIG "https://github.com/geshan/ollama-cloud-run/tree/master/Dockerfile"
    click CB "https://github.com/geshan/ollama-cloud-run/blob/master/cloudbuild.yaml"
    click METRICS "https://github.com/geshan/ollama-cloud-run/blob/master/README.md"

    %% Styling
    classDef gcp fill:#4285F4,color:white
    classDef runtime fill:#34A853,color:white
    classDef model fill:#FBBC05,color:white
    classDef config fill:#EA4335,color:white
    classDef metrics fill:#gray,color:black

    %% Legend
    subgraph Legend
        L1[GCP Services]:::gcp
        L2[Runtime Components]:::runtime
        L3[Model Components]:::model
        L4[Configuration]:::config
    end
```
