# jasmeetsb/google_generative_ai_samples architecture

> Architecture diagram of the GitHub repository jasmeetsb/google_generative_ai_samples, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jasmeetsb/google_generative_ai_samples
- Repository: https://github.com/jasmeetsb/google_generative_ai_samples

## Overview

##### Project Type and Purpose
- This repo is a collection of Generative AI sample apps and utilities. It includes:
- Interactive Flask UIs (chat‐flask‐cloudrun, dynamic_webpage)
- A Hugging Face model‐serving demo (model_serving/hf_model_serving)
- Jupyter notebooks for Doc AI + Palm API use cases
- Utility scripts for load tests and data conversion
- Purpose: demonstrate end‐to‐end GenAI workflows (document extraction, conversational AI) on GCP & HF.

##### File Structure
- Top‐level directories:
- Utilities: batch scripts, load testing, data conversion
- chat‐flask‐cloudrun: Flask chat UI, Dockerfile for Cloud Run
- dynamic_webpage: Another Flask demo, Dockerfile + Procfile (Heroku)
- model_serving/hf_model_serving: Flask server for local HF models
- sample_data: PDF assets for Doc AI
- Scratch: playground code
- Config files: Dockerfiles, Procfiles, requirements.txt → deployment targets: Cloud Run, Heroku, local.

##### Extract Architectural Insights from README
- Key GenAI components:
- Doc AI (GCP) for document ingestion
- Palm API (Vertex AI) for generative responses
- Notebooks illustrate orchestration of these services offline.

##### Main Components & Their Relationships
a. User Interfaces (Frontend)
- chat‐flask‐cloudrun: Web UI for conversational AI
- dynamic_webpage: Sample dynamic web UI
- Notebooks: serve as offline UIs for data scientists
b. Application Backends
- Flask apps (in each demo folder) accept HTTP requests, format prompts, call AI services
- model_serving/hf_model_serving: hosts HF models via REST
c. AI Services (External & Internal)
- Google Vertex AI Palm API (Generative AI)
- Google Doc AI (OCR & entity extraction)
- Hugging Face models (local or cloud) via custom server
d. Data Layer
- sample_data: PDFs are ingested by Doc AI
- No persistent database in samples—state is ephemeral in memory
e. Utility Scripts
- load_test.py, latency measurement notebooks: used to benchmark API latency
- csv_to_jsonl_converter.ipynb: data prep for fine‐tuning or evaluation

##### Architectural Patterns & Design Principles
- Microservices style: each demo lives in its own container
- Clear separation between UI, orchestration layer (Flask), and AI services
- Scalable deployments via Docker + Cloud Run / Heroku
- Extensible: new demos, new AI backends can be “dropped in” as separate services

