# yhdf/zerogravity architecture

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

- Interactive diagram: https://gitdiagram.com/yhdf/zerogravity
- Repository: https://github.com/yhdf/zerogravity

## Overview

ZeroGravity is a Gemini-Web-backed code-generation service: OpenWebUI requests enter a FastAPI router, which obtains Gemini output through a browser bridge, extracts and validates files and commands, applies them to a workspace, and records turn telemetry. The README documents the overall handoff and optional Ollama stage; sampled excerpts show the bridge and workspace/history implementations. Some router internals are omitted, so edges for those documented handoffs cite the README rather than implying the missing code was inspected.

Main entry points: [`services/router/src/app.py`](https://github.com/yhdf/zerogravity/blob/main/services/router/src/app.py) (Router API), [`services/browser_bridge/server.py`](https://github.com/yhdf/zerogravity/blob/main/services/browser_bridge/server.py) (Bridge API), [`services/browser_bridge/gemini_automator.py`](https://github.com/yhdf/zerogravity/blob/main/services/browser_bridge/gemini_automator.py) (Gemini Automation), [`services/router/src/browser_extractor.py`](https://github.com/yhdf/zerogravity/blob/main/services/router/src/browser_extractor.py) (Response Extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Request Routing"]
  node_router_api["Router API<br/>[app.py]"]
  node_meta_interceptor["Meta-task Interceptor<br/>[app.py]"]
end

subgraph group_generation["Gemini Generation"]
  node_browser_bridge_api["Bridge API<br/>[server.py]"]
  node_browser_automation["Gemini Automation"]
  node_gemini_web["Gemini Web"]
end

subgraph group_processing["Extraction and Validation"]
  node_response_extraction["Response Extraction"]
  node_file_validation["File and Command Validation"]
  node_ollama["Ollama"]
end

subgraph group_effects["Workspace and History"]
  node_workspace_router["Workspace Operations<br/>[mcp_workspace.py]"]
  node_target_workspace["Target Workspace"]
  node_command_runner["Command Execution<br/>[mcp_workspace.py]"]
  node_turn_history["Turn Archive<br/>[history_manager.py]"]
  node_history_index["History Index<br/>[history_manager.py]"]
end

node_openwebui(("OpenWebUI"))

node_openwebui -->|"submits chat"| node_router_api
node_router_api -->|"filters meta-tasks"| node_meta_interceptor
node_router_api -->|"requests generation"| node_browser_bridge_api
node_browser_bridge_api -->|"delegates prompts"| node_browser_automation
node_browser_automation -->|"sends prompt"| node_gemini_web
node_gemini_web -->|"streams response"| node_browser_automation
node_browser_automation -->|"returns output"| node_browser_bridge_api
node_browser_bridge_api -->|"returns raw text"| node_router_api
node_router_api -->|"extracts chunks"| node_response_extraction
node_response_extraction -->|"checks outputs"| node_file_validation
node_response_extraction -.->|"optionally synthesizes"| node_ollama
node_router_api -->|"writes files"| node_workspace_router
node_workspace_router -->|"stores files"| node_target_workspace
node_router_api -->|"runs commands"| node_command_runner
node_command_runner -->|"uses workspace cwd"| node_target_workspace
node_router_api -->|"records turns"| node_turn_history
node_turn_history -->|"updates index"| node_history_index
node_router_api -->|"returns result"| node_openwebui

click node_router_api "https://github.com/yhdf/zerogravity/blob/main/services/router/src/app.py"
click node_meta_interceptor "https://github.com/yhdf/zerogravity/blob/main/services/router/src/app.py"
click node_browser_bridge_api "https://github.com/yhdf/zerogravity/blob/main/services/browser_bridge/server.py"
click node_browser_automation "https://github.com/yhdf/zerogravity/blob/main/services/browser_bridge/gemini_automator.py"
click node_response_extraction "https://github.com/yhdf/zerogravity/blob/main/services/router/src/browser_extractor.py"
click node_file_validation "https://github.com/yhdf/zerogravity/blob/main/services/router/src/browser_extractor.py"
click node_workspace_router "https://github.com/yhdf/zerogravity/blob/main/services/router/src/mcp_workspace.py"
click node_command_runner "https://github.com/yhdf/zerogravity/blob/main/services/router/src/mcp_workspace.py"
click node_turn_history "https://github.com/yhdf/zerogravity/blob/main/services/router/src/history_manager.py"
click node_history_index "https://github.com/yhdf/zerogravity/blob/main/services/router/src/history_manager.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_router_api,node_meta_interceptor,node_openwebui toneBlue
class node_browser_bridge_api,node_browser_automation,node_gemini_web toneAmber
class node_response_extraction,node_file_validation,node_ollama toneMint
class node_workspace_router,node_target_workspace,node_command_runner,node_turn_history,node_history_index toneRose
```

## Components

### Request Routing

- [Router API](https://github.com/yhdf/zerogravity/blob/main/services/router/src/app.py): `services/router/src/app.py`
- [Meta-task Interceptor](https://github.com/yhdf/zerogravity/blob/main/services/router/src/app.py): `services/router/src/app.py`

### Gemini Generation

- [Bridge API](https://github.com/yhdf/zerogravity/blob/main/services/browser_bridge/server.py): `services/browser_bridge/server.py`
- [Gemini Automation](https://github.com/yhdf/zerogravity/blob/main/services/browser_bridge/gemini_automator.py): `services/browser_bridge/gemini_automator.py`
- **Gemini Web**

### Extraction and Validation

- [Response Extraction](https://github.com/yhdf/zerogravity/blob/main/services/router/src/browser_extractor.py): `services/router/src/browser_extractor.py`
- [File and Command Validation](https://github.com/yhdf/zerogravity/blob/main/services/router/src/browser_extractor.py): `services/router/src/browser_extractor.py`
- **Ollama**

### Workspace and History

- [Workspace Operations](https://github.com/yhdf/zerogravity/blob/main/services/router/src/mcp_workspace.py): `services/router/src/mcp_workspace.py`
- **Target Workspace**
- [Command Execution](https://github.com/yhdf/zerogravity/blob/main/services/router/src/mcp_workspace.py): `services/router/src/mcp_workspace.py`
- [Turn Archive](https://github.com/yhdf/zerogravity/blob/main/services/router/src/history_manager.py): `services/router/src/history_manager.py`
- [History Index](https://github.com/yhdf/zerogravity/blob/main/services/router/src/history_manager.py): `services/router/src/history_manager.py`

### Other components

- **OpenWebUI**

## Connections

- OpenWebUI → Router API: submits chat (evidence: `README.md`)
- Router API → Meta-task Interceptor: filters meta-tasks (evidence: `README.md`)
- Router API → Bridge API: requests generation (evidence: `services/router/src/app.py`)
- Bridge API → Gemini Automation: delegates prompts (evidence: `services/browser_bridge/server.py`)
- Gemini Automation → Gemini Web: sends prompt (evidence: `services/browser_bridge/gemini_automator.py`)
- Gemini Web → Gemini Automation: streams response (evidence: `README.md`)
- Gemini Automation → Bridge API: returns output (evidence: `services/browser_bridge/server.py`)
- Bridge API → Router API: returns raw text (evidence: `services/router/src/app.py`)
- Router API → Response Extraction: extracts chunks (evidence: `README.md`)
- Response Extraction → File and Command Validation: checks outputs (evidence: `services/router/src/browser_extractor.py`)
- Response Extraction → Ollama: optionally synthesizes (evidence: `services/router/src/browser_extractor.py`)
- Router API → Workspace Operations: writes files (evidence: `services/router/src/app.py`)
- Workspace Operations → Target Workspace: stores files (evidence: `services/router/src/mcp_workspace.py`)
- Router API → Command Execution: runs commands (evidence: `README.md`)
- Command Execution → Target Workspace: uses workspace cwd (evidence: `services/router/src/mcp_workspace.py`)
- Router API → Turn Archive: records turns (evidence: `README.md`)
- Turn Archive → History Index: updates index (evidence: `services/router/src/history_manager.py`)
- Router API → OpenWebUI: returns result (evidence: `README.md`)
