# hemanth-yamsani/serverless-image-processing-gcp architecture

> Architecture diagram of the GitHub repository hemanth-yamsani/serverless-image-processing-gcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hemanth-yamsani/serverless-image-processing-gcp
- Repository: https://github.com/hemanth-yamsani/serverless-image-processing-gcp

## Overview

#### Purpose and entry points
This repository provisions a fully serverless GCP image-processing pipeline with Terraform. Deployment enters through the root Terraform configuration (`providers.tf`, `backend.tf`, `variables.tf`); runtime entry points are the two Python Cloud Functions: `src/main.py` and `src-notification/main.py`.

#### Infrastructure composition
Terraform creates the storage, messaging, functions, triggers, and required platform enablement:
- GCS input/output buckets and object-finalize notification: `gcs-buckets.tf`
- Upload and resize-success Pub/Sub topics: `pubsub.tf`
- Required GCP APIs and dependency timing: `apis.tf`, `time-delay.tf`
- Gen2 function deployments and Eventarc wiring: `cloud-function.tf`, `notification-function.tf`

Source deployment artifacts are represented by `CreateThumbnail.zip` and `CreateNotification.zip`, with corresponding unpacked source directories.

#### Ingestion and processing flow
An image upload enters the input Cloud Storage bucket. Its `OBJECT_FINALIZE` notification publishes to the upload-event Pub/Sub topic. Eventarc delivers that event to the image-resizing Gen2 function configured in `cloud-function.tf`.

The processing function in `src/main.py` decodes the incoming CloudEvent/Pub/Sub payload, downloads the referenced GCS object, uses Pillow to resize it to 50%, writes the derived image to the output bucket, then publishes a success JSON event. Python dependencies, including image-processing/runtime libraries, are defined in `src/requirements.txt`.

#### Notification flow
The success topic separates image processing from downstream notification concerns. The notification Gen2 function deployment is defined in `notification-function.tf`; its runtime handler is `src-notification/main.py`.

This function decodes the resize-success message and emits a structured Cloud Logging record. Its dependencies are isolated in `src-notification/requirements.txt`. This boundary allows new delivery channels such as webhooks or chat/email integrations without coupling them to the resize function.

#### Security and execution identities
Both functions run under a dedicated service account rather than a default runtime identity. Account creation and least-privilege access bindings are defined in `iam-service-account.tf` and `iam-policy-bindings.tf`, covering GCS read/write, Pub/Sub publishing, and logging. Platform service-agent permissions needed by Cloud Functions, Eventarc, and related managed services are handled in `service-agent-iam.tf`.

#### Runtime and external services
Material runtime is Python 3.11 on Cloud Functions Gen2, backed by Cloud Run revisions. External managed services are Google Cloud Storage, Pub/Sub, Eventarc, Cloud Logging, Cloud Build/function deployment infrastructure, IAM, and Terraform’s Google provider. Project, region, bucket names, and topic names are parameterized through `variables.tf` and the deployer-supplied `terraform.tfvars` derived from `terraform.tfvars.example`.

Main entry points: [`cloud-function.tf`](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/cloud-function.tf) (Resize function deployment), [`providers.tf`](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/providers.tf) (Terraform root), [`notification-function.tf`](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/notification-function.tf) (Notification deployment), [`iam-service-account.tf`](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/iam-service-account.tf) (Function service account)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_infra["Terraform deployment"]
  node_terraform["Terraform root<br/>IaC entrypoint<br/>[providers.tf]"]
  node_platform_apis["GCP API enablement<br/>Terraform resources<br/>[apis.tf]"]
  node_storage[("GCS buckets<br/>Cloud Storage<br/>[gcs-buckets.tf]")]
  node_runtime_sa["Function service account<br/>IAM service account"]
  node_iam_bindings["Runtime IAM bindings<br/>IAM policy"]
  node_service_agent_iam["Service-agent IAM<br/>IAM policy"]
  node_cloud_run["Cloud Run revisions<br/>Gen2 runtime"]
