# glotlabs/gdrive architecture

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

- Interactive diagram: https://gitdiagram.com/glotlabs/gdrive
- Repository: https://github.com/glotlabs/gdrive

## Overview

gdrive is a command-line client for Google Drive. Users configure or import an account, then invoke commands for file and folder operations, Drive listing, and permission management. Those command handlers obtain an authenticated Drive hub and perform API requests; file transfer also includes local tree traversal, metadata preparation, and retry-aware chunk uploads. Account management and archive export/import form a separate credential lifecycle. The graph reflects documented capabilities and relationships visible in the excerpts or source index; several unsampled handlers are represented by their exact enclosing directories.

Main entry points: [`src/files/upload.rs`](https://github.com/glotlabs/gdrive/blob/main/src/files/upload.rs) (Upload and download), [`src/common/hub_helper.rs`](https://github.com/glotlabs/gdrive/blob/main/src/common/hub_helper.rs) (Hub setup), [`src/files`](https://github.com/glotlabs/gdrive/tree/main/src/files) (File commands), [`src/main.rs`](https://github.com/glotlabs/gdrive/blob/main/src/main.rs) (Command dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI entry"]
  node_commands["Command dispatch<br/>[main.rs]"]
end

subgraph group_accounts["Account lifecycle"]
  node_account_cmd["Account commands"]
  node_account_config[("Account config<br/>[app_config.rs]")]
  node_account_archive["Account archives<br/>[account_archive.rs]"]
end

subgraph group_drive["Drive operations"]
  node_files_cmd["File commands"]
  node_file_transfer["Upload and download<br/>[upload.rs]"]
  node_file_info["File metadata<br/>[info.rs]"]
  node_file_listing["Search and list<br/>[list.rs]"]
  node_drive_tree["Drive tree traversal<br/>[file_tree_drive.rs]"]
  node_local_tree["Local tree traversal<br/>[file_tree.rs]"]
  node_drives["Drive listing<br/>[list.rs]"]
  node_permissions["Permission commands"]
end

subgraph group_support["Shared runtime"]
  node_auth["OAuth and hub<br/>[hub.rs]"]
  node_hub_helper["Hub setup<br/>[hub_helper.rs]"]
  node_file_types["Drive file types<br/>[drive_file.rs]"]
  node_permission_model["Permission model<br/>[permission.rs]"]
  node_upload_retry["Chunk retry support<br/>[delegate.rs]"]
  node_table["Table formatting<br/>[table.rs]"]
end

node_user(("CLI user"))
node_google_drive{{"Google Drive API"}}
node_local_files[("Local files")]

node_user -->|"runs commands"| node_commands
node_commands -->|"dispatches account"| node_account_cmd
node_commands -->|"dispatches files"| node_files_cmd
node_commands -->|"dispatches drives"| node_drives
node_commands -->|"dispatches permissions"| node_permissions
node_account_cmd -->|"manages accounts"| node_account_config
node_account_cmd -->|"imports and exports"| node_account_archive
node_account_cmd -->|"starts OAuth"| node_auth
node_account_config -->|"persists credentials"| node_local_files
node_hub_helper -->|"loads account"| node_account_config
node_hub_helper -->|"creates hub"| node_auth
node_files_cmd -->|"dispatches transfers"| node_file_transfer
node_files_cmd -->|"dispatches metadata"| node_file_info
node_files_cmd -->|"dispatches listing"| node_file_listing
node_files_cmd -.->|"operates on"| node_google_drive
node_file_transfer -->|"obtains hub"| node_hub_helper
node_file_transfer -->|"gets file details"| node_file_info
node_file_transfer -->|"builds upload tree"| node_local_tree
node_file_transfer -->|"walks remote tree"| node_drive_tree
node_file_transfer -->|"configures retries"| node_upload_retry
node_file_transfer -->|"transfers files"| node_google_drive
node_file_transfer -->|"reads and writes"| node_local_files
node_file_info -->|"obtains hub"| node_hub_helper
node_file_info -->|"fetches metadata"| node_google_drive
node_file_listing -->|"obtains hub"| node_hub_helper
node_file_listing -->|"queries files"| node_google_drive
node_file_listing -->|"formats results"| node_table
node_drive_tree -->|"lists children"| node_file_listing
node_drive_tree -.->|"reads remote tree"| node_google_drive
node_local_tree -.->|"scans paths"| node_local_files
node_files_cmd -.->|"uses file metadata"| node_file_types
node_drives -->|"obtains hub"| node_hub_helper
node_drives -.->|"lists drives"| node_google_drive
node_drives -->|"formats results"| node_table
node_permissions -.->|"obtains hub"| node_hub_helper
node_permissions -.->|"manages sharing"| node_google_drive
node_permissions -->|"matches permissions"| node_permission_model

click node_commands "https://github.com/glotlabs/gdrive/blob/main/src/main.rs"
click node_account_cmd "https://github.com/glotlabs/gdrive/tree/main/src/account"
click node_account_config "https://github.com/glotlabs/gdrive/blob/main/src/app_config.rs"
click node_account_archive "https://github.com/glotlabs/gdrive/blob/main/src/common/account_archive.rs"
click node_auth "https://github.com/glotlabs/gdrive/blob/main/src/hub.rs"
click node_hub_helper "https://github.com/glotlabs/gdrive/blob/main/src/common/hub_helper.rs"
click node_files_cmd "https://github.com/glotlabs/gdrive/tree/main/src/files"
click node_file_transfer "https://github.com/glotlabs/gdrive/blob/main/src/files/upload.rs"
click node_file_info "https://github.com/glotlabs/gdrive/blob/main/src/files/info.rs"
click node_file_listing "https://github.com/glotlabs/gdrive/blob/main/src/files/list.rs"
click node_drive_tree "https://github.com/glotlabs/gdrive/blob/main/src/common/file_tree_drive.rs"
click node_local_tree "https://github.com/glotlabs/gdrive/blob/main/src/common/file_tree.rs"
click node_file_types "https://github.com/glotlabs/gdrive/blob/main/src/common/drive_file.rs"
click node_drives "https://github.com/glotlabs/gdrive/blob/main/src/drives/list.rs"
click node_permissions "https://github.com/glotlabs/gdrive/tree/main/src/permissions"
click node_permission_model "https://github.com/glotlabs/gdrive/blob/main/src/common/permission.rs"
click node_upload_retry "https://github.com/glotlabs/gdrive/blob/main/src/common/delegate.rs"
click node_table "https://github.com/glotlabs/gdrive/blob/main/src/common/table.rs"

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_commands,node_user toneBlue
class node_account_cmd,node_account_config,node_account_archive,node_local_files toneAmber
class node_files_cmd,node_file_transfer,node_file_info,node_file_listing,node_drive_tree,node_local_tree,node_drives,node_permissions,node_google_drive toneMint
class node_auth,node_hub_helper,node_file_types,node_permission_model,node_upload_retry,node_table toneRose
```

## Components

### CLI entry

- [Command dispatch](https://github.com/glotlabs/gdrive/blob/main/src/main.rs): `src/main.rs`

### Account lifecycle

- [Account commands](https://github.com/glotlabs/gdrive/tree/main/src/account): `src/account`
- [Account config](https://github.com/glotlabs/gdrive/blob/main/src/app_config.rs): `src/app_config.rs`
- [Account archives](https://github.com/glotlabs/gdrive/blob/main/src/common/account_archive.rs): `src/common/account_archive.rs`

### Drive operations

- [File commands](https://github.com/glotlabs/gdrive/tree/main/src/files): `src/files`
- [Upload and download](https://github.com/glotlabs/gdrive/blob/main/src/files/upload.rs): `src/files/upload.rs`
- [File metadata](https://github.com/glotlabs/gdrive/blob/main/src/files/info.rs): `src/files/info.rs`
- [Search and list](https://github.com/glotlabs/gdrive/blob/main/src/files/list.rs): `src/files/list.rs`
- [Drive tree traversal](https://github.com/glotlabs/gdrive/blob/main/src/common/file_tree_drive.rs): `src/common/file_tree_drive.rs`
- [Local tree traversal](https://github.com/glotlabs/gdrive/blob/main/src/common/file_tree.rs): `src/common/file_tree.rs`
- [Drive listing](https://github.com/glotlabs/gdrive/blob/main/src/drives/list.rs): `src/drives/list.rs`
- [Permission commands](https://github.com/glotlabs/gdrive/tree/main/src/permissions): `src/permissions`

### Shared runtime

- [OAuth and hub](https://github.com/glotlabs/gdrive/blob/main/src/hub.rs): `src/hub.rs`
- [Hub setup](https://github.com/glotlabs/gdrive/blob/main/src/common/hub_helper.rs): `src/common/hub_helper.rs`
- [Drive file types](https://github.com/glotlabs/gdrive/blob/main/src/common/drive_file.rs): `src/common/drive_file.rs`
- [Permission model](https://github.com/glotlabs/gdrive/blob/main/src/common/permission.rs): `src/common/permission.rs`
- [Chunk retry support](https://github.com/glotlabs/gdrive/blob/main/src/common/delegate.rs): `src/common/delegate.rs`
- [Table formatting](https://github.com/glotlabs/gdrive/blob/main/src/common/table.rs): `src/common/table.rs`

### Other components

- **CLI user**
- **Google Drive API**
- **Local files**

## Connections

- CLI user → Command dispatch: runs commands
- Command dispatch → Account commands: dispatches account
- Command dispatch → File commands: dispatches files
- Command dispatch → Drive listing: dispatches drives (evidence: `src/main.rs`)
- Command dispatch → Permission commands: dispatches permissions
- Account commands → Account config: manages accounts (evidence: `src/account/add.rs`)
- Account commands → Account archives: imports and exports (evidence: `src/account/export.rs`)
- Account commands → OAuth and hub: starts OAuth (evidence: `src/account/add.rs`)
- Account config → Local files: persists credentials (evidence: `src/app_config.rs`)
- Hub setup → Account config: loads account (evidence: `src/common/hub_helper.rs`)
- Hub setup → OAuth and hub: creates hub (evidence: `src/common/hub_helper.rs`)
- File commands → Upload and download: dispatches transfers (evidence: `src/files.rs`)
- File commands → File metadata: dispatches metadata (evidence: `src/files.rs`)
- File commands → Search and list: dispatches listing (evidence: `src/files.rs`)
- File commands → Google Drive API: operates on
- Upload and download → Hub setup: obtains hub (evidence: `src/files/upload.rs`)
- Upload and download → File metadata: gets file details (evidence: `src/files/upload.rs`)
- Upload and download → Local tree traversal: builds upload tree (evidence: `src/files/upload.rs`)
- Upload and download → Drive tree traversal: walks remote tree
- Upload and download → Chunk retry support: configures retries (evidence: `src/files/upload.rs`)
- Upload and download → Google Drive API: transfers files (evidence: `src/files/upload.rs`)
- Upload and download → Local files: reads and writes
- File metadata → Hub setup: obtains hub (evidence: `src/files/info.rs`)
- File metadata → Google Drive API: fetches metadata (evidence: `src/files/info.rs`)
- Search and list → Hub setup: obtains hub (evidence: `src/files/list.rs`)
- Search and list → Google Drive API: queries files (evidence: `src/files/list.rs`)
- Search and list → Table formatting: formats results (evidence: `src/files/list.rs`)
- Drive tree traversal → Search and list: lists children (evidence: `src/common/file_tree_drive.rs`)
- Drive tree traversal → Google Drive API: reads remote tree (evidence: `src/common/file_tree_drive.rs`)
- Local tree traversal → Local files: scans paths (evidence: `src/common/file_tree.rs`)
- File commands → Drive file types: uses file metadata (evidence: `src/common/drive_file.rs`)
- Drive listing → Hub setup: obtains hub (evidence: `src/drives/list.rs`)
- Drive listing → Google Drive API: lists drives
- Drive listing → Table formatting: formats results (evidence: `src/drives/list.rs`)
- Permission commands → Hub setup: obtains hub (evidence: `src/permissions/revoke.rs`)
- Permission commands → Google Drive API: manages sharing
- Permission commands → Permission model: matches permissions (evidence: `src/permissions/revoke.rs`)
