# kushalkumarj2006/colab-api architecture

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

- Interactive diagram: https://gitdiagram.com/kushalkumarj2006/colab-api
- Repository: https://github.com/kushalkumarj2006/colab-api

## Overview

This repository implements a FastAPI service for authorizing users and managing remote Google Colab runtimes. The main workflow obtains OAuth credentials, assigns a Colab runtime (optionally with a GPU or TPU), initializes a Jupyter kernel, and exposes runtime operations such as code execution and session keep-alive or deletion. The sampled source shows the authentication, assignment, kernel-creation, and lifecycle calls; the execution endpoint’s intervening code is omitted, so its connection to the runtime is shown as unverified.

Main entry points: [`main.py`](https://github.com/kushalkumarj2006/colab-api/blob/main/main.py) (FastAPI service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_service["FastAPI service<br/>[main.py]"]
end

subgraph group_auth["Authorization"]
  node_oauth["OAuth helpers<br/>[main.py]"]
  node_credentials["Credential refresh<br/>[main.py]"]
end

subgraph group_runtime["Remote runtime"]
  node_colab_client["Colab client<br/>[main.py]"]
  node_runtime_client["Runtime client<br/>[main.py]"]
  node_execution["Code execution<br/>[main.py]"]
end

node_client(("API client"))
node_google["Google OAuth"]
node_colab["Colab service"]
node_kernel["Jupyter kernel"]

node_client -->|"calls endpoints"| node_service
node_service -->|"requests auth URL"| node_oauth
node_service -->|"exchanges code"| node_oauth
node_oauth -->|"requests tokens"| node_google
node_service -->|"refreshes credentials"| node_credentials
node_service -->|"assigns runtime"| node_colab_client
node_colab_client -->|"sends requests"| node_colab
node_service -->|"creates kernel"| node_runtime_client
node_runtime_client -->|"creates kernel"| node_kernel
node_service -.->|"handles execution"| node_execution
node_execution -.->|"runs code"| node_runtime_client
node_service -->|"keeps alive"| node_colab_client
node_service -->|"unassigns runtime"| node_colab_client

click node_service "https://github.com/kushalkumarj2006/colab-api/blob/main/main.py"
click node_oauth "https://github.com/kushalkumarj2006/colab-api/blob/main/main.py"
click node_credentials "https://github.com/kushalkumarj2006/colab-api/blob/main/main.py"
click node_colab_client "https://github.com/kushalkumarj2006/colab-api/blob/main/main.py"
click node_runtime_client "https://github.com/kushalkumarj2006/colab-api/blob/main/main.py"
click node_execution "https://github.com/kushalkumarj2006/colab-api/blob/main/main.py"

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_service,node_client toneBlue
class node_oauth,node_credentials toneAmber
class node_colab_client,node_runtime_client,node_execution toneMint
class node_google,node_colab,node_kernel toneIndigo
```

## Components

### HTTP API

- [FastAPI service](https://github.com/kushalkumarj2006/colab-api/blob/main/main.py): `main.py`

### Authorization

- [OAuth helpers](https://github.com/kushalkumarj2006/colab-api/blob/main/main.py): `main.py`
- [Credential refresh](https://github.com/kushalkumarj2006/colab-api/blob/main/main.py): `main.py`

### Remote runtime

- [Colab client](https://github.com/kushalkumarj2006/colab-api/blob/main/main.py): `main.py`
- [Runtime client](https://github.com/kushalkumarj2006/colab-api/blob/main/main.py): `main.py`
- [Code execution](https://github.com/kushalkumarj2006/colab-api/blob/main/main.py): `main.py`

### Other components

- **API client**
- **Google OAuth**
- **Colab service**
- **Jupyter kernel**

## Connections

- API client → FastAPI service: calls endpoints (evidence: `main.py`)
- FastAPI service → OAuth helpers: requests auth URL (evidence: `main.py`)
- FastAPI service → OAuth helpers: exchanges code (evidence: `main.py`)
- OAuth helpers → Google OAuth: requests tokens (evidence: `main.py`)
- FastAPI service → Credential refresh: refreshes credentials (evidence: `main.py`)
- FastAPI service → Colab client: assigns runtime (evidence: `main.py`)
- Colab client → Colab service: sends requests (evidence: `main.py`)
- FastAPI service → Runtime client: creates kernel (evidence: `main.py`)
- Runtime client → Jupyter kernel: creates kernel (evidence: `main.py`)
- FastAPI service → Code execution: handles execution (evidence: `main.py`)
- Code execution → Runtime client: runs code (evidence: `main.py`)
- FastAPI service → Colab client: keeps alive (evidence: `main.py`)
- FastAPI service → Colab client: unassigns runtime (evidence: `main.py`)