##### Checklist
- [ ] Clear labels on all components (e.g., “chat‐flask‐cloudrun container,” “Vertex AI Palm API”)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Clients / Users
    subgraph "Clients / Users"
        Browser["Browser"]:::client
        subgraph "Data Science Notebooks"
            Note1["Vertex_GenAI_Entity_Extraction.ipynb"]:::notebook
            Note2["Vertex_GenAI_Entity_Extraction_Deeds.ipynb"]:::notebook
        end
        subgraph "Utility Notebooks"
            Note3["calculate_vertexai_llm_latency.ipynb"]:::notebook
            Note4["csv_to_jsonl_converter.ipynb"]:::notebook
            Note5["load_test_notebook.ipynb"]:::notebook
        end
        LoadTester["load_test.py"]:::utilityClient
    end

    %% Frontend Layer
    subgraph "Frontends" 
        direction TB
        subgraph "chat-flask-cloudrun Demo" 
            ChatApp["chat-flask-cloudrun/app.py"]:::frontend
            ChatDocker["Dockerfile.txt"]:::config
            ChatReq["requirements.txt"]:::config
            ChatIndex["templates/index.html"]:::frontend
            ChatCSS["static/style.css"]:::frontend
        end
        subgraph "dynamic_webpage Demo"
            DynApp["dynamic_webpage/app.py"]:::frontend
            DynDocker["Dockerfile"]:::config
            DynProc["Procfile"]:::config
            DynReq["requirements.txt"]:::config
            DynIndex["templates/index.html"]:::frontend
            DynCSS["static/style.css"]:::frontend
        end
    end

    %% Backend / Orchestration Layer
    subgraph "Model Serving Backend"
        direction TB
        HFApp["model_serving/hf_model_serving/app.py"]:::backend
        HFDocker["Dockerfile"]:::config
        HFProc["Procfile"]:::config
        HFReq["requirements.txt"]:::config
        HFIndex["templates/index.html"]:::backend
        HFCSS["static/style.css"]:::backend
    end

    %% AI Services Layer
    subgraph "AI Services"
        direction TB
        PalmAPI(("Vertex AI Palm API")):::ai
        DocAI(("Google Doc AI")):::ai
        HFServer(("HF Model Server")):::aiInternal
    end

    %% Data and Utilities Layer
    subgraph "Data / Utilities"
        direction TB
        PDF[(US_PTO_Sample.pdf)]:::data
        CSVConv["csv_to_jsonl_converter.ipynb"]:::utility
        LoadScript["Utilities/load_test.py"]:::utility
    end

    %% Connections
    Browser -->|"HTTP/REST JSON"| ChatApp
    Browser -->|"HTTP/REST JSON"| DynApp
    Note1 -->|"gRPC/JSON"| DocAI
    Note2 -->|"gRPC/JSON"| DocAI
    Note1 -->|"HTTP/REST JSON"| PalmAPI
    Note2 -->|"HTTP/REST JSON"| PalmAPI
    Note3 -->|"benchmark"| PalmAPI
    Note4 -->|"data prep"| CSVConv
    Note5 -->|"benchmark"| ChatApp
    LoadTester -->|"load test"| ChatApp
    LoadTester -->|"load test"| HFApp

    ChatApp -->|"HTTP/REST JSON"| PalmAPI
    DynApp -->|"HTTP/REST JSON"| PalmAPI
    HFApp -->|"HTTP/REST JSON"| HFServer

    DocAI -->|"PDF input"| PDF
    PDF -->|"OCR ingest"| DocAI

    %% Click Events
    click ChatApp "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/chat-flask-cloudrun/app.py"
    click ChatDocker "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/chat-flask-cloudrun/Dockerfile.txt"
    click ChatReq "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/chat-flask-cloudrun/requirements.txt"
    click ChatIndex "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/chat-flask-cloudrun/templates/index.html"
    click ChatCSS "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/chat-flask-cloudrun/static/style.css"
    click DynApp "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/dynamic_webpage/app.py"
    click DynDocker "https://github.com/jasmeetsb/google_generative_ai_samples/tree/main/dynamic_webpage/Dockerfile"
    click DynProc "https://github.com/jasmeetsb/google_generative_ai_samples/tree/main/dynamic_webpage/Procfile"
    click DynReq "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/dynamic_webpage/requirements.txt"
    click DynIndex "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/dynamic_webpage/templates/index.html"
    click DynCSS "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/dynamic_webpage/static/style.css"
    click HFApp "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/model_serving/hf_model_serving/app.py"
    click HFDocker "https://github.com/jasmeetsb/google_generative_ai_samples/tree/main/model_serving/hf_model_serving/Dockerfile"
    click HFProc "https://github.com/jasmeetsb/google_generative_ai_samples/tree/main/model_serving/hf_model_serving/Procfile"
    click HFReq "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/model_serving/hf_model_serving/requirements.txt"
    click HFIndex "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/model_serving/hf_model_serving/templates/index.html"
    click HFCSS "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/model_serving/hf_model_serving/static/style.css"
    click Note1 "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/Vertex_GenAI_Entity_Extraction.ipynb"
    click Note2 "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/Vertex_GenAI_Entity_Extraction_Deeds.ipynb"
    click Note3 "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/Utilities/calculate_vertexai_llm_latency.ipynb"
    click Note4 "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/Utilities/csv_to_jsonl_converter.ipynb"
    click Note5 "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/Utilities/load_test_notebook.ipynb"
    click LoadTester "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/Utilities/load_test.py"
    click CSVConv "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/Utilities/csv_to_jsonl_converter.ipynb"
    click PDF "https://github.com/jasmeetsb/google_generative_ai_samples/blob/main/sample_data/US_PTO_Sample.pdf"

    %% Styles
    classDef client fill:#e0f7fa,stroke:#006064,color:#006064
    classDef notebook fill:#e8eaf6,stroke:#283593,color:#283593
    classDef utilityClient fill:#fff3e0,stroke:#e65100,color:#e65100
    classDef frontend fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32
    classDef backend fill:#e3f2fd,stroke:#1565c0,color:#1565c0
    classDef ai fill:#f3e5f5,stroke:#6a1b9a,color:#6a1b9a
    classDef aiInternal fill:#f3e5f5,stroke:#4a148c,color:#4a148c
    classDef data fill:#fff8e1,stroke:#ff8f00,color:#ff8f00
    classDef utility fill:#fff3e0,stroke:#ef6c00,color:#ef6c00
    classDef config fill:#eceff1,stroke:#546e7a,color:#546e7a
```
