# googleapis/google-api-php-client architecture

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

- Interactive diagram: https://gitdiagram.com/googleapis/google-api-php-client
- Repository: https://github.com/googleapis/google-api-php-client

## Overview

This is the Google APIs Client Library for PHP: application code configures a client and service, makes API operations, and receives response data as typed models. Its major capabilities include OAuth and service-account authentication, REST calls, batching, uploads, retry handling, and API service wrappers supplied by the separate google-api-php-client-services package. The graph uses documented workflow and sampled call references; relationships for unsampled token and REST internals are omitted rather than inferred.

Main entry points: [`src/Service/Resource.php`](https://github.com/googleapis/google-api-php-client/blob/main/src/Service/Resource.php) (Resource Calls), [`src/Client.php`](https://github.com/googleapis/google-api-php-client/blob/main/src/Client.php) (OAuth Tokens), [`src/Http/REST.php`](https://github.com/googleapis/google-api-php-client/blob/main/src/Http/REST.php) (REST Transport), [`src/Service.php`](https://github.com/googleapis/google-api-php-client/blob/main/src/Service.php) (Service Context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API Operations"]
  node_servicewrappers["Service Wrappers"]
  node_service["Service Context<br/>[Service.php]"]
  node_resource["Resource Calls<br/>[Resource.php]"]
  node_models["Response Models<br/>[Model.php]"]
  node_collection["Collections<br/>[Collection.php]"]
end

subgraph group_auth["Authentication"]
  node_oauth["OAuth Tokens<br/>[Client.php]"]
  node_tokenverify["ID Token Verify<br/>[Verify.php]"]
  node_tokenrevoke["Token Revoke<br/>[Revoke.php]"]
  node_authfactory["Auth Handler Factory"]
  node_guzzleauth["Guzzle Auth Handler"]
end

subgraph group_transport["HTTP Transport"]
  node_rest["REST Transport<br/>[REST.php]"]
  node_batch["Batch Requests<br/>[Batch.php]"]
  node_upload["Media Uploads"]
end

subgraph group_runtime["Runtime Support"]
  node_runner["Retry Runner<br/>[Runner.php]"]
  node_uritemplate["URI Templates<br/>[UriTemplate.php]"]
  node_composer["Service Cleanup<br/>[Composer.php]"]
end

node_developer(("Application Code"))
node_googleapis(("Google APIs"))

node_developer -->|"selects API"| node_servicewrappers
node_servicewrappers -.->|"uses client"| node_service
node_developer -->|"configures credentials"| node_oauth
node_oauth -->|"verifies ID tokens"| node_tokenverify
node_oauth -->|"revokes tokens"| node_tokenrevoke
node_oauth -.->|"builds handler"| node_authfactory
node_authfactory -->|"selects handler"| node_guzzleauth
node_service -->|"creates batch"| node_batch
node_servicewrappers -.->|"exposes operations"| node_resource
node_resource -->|"expands URI"| node_uritemplate
node_resource -->|"creates upload"| node_upload
node_resource -.->|"sends request"| node_rest
node_rest -.->|"retries requests"| node_runner
node_rest -.->|"calls API"| node_googleapis
node_batch -.->|"sends batch"| node_googleapis
node_upload -.->|"uploads media"| node_googleapis
node_googleapis -.->|"returns data"| node_models
node_models -->|"uses collections"| node_collection
node_developer -->|"cleans services"| node_composer

click node_service "https://github.com/googleapis/google-api-php-client/blob/main/src/Service.php"
click node_resource "https://github.com/googleapis/google-api-php-client/blob/main/src/Service/Resource.php"
click node_models "https://github.com/googleapis/google-api-php-client/blob/main/src/Model.php"
click node_collection "https://github.com/googleapis/google-api-php-client/blob/main/src/Collection.php"
click node_oauth "https://github.com/googleapis/google-api-php-client/blob/main/src/Client.php"
click node_tokenverify "https://github.com/googleapis/google-api-php-client/blob/main/src/AccessToken/Verify.php"
click node_tokenrevoke "https://github.com/googleapis/google-api-php-client/blob/main/src/AccessToken/Revoke.php"
click node_authfactory "https://github.com/googleapis/google-api-php-client/blob/main/src/AuthHandler/AuthHandlerFactory.php"
click node_guzzleauth "https://github.com/googleapis/google-api-php-client/blob/main/src/AuthHandler/Guzzle6AuthHandler.php"
click node_rest "https://github.com/googleapis/google-api-php-client/blob/main/src/Http/REST.php"
click node_batch "https://github.com/googleapis/google-api-php-client/blob/main/src/Http/Batch.php"
click node_upload "https://github.com/googleapis/google-api-php-client/blob/main/src/Http/MediaFileUpload.php"
click node_runner "https://github.com/googleapis/google-api-php-client/blob/main/src/Task/Runner.php"
click node_uritemplate "https://github.com/googleapis/google-api-php-client/blob/main/src/Utils/UriTemplate.php"
click node_composer "https://github.com/googleapis/google-api-php-client/blob/main/src/Task/Composer.php"

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_servicewrappers,node_service,node_resource,node_models,node_collection toneBlue
class node_oauth,node_tokenverify,node_tokenrevoke,node_authfactory,node_guzzleauth toneAmber
class node_rest,node_batch,node_upload,node_googleapis toneMint
class node_runner,node_uritemplate,node_composer toneRose
class node_developer toneIndigo
```

## Components

### API Operations

- **Service Wrappers**
- [Service Context](https://github.com/googleapis/google-api-php-client/blob/main/src/Service.php): `src/Service.php`
- [Resource Calls](https://github.com/googleapis/google-api-php-client/blob/main/src/Service/Resource.php): `src/Service/Resource.php`
- [Response Models](https://github.com/googleapis/google-api-php-client/blob/main/src/Model.php): `src/Model.php`
- [Collections](https://github.com/googleapis/google-api-php-client/blob/main/src/Collection.php): `src/Collection.php`

### Authentication

- [OAuth Tokens](https://github.com/googleapis/google-api-php-client/blob/main/src/Client.php): `src/Client.php`
- [ID Token Verify](https://github.com/googleapis/google-api-php-client/blob/main/src/AccessToken/Verify.php): `src/AccessToken/Verify.php`
- [Token Revoke](https://github.com/googleapis/google-api-php-client/blob/main/src/AccessToken/Revoke.php): `src/AccessToken/Revoke.php`
- [Auth Handler Factory](https://github.com/googleapis/google-api-php-client/blob/main/src/AuthHandler/AuthHandlerFactory.php): `src/AuthHandler/AuthHandlerFactory.php`
- [Guzzle Auth Handler](https://github.com/googleapis/google-api-php-client/blob/main/src/AuthHandler/Guzzle6AuthHandler.php): `src/AuthHandler/Guzzle6AuthHandler.php`

### HTTP Transport

- [REST Transport](https://github.com/googleapis/google-api-php-client/blob/main/src/Http/REST.php): `src/Http/REST.php`
- [Batch Requests](https://github.com/googleapis/google-api-php-client/blob/main/src/Http/Batch.php): `src/Http/Batch.php`
- [Media Uploads](https://github.com/googleapis/google-api-php-client/blob/main/src/Http/MediaFileUpload.php): `src/Http/MediaFileUpload.php`

### Runtime Support

- [Retry Runner](https://github.com/googleapis/google-api-php-client/blob/main/src/Task/Runner.php): `src/Task/Runner.php`
- [URI Templates](https://github.com/googleapis/google-api-php-client/blob/main/src/Utils/UriTemplate.php): `src/Utils/UriTemplate.php`
- [Service Cleanup](https://github.com/googleapis/google-api-php-client/blob/main/src/Task/Composer.php): `src/Task/Composer.php`

### Other components

- **Application Code**
- **Google APIs**

## Connections

- Application Code → Service Wrappers: selects API (evidence: `README.md`)
- Service Wrappers → Service Context: uses client
- Application Code → OAuth Tokens: configures credentials (evidence: `README.md`)
- OAuth Tokens → ID Token Verify: verifies ID tokens (evidence: `src/Client.php`)
- OAuth Tokens → Token Revoke: revokes tokens (evidence: `src/Client.php`)
- OAuth Tokens → Auth Handler Factory: builds handler (evidence: `src/Client.php`)
- Auth Handler Factory → Guzzle Auth Handler: selects handler (evidence: `src/AuthHandler/AuthHandlerFactory.php`)
- Service Context → Batch Requests: creates batch (evidence: `src/Service.php`)
- Service Wrappers → Resource Calls: exposes operations
- Resource Calls → URI Templates: expands URI (evidence: `src/Service/Resource.php`)
- Resource Calls → Media Uploads: creates upload (evidence: `src/Service/Resource.php`)
- Resource Calls → REST Transport: sends request
- REST Transport → Retry Runner: retries requests (evidence: `src/Http/REST.php`)
- REST Transport → Google APIs: calls API
- Batch Requests → Google APIs: sends batch
- Media Uploads → Google APIs: uploads media
- Google APIs → Response Models: returns data
- Response Models → Collections: uses collections (evidence: `src/Collection.php`)
- Application Code → Service Cleanup: cleans services (evidence: `README.md`)
