# xai-org/grok-build architecture

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

- Interactive diagram: https://gitdiagram.com/xai-org/grok-build
- Repository: https://github.com/xai-org/grok-build
- Video tour (about a minute): https://gitdiagram.com/xai-org/grok-build/video

## Overview

Grok Build is a terminal AI coding agent. A user submits a request through the full-screen TUI; the shell runtime and agent assemble context, authenticate, call the model, and invoke tools for code search, file edits, terminal commands, and workspace operations. Results stream back through agent state and markdown rendering to the TUI. The tree and README establish major capabilities, but several composition-root call sites were not sampled, so optional subsystem links are conservative.

Main entry points: [`crates/codegen/xai-grok-agent/src/agent.rs`](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-agent/src/agent.rs) (Agent Runtime), [`crates/codegen/xai-grok-pager`](https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-pager) (Terminal TUI), [`crates/codegen/xai-grok-tools`](https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-tools) (Agent Tools), [`crates/codegen/xai-grok-shell`](https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-shell) (Shell Runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_tui["Terminal TUI"]
  node_markdown["Markdown Renderer<br/>[lib.rs]"]
end

subgraph group_agent["Agent Runtime"]
  node_shell["Shell Runtime"]
  node_agent_runtime["Agent Runtime<br/>[agent.rs]"]
  node_prompt["Prompt Context<br/>[mod.rs]"]
  node_workflow["Workflow Engine<br/>[engine.rs]"]
end

subgraph group_workspace["Workspace Operations"]
  node_tools["Agent Tools"]
  node_workspace_ops["Workspace Host"]
  node_terminal["PTY Terminal<br/>[lib.rs]"]
  node_code_graph["Codebase Graph<br/>[lib.rs]"]
end

subgraph group_integrations["External Integrations"]
  node_auth["Authentication<br/>[lib.rs]"]
  node_mcp["MCP Integration<br/>[lib.rs]"]
  node_voice["Voice Pipeline<br/>[pipeline.rs]"]
  node_model_api["xAI Model API"]
end

subgraph group_state["State and Persistence"]
  node_chat_state["Chat State<br/>[lib.rs]"]
  node_memory["Markdown Memory<br/>[storage.rs]"]
end

node_user(("Developer"))
node_editor(("Editor Client"))
node_local_files["Local Files"]
node_mcp_servers["MCP Servers"]

node_user -->|"submits request"| node_tui
node_tui -->|"dispatches input"| node_shell
node_editor -.->|"sends ACP request"| node_shell
node_tui -->|"renders output"| node_markdown
node_shell -->|"starts agent"| node_agent_runtime
node_agent_runtime -->|"builds context"| node_prompt
node_agent_runtime -->|"updates state"| node_chat_state
node_agent_runtime -->|"sends prompt"| node_model_api
node_model_api -->|"returns response"| node_agent_runtime
node_agent_runtime -->|"invokes tools"| node_tools
node_tools -->|"edits workspace"| node_workspace_ops
node_tools -->|"runs commands"| node_terminal
node_tools -->|"searches code"| node_code_graph
node_workspace_ops -->|"reads and writes"| node_local_files
node_terminal -->|"executes locally"| node_local_files
node_agent_runtime -->|"gets credentials"| node_auth
node_auth -->|"authorizes access"| node_model_api
node_agent_runtime -->|"reads and writes"| node_memory
node_agent_runtime -->|"runs workflows"| node_workflow
node_workflow -->|"spawns agents"| node_agent_runtime
node_tools -.->|"calls tools"| node_mcp
node_mcp -.->|"dispatches requests"| node_mcp_servers
node_tui -.->|"controls capture"| node_voice
node_voice -.->|"returns transcript"| node_tui
node_agent_runtime -->|"streams results"| node_tui
node_chat_state -->|"provides events"| node_tui

click node_tui "https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-pager"
click node_markdown "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-markdown/src/lib.rs"
click node_shell "https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-shell"
click node_agent_runtime "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-agent/src/agent.rs"
click node_prompt "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-agent/src/prompt/mod.rs"
click node_workflow "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-workflow/src/engine.rs"
click node_tools "https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-tools"
click node_workspace_ops "https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-workspace"
click node_terminal "https://github.com/xai-org/grok-build/blob/main/crates/codegen/ptyctl/src/lib.rs"
click node_code_graph "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-codebase-graph/src/lib.rs"
click node_auth "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-login/src/lib.rs"
click node_mcp "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-mcp/src/lib.rs"
click node_voice "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-voice/src/pipeline.rs"
click node_chat_state "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-chat-state/src/lib.rs"
click node_memory "https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-memory/src/storage.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_tui,node_markdown,node_editor toneBlue
class node_shell,node_agent_runtime,node_prompt,node_workflow toneAmber
class node_tools,node_workspace_ops,node_terminal,node_code_graph,node_mcp_servers toneMint
class node_auth,node_mcp,node_voice,node_model_api toneRose
class node_chat_state,node_memory,node_user,node_local_files toneIndigo
```

## Components

### User Interface

- [Terminal TUI](https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-pager): `crates/codegen/xai-grok-pager`
- [Markdown Renderer](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-markdown/src/lib.rs): `crates/codegen/xai-grok-markdown/src/lib.rs`

### Agent Runtime

- [Shell Runtime](https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-shell): `crates/codegen/xai-grok-shell`
- [Agent Runtime](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-agent/src/agent.rs): `crates/codegen/xai-grok-agent/src/agent.rs`
- [Prompt Context](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-agent/src/prompt/mod.rs): `crates/codegen/xai-grok-agent/src/prompt/mod.rs`
- [Workflow Engine](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-workflow/src/engine.rs): `crates/codegen/xai-workflow/src/engine.rs`

### Workspace Operations

- [Agent Tools](https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-tools): `crates/codegen/xai-grok-tools`
- [Workspace Host](https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-workspace): `crates/codegen/xai-grok-workspace`
- [PTY Terminal](https://github.com/xai-org/grok-build/blob/main/crates/codegen/ptyctl/src/lib.rs): `crates/codegen/ptyctl/src/lib.rs`
- [Codebase Graph](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-codebase-graph/src/lib.rs): `crates/codegen/xai-codebase-graph/src/lib.rs`

### External Integrations

- [Authentication](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-login/src/lib.rs): `crates/codegen/xai-grok-login/src/lib.rs`
- [MCP Integration](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-mcp/src/lib.rs): `crates/codegen/xai-grok-mcp/src/lib.rs`
- [Voice Pipeline](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-voice/src/pipeline.rs): `crates/codegen/xai-grok-voice/src/pipeline.rs`
- **xAI Model API**

### State and Persistence

- [Chat State](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-chat-state/src/lib.rs): `crates/codegen/xai-chat-state/src/lib.rs`
- [Markdown Memory](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-memory/src/storage.rs): `crates/codegen/xai-grok-memory/src/storage.rs`

### Other components

- **Developer**
- **Editor Client**
- **Local Files**
- **MCP Servers**

## Connections

- Developer → Terminal TUI: submits request
- Terminal TUI → Shell Runtime: dispatches input
- Editor Client → Shell Runtime: sends ACP request
- Terminal TUI → Markdown Renderer: renders output
- Shell Runtime → Agent Runtime: starts agent
- Agent Runtime → Prompt Context: builds context
- Agent Runtime → Chat State: updates state
- Agent Runtime → xAI Model API: sends prompt
- xAI Model API → Agent Runtime: returns response
- Agent Runtime → Agent Tools: invokes tools
- Agent Tools → Workspace Host: edits workspace
- Agent Tools → PTY Terminal: runs commands
- Agent Tools → Codebase Graph: searches code
- Workspace Host → Local Files: reads and writes
- PTY Terminal → Local Files: executes locally
- Agent Runtime → Authentication: gets credentials
- Authentication → xAI Model API: authorizes access
- Agent Runtime → Markdown Memory: reads and writes
- Agent Runtime → Workflow Engine: runs workflows
- Workflow Engine → Agent Runtime: spawns agents
- Agent Tools → MCP Integration: calls tools
- MCP Integration → MCP Servers: dispatches requests
- Terminal TUI → Voice Pipeline: controls capture
- Voice Pipeline → Terminal TUI: returns transcript
- Agent Runtime → Terminal TUI: streams results
- Chat State → Terminal TUI: provides events
