# gradio-app/gradio architecture

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

- Interactive diagram: https://gitdiagram.com/gradio-app/gradio
- Repository: https://github.com/gradio-app/gradio

## Overview

Gradio lets Python developers wrap functions or ML pipelines in component-based web apps, then launch them for browser use and optionally share them. The central path is app construction, server setup, browser input/API submission, function execution, and rendered output. The tree and README establish broader capabilities such as custom Blocks layouts, built-in components, queueing, sharing, and clients; sampled source confirms route handling, pipeline adaptation, and run-history storage controls. Some runtime wiring and several documented subsystems are represented only at their enclosing source paths because their implementations were not sampled.

Main entry points: [`gradio/routes.py`](https://github.com/gradio-app/gradio/blob/main/gradio/routes.py) (FastAPI server), [`gradio/blocks.py`](https://github.com/gradio-app/gradio/blob/main/gradio/blocks.py) (Blocks and Interface), [`gradio/pipelines.py`](https://github.com/gradio-app/gradio/blob/main/gradio/pipelines.py) (Pipeline adapter), [`gradio/block_function.py`](https://github.com/gradio-app/gradio/blob/main/gradio/block_function.py) (Function runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["App authoring"]
  node_appdef["Blocks and Interface<br/>[blocks.py]"]
  node_components["UI components"]
  node_chatinterface["ChatInterface<br/>[chat_interface.py]"]
  node_pipeline_adapter["Pipeline adapter<br/>[pipelines.py]"]
  node_pipeline_helpers["Pipeline mappings<br/>[pipelines_utils.py]"]
end

subgraph group_runtime["App runtime"]
  node_web_frontend["Browser frontend<br/>[+page.server.ts]"]
  node_proxy["Request proxy<br/>[proxy_routes.js]"]
  node_server["FastAPI server<br/>[routes.py]"]
  node_events["Event dispatch<br/>[events.py]"]
  node_queue["Queue execution<br/>[blocks.py]"]
  node_function_runner["Function runner<br/>[block_function.py]"]
  node_storage[("Cache and storage<br/>[caching.py]")]
end

subgraph group_integrations["Clients and integrations"]
  node_share_service{{"Public sharing service"}}
  node_python_client["Python client<br/>[client.py]"]
  node_js_client["JavaScript client<br/>[client.ts]"]
end

subgraph group_state["History and state"]
  node_history_ui["History controls"]
  node_history_api["Run history API<br/>[routes.py]"]
  node_history_store[("Run history state<br/>[routes.py]")]
end

node_developer(("App developer"))
node_browser(("App user"))
node_external_fn{{"App function or model"}}
node_hf_bucket[("Hugging Face bucket")]

node_developer -->|"defines app"| node_appdef
node_developer -->|"selects components"| node_components
node_appdef -->|"configures UI"| node_components
node_developer -->|"defines chat"| node_chatinterface
node_developer -->|"adapts pipeline"| node_pipeline_adapter
node_pipeline_adapter -->|"loads mappings"| node_pipeline_helpers
node_pipeline_adapter -->|"invokes pipeline"| node_external_fn
node_appdef -->|"launches app"| node_server
node_browser -->|"opens app"| node_web_frontend
node_web_frontend -->|"loads config"| node_server
node_browser -->|"submits input"| node_proxy
node_proxy -->|"routes API"| node_server
node_server -->|"dispatches event"| node_events
node_events -->|"enqueues work"| node_queue
node_queue -->|"runs event"| node_function_runner
node_function_runner -->|"calls function"| node_external_fn
node_function_runner -->|"formats outputs"| node_components
node_server -->|"returns response"| node_web_frontend
node_appdef -.->|"creates public link"| node_share_service
node_python_client -->|"calls endpoints"| node_server
node_js_client -->|"calls endpoints"| node_server
node_history_ui -->|"manages storage"| node_js_client
node_history_ui -->|"requests history"| node_history_api
node_history_api -->|"reads and writes"| node_history_store
node_js_client -->|"connects bucket"| node_hf_bucket

click node_appdef "https://github.com/gradio-app/gradio/blob/main/gradio/blocks.py"
click node_components "https://github.com/gradio-app/gradio/tree/main/gradio/components"
click node_chatinterface "https://github.com/gradio-app/gradio/blob/main/gradio/chat_interface.py"
click node_pipeline_adapter "https://github.com/gradio-app/gradio/blob/main/gradio/pipelines.py"
click node_pipeline_helpers "https://github.com/gradio-app/gradio/blob/main/gradio/pipelines_utils.py"
click node_web_frontend "https://github.com/gradio-app/gradio/blob/main/js/app/src/routes/%5B...catchall%5D/%2Bpage.server.ts"
click node_proxy "https://github.com/gradio-app/gradio/blob/main/js/app/proxy_routes.js"
click node_server "https://github.com/gradio-app/gradio/blob/main/gradio/routes.py"
click node_events "https://github.com/gradio-app/gradio/blob/main/gradio/events.py"
click node_queue "https://github.com/gradio-app/gradio/blob/main/gradio/blocks.py"
click node_function_runner "https://github.com/gradio-app/gradio/blob/main/gradio/block_function.py"
click node_storage "https://github.com/gradio-app/gradio/blob/main/gradio/caching.py"
click node_python_client "https://github.com/gradio-app/gradio/blob/main/client/python/gradio_client/client.py"
click node_js_client "https://github.com/gradio-app/gradio/blob/main/client/js/src/client.ts"
click node_history_ui "https://github.com/gradio-app/gradio/blob/main/js/core/src/api_docs/HistoryStorageControl.svelte"
click node_history_api "https://github.com/gradio-app/gradio/blob/main/gradio/routes.py"
click node_history_store "https://github.com/gradio-app/gradio/blob/main/gradio/routes.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_appdef,node_components,node_chatinterface,node_pipeline_adapter,node_pipeline_helpers,node_browser toneBlue
class node_web_frontend,node_proxy,node_server,node_events,node_queue,node_function_runner,node_storage,node_hf_bucket toneAmber
class node_share_service,node_python_client,node_js_client toneMint
class node_history_ui,node_history_api,node_history_store toneRose
class node_developer,node_external_fn toneIndigo
```

## Components

### App authoring

- [Blocks and Interface](https://github.com/gradio-app/gradio/blob/main/gradio/blocks.py): `gradio/blocks.py`
- [UI components](https://github.com/gradio-app/gradio/tree/main/gradio/components): `gradio/components`
- [ChatInterface](https://github.com/gradio-app/gradio/blob/main/gradio/chat_interface.py): `gradio/chat_interface.py`
- [Pipeline adapter](https://github.com/gradio-app/gradio/blob/main/gradio/pipelines.py): `gradio/pipelines.py`
- [Pipeline mappings](https://github.com/gradio-app/gradio/blob/main/gradio/pipelines_utils.py): `gradio/pipelines_utils.py`

### App runtime

- [Browser frontend](https://github.com/gradio-app/gradio/blob/main/js/app/src/routes/%5B...catchall%5D/%2Bpage.server.ts): `js/app/src/routes/[...catchall]/+page.server.ts`
- [Request proxy](https://github.com/gradio-app/gradio/blob/main/js/app/proxy_routes.js): `js/app/proxy_routes.js`
- [FastAPI server](https://github.com/gradio-app/gradio/blob/main/gradio/routes.py): `gradio/routes.py`
- [Event dispatch](https://github.com/gradio-app/gradio/blob/main/gradio/events.py): `gradio/events.py`
- [Queue execution](https://github.com/gradio-app/gradio/blob/main/gradio/blocks.py): `gradio/blocks.py`
- [Function runner](https://github.com/gradio-app/gradio/blob/main/gradio/block_function.py): `gradio/block_function.py`
- [Cache and storage](https://github.com/gradio-app/gradio/blob/main/gradio/caching.py): `gradio/caching.py`

### Clients and integrations

- **Public sharing service**
- [Python client](https://github.com/gradio-app/gradio/blob/main/client/python/gradio_client/client.py): `client/python/gradio_client/client.py`
- [JavaScript client](https://github.com/gradio-app/gradio/blob/main/client/js/src/client.ts): `client/js/src/client.ts`

### History and state

- [History controls](https://github.com/gradio-app/gradio/blob/main/js/core/src/api_docs/HistoryStorageControl.svelte): `js/core/src/api_docs/HistoryStorageControl.svelte`
- [Run history API](https://github.com/gradio-app/gradio/blob/main/gradio/routes.py): `gradio/routes.py`
- [Run history state](https://github.com/gradio-app/gradio/blob/main/gradio/routes.py): `gradio/routes.py`

### Other components

- **App developer**
- **App user**
- **App function or model**
- **Hugging Face bucket**

## Connections

- App developer → Blocks and Interface: defines app
- App developer → UI components: selects components
- Blocks and Interface → UI components: configures UI
- App developer → ChatInterface: defines chat
- App developer → Pipeline adapter: adapts pipeline
- Pipeline adapter → Pipeline mappings: loads mappings
- Pipeline adapter → App function or model: invokes pipeline
- Blocks and Interface → FastAPI server: launches app
- App user → Browser frontend: opens app
- Browser frontend → FastAPI server: loads config
- App user → Request proxy: submits input
- Request proxy → FastAPI server: routes API
- FastAPI server → Event dispatch: dispatches event
- Event dispatch → Queue execution: enqueues work
- Queue execution → Function runner: runs event
- Function runner → App function or model: calls function
- Function runner → UI components: formats outputs
- FastAPI server → Browser frontend: returns response
- Blocks and Interface → Public sharing service: creates public link
- Python client → FastAPI server: calls endpoints
- JavaScript client → FastAPI server: calls endpoints
- History controls → JavaScript client: manages storage
- History controls → Run history API: requests history
- Run history API → Run history state: reads and writes
- JavaScript client → Hugging Face bucket: connects bucket