end

subgraph group_processing["Image processing"]
  node_upload_topic["Upload event topic<br/>Pub/Sub topic<br/>[pubsub.tf]"]
  node_eventarc{{"Eventarc trigger<br/>event routing<br/>[cloud-function.tf]"}}
  node_resize_deploy["Resize function deployment<br/>Gen2 Cloud Function<br/>[cloud-function.tf]"]
  node_resize_source["Resize handler<br/>Python 3.11<br/>[main.py]"]
  node_resize_dependencies["Resize dependencies<br/>Python requirements<br/>[requirements.txt]"]
  node_resize_artifact["Resize artifact<br/>deployment ZIP"]
end

subgraph group_notification["Notifications"]
  node_success_topic["Resize success topic<br/>Pub/Sub topic<br/>[pubsub.tf]"]
  node_notification_deploy["Notification deployment<br/>Gen2 Cloud Function"]
  node_notification_source["Notification handler<br/>Python 3.11<br/>[main.py]"]
  node_notification_dependencies["Notification dependencies<br/>Python requirements<br/>[requirements.txt]"]
  node_notification_artifact["Notification artifact<br/>deployment ZIP"]
  node_cloud_logging[("Cloud Logging<br/>managed logging")]
end

node_terraform -->|"enables"| node_platform_apis
node_terraform -->|"provisions"| node_storage
node_terraform -->|"provisions"| node_upload_topic
node_terraform -->|"provisions"| node_success_topic
node_terraform -->|"creates"| node_runtime_sa
node_runtime_sa -->|"receives access"| node_iam_bindings
node_platform_apis -.->|"managed services require"| node_service_agent_iam
node_storage -->|"OBJECT_FINALIZE publishes"| node_upload_topic
node_upload_topic -->|"upload event"| node_eventarc
node_eventarc -->|"invokes"| node_resize_deploy
node_resize_artifact -->|"deployment source"| node_resize_deploy
node_resize_source -->|"packaged as"| node_resize_artifact
node_resize_dependencies -->|"runtime libraries"| node_resize_source
node_resize_deploy -->|"runs on"| node_cloud_run
node_resize_deploy -->|"executes as"| node_runtime_sa
node_resize_deploy -->|"reads input / writes output"| node_storage
node_resize_deploy -->|"publishes success"| node_success_topic
node_success_topic -->|"triggers"| node_notification_deploy
node_notification_artifact -->|"deployment source"| node_notification_deploy
node_notification_source -->|"packaged as"| node_notification_artifact
node_notification_dependencies -->|"runtime libraries"| node_notification_source
node_notification_deploy -->|"runs on"| node_cloud_run
node_notification_deploy -->|"executes as"| node_runtime_sa
node_notification_deploy -->|"writes structured record"| node_cloud_logging

