# priyanshunegi-work/cloud-run-assignment architecture

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

- Interactive diagram: https://gitdiagram.com/priyanshunegi-work/cloud-run-assignment
- Repository: https://github.com/priyanshunegi-work/cloud-run-assignment

## Overview

##### Project type and purpose
- This is a containerized Python Flask web service, deployed in a serverless fashion on Google Cloud Run.
- Its purpose is to demonstrate containerization, cloud‐native deployment, and simple system health checks via a Bash script.

##### File structure
- Top‐level artifacts:
- README.md – overview and deployment instructions
- sys_check.sh – standalone health‐check script (disk usage, login history)
- `deploy_app/` folder:
- main.py – Flask application entry point
- requirements.txt – Python dependencies (Flask, Gunicorn)
- Dockerfile – instructions to build the container image
- log.txt – placeholder or sample application log file

##### Extract key architectural hints from the README
- Containerization with Docker
- Image storage in Google Artifact Registry
- Deployment to Cloud Run (fully managed, serverless)
- Uses gcloud CLI for deployment

##### Main components & their roles
a. Developer workstation / CI pipeline
- Holds the source code (`deploy_app/` + `sys_check.sh`) and Dockerfile
- Triggers a Docker build (either locally or via Cloud Build)
b. Container image
- Built from `deploy_app/Dockerfile`, includes Flask app + Gunicorn
c. Artifact Registry (us-central1-docker.pkg.dev)
- Stores the built container image
d. Google Cloud Run
- Pulls the image from Artifact Registry
- Runs containers on demand, scales automatically
- Exposes an HTTPS endpoint to clients
e. Clients
- Web browsers or API clients consuming the Flask service
f. Health‐check script (`sys_check.sh`)
- External monitoring tool, can run on a VM or local cron
- Checks disk usage, login history—reports or logs results

##### Relationships & data flows
- Code → Docker build → Image pushed → Artifact Registry
- Artifact Registry → Cloud Run deployment → Running service
- Client HTTP(S) requests → Cloud Run → Container (Flask + Gunicorn) → Response
- sys_check.sh → (optionally) invokes Cloud Run endpoint or queries VM to perform health checks

##### Architectural patterns & design principles
- Serverless microservice (single‐purpose container)
- Separation of concerns: build pipeline vs. runtime
- Immutable infrastructure: containers are rebuilt & redeployed
- Infrastructure as code: Dockerfile + gcloud CLI commands

##### Relevant technologies & frameworks
- Python 3.x, Flask, Gunicorn
- Docker
- Google Cloud Build (optional), Artifact Registry
- Google Cloud Run (fully managed)
- Bash (sys_check.sh)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source & Build Stage
    subgraph "Source & Build" 
        direction TB
        Dev["Developer Workstation / CI Pipeline"]:::dev
        README["README.md"]:::doc
        subgraph "Application Code"
            direction TB
            Main["main.py\n(Flask App)"]:::compute
            Req["requirements.txt"]:::compute
            Log["log.txt"]:::compute
        end
        DockerBuild["Docker Build"]:::dev
    end

    %% Artifact Storage
    subgraph "Artifact Storage"
        direction TB
        Registry["Artifact Registry\n(us-central1)"]:::registry
    end

    %% Runtime Stage
    subgraph "Runtime Environment"
        direction TB
        CloudRun["Cloud Run Service\n(HTTPS Endpoint)"]:::runtime
        Container["Container Runtime\n(Flask + Gunicorn)"]:::runtime
        Clients["Clients\n(Web Browsers / API Clients)"]:::client
    end

    %% Monitoring
    SysCheck["sys_check.sh\n(Health Check Script)"]:::script

    %% Connections
    Dev -->|includes code & Dockerfile| Main
    Dev -->|includes requirements| Req
    Dev -->|includes sample logs| Log
    Main --> DockerBuild
    Req --> DockerBuild
    Log --> DockerBuild
    DockerBuild -->|docker build & push| Registry
    Registry -->|gcloud run deploy| CloudRun
    CloudRun --> Container
    Clients -->|HTTPS GET/POST| CloudRun
    CloudRun -->|HTTPS Response| Clients
    SysCheck -.->|invokes endpoint| CloudRun

    %% Click Events
    click Main "https://github.com/priyanshunegi-work/cloud-run-assignment/blob/main/deploy_app/main.py"
    click Req "https://github.com/priyanshunegi-work/cloud-run-assignment/blob/main/deploy_app/requirements.txt"
    click Log "https://github.com/priyanshunegi-work/cloud-run-assignment/blob/main/deploy_app/log.txt"
    click DockerBuild "https://github.com/priyanshunegi-work/cloud-run-assignment/tree/main/deploy_app/Dockerfile"
    click README "https://github.com/priyanshunegi-work/cloud-run-assignment/blob/main/README.md"
    click SysCheck "https://github.com/priyanshunegi-work/cloud-run-assignment/blob/main/sys_check.sh"

    %% Styles
    classDef dev fill:#FFE5B4,stroke:#E69138,stroke-width:2px
    classDef registry fill:#D5E8D4,stroke:#82B366,stroke-width:2px
    classDef runtime fill:#DAE8FC,stroke:#6C8EBF,stroke-width:2px
    classDef compute fill:#F8CECC,stroke:#B85450,stroke-width:2px
    classDef client fill:#FFF2CC,stroke:#D6B656,stroke-width:2px
    classDef script fill:#E1D5E7,stroke:#9673A6,stroke-width:2px
    classDef doc fill:#F5F5F5,stroke:#CCCCCC,stroke-width:2px
```