click node_terraform "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/providers.tf"
click node_platform_apis "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/apis.tf"
click node_storage "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/gcs-buckets.tf"
click node_upload_topic "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/pubsub.tf"
click node_eventarc "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/cloud-function.tf"
click node_resize_deploy "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/cloud-function.tf"
click node_resize_source "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/src/main.py"
click node_resize_dependencies "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/src/requirements.txt"
click node_resize_artifact "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/CreateThumbnail.zip"
click node_success_topic "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/pubsub.tf"
click node_notification_deploy "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/notification-function.tf"
click node_notification_source "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/src-notification/main.py"
click node_notification_dependencies "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/src-notification/requirements.txt"
click node_notification_artifact "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/CreateNotification.zip"
click node_runtime_sa "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/iam-service-account.tf"
click node_iam_bindings "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/iam-policy-bindings.tf"
click node_service_agent_iam "https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/service-agent-iam.tf"

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_terraform,node_platform_apis,node_storage,node_runtime_sa,node_iam_bindings,node_service_agent_iam,node_cloud_run toneBlue
class node_upload_topic,node_eventarc,node_resize_deploy,node_resize_source,node_resize_dependencies,node_resize_artifact toneAmber
class node_success_topic,node_notification_deploy,node_notification_source,node_notification_dependencies,node_notification_artifact,node_cloud_logging toneMint
```

## Components

### Terraform deployment

Serverless GCP resources and permissions.

- [Terraform root](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/providers.tf): IaC entrypoint · Configures provider, backend, variables, and deployment inputs. · `providers.tf`
- [GCP API enablement](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/apis.tf): Terraform resources · Platform APIs and dependency delay. · `apis.tf`
- [GCS buckets](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/gcs-buckets.tf): Cloud Storage · Input and derived-image output buckets. · `gcs-buckets.tf`
- [Function service account](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/iam-service-account.tf): IAM service account · Dedicated least-privilege runtime identity. · `iam-service-account.tf`
- [Runtime IAM bindings](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/iam-policy-bindings.tf): IAM policy · Grants storage, Pub/Sub publishing, and logging access. · `iam-policy-bindings.tf`
- [Service-agent IAM](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/service-agent-iam.tf): IAM policy · Permissions for Cloud Functions, Eventarc, and managed services. · `service-agent-iam.tf`
- **Cloud Run revisions**: Gen2 runtime · Execution substrate for both functions.

### Image processing

Upload-to-thumbnail runtime path.

- [Upload event topic](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/pubsub.tf): Pub/Sub topic · `pubsub.tf`
- [Eventarc trigger](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/cloud-function.tf): event routing · Routes upload events to the resize function. · `cloud-function.tf`
- [Resize function deployment](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/cloud-function.tf): Gen2 Cloud Function · Deploys the image-processing function and its trigger. · `cloud-function.tf`
- [Resize handler](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/src/main.py): Python 3.11 · Decodes events, resizes images with Pillow, and publishes success. · `src/main.py`
- [Resize dependencies](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/src/requirements.txt): Python requirements · `src/requirements.txt`
- [Resize artifact](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/CreateThumbnail.zip): deployment ZIP · `CreateThumbnail.zip`

### Notifications

Post-processing event consumer.

- [Resize success topic](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/pubsub.tf): Pub/Sub topic · Decouples processing from notification delivery. · `pubsub.tf`
- [Notification deployment](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/notification-function.tf): Gen2 Cloud Function · Deploys the success-event consumer. · `notification-function.tf`
- [Notification handler](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/src-notification/main.py): Python 3.11 · Logs structured resize-success records. · `src-notification/main.py`
- [Notification dependencies](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/src-notification/requirements.txt): Python requirements · `src-notification/requirements.txt`
- [Notification artifact](https://github.com/hemanth-yamsani/serverless-image-processing-gcp/blob/main/CreateNotification.zip): deployment ZIP · `CreateNotification.zip`
- **Cloud Logging**: managed logging

## Connections

- Terraform root → GCP API enablement: enables
- Terraform root → GCS buckets: provisions
- Terraform root → Upload event topic: provisions
- Terraform root → Resize success topic: provisions
- Terraform root → Function service account: creates
- Function service account → Runtime IAM bindings: receives access
- GCP API enablement → Service-agent IAM: managed services require
- GCS buckets → Upload event topic: OBJECT_FINALIZE publishes
- Upload event topic → Eventarc trigger: upload event
- Eventarc trigger → Resize function deployment: invokes
- Resize artifact → Resize function deployment: deployment source
- Resize handler → Resize artifact: packaged as
- Resize dependencies → Resize handler: runtime libraries
- Resize function deployment → Cloud Run revisions: runs on
- Resize function deployment → Function service account: executes as
- Resize function deployment → GCS buckets: reads input / writes output
- Resize function deployment → Resize success topic: publishes success
- Resize success topic → Notification deployment: triggers
- Notification artifact → Notification deployment: deployment source
- Notification handler → Notification artifact: packaged as
- Notification dependencies → Notification handler: runtime libraries
- Notification deployment → Cloud Run revisions: runs on
- Notification deployment → Function service account: executes as
- Notification deployment → Cloud Logging: writes structured record
