# edwin-metcalf/metcode architecture

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

- Interactive diagram: https://gitdiagram.com/edwin-metcalf/metcode
- Repository: https://github.com/edwin-metcalf/metcode

## Overview

MetCode is a local terminal coding assistant: the user selects an Ollama model, enters a prompt, and receives a response after the agent coordinates any requested tools. Tool calls cover sandboxed file operations, confirmed shell commands, and multi-step plans; slash commands manage model choice and saved conversations. Startup loads the customizable system prompt. The graph reflects the shown wiring and README-described capabilities; unsampled implementation details are represented only where documented.

Main entry points: [`internal/ui/ui.go`](https://github.com/edwin-metcalf/metcode/blob/main/internal/ui/ui.go) (Interactive CLI), [`internal/ollama/ollama.go`](https://github.com/edwin-metcalf/metcode/blob/main/internal/ollama/ollama.go) (Ollama HTTP client), [`internal/agent/agent.go`](https://github.com/edwin-metcalf/metcode/blob/main/internal/agent/agent.go) (Turn and tool loop), [`internal/tools/tools.go`](https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/tools.go) (Tool dispatcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["CLI runtime"]
  node_entry["Startup wiring<br/>[main.go]"]
  node_cli["Interactive CLI<br/>[ui.go]"]
  node_slash["Slash commands<br/>[commands.go]"]
  node_spinner["Request spinner<br/>[spinner.go]"]
end

subgraph group_assistant["Agent and model"]
  node_agent["Turn and tool loop<br/>[agent.go]"]
  node_ollama["Ollama HTTP client<br/>[ollama.go]"]
end

subgraph group_tools["Workspace tools"]
  node_definitions["Tool definitions<br/>[definitions.go]"]
  node_dispatch["Tool dispatcher<br/>[tools.go]"]
  node_file_ops["Sandboxed file tools<br/>[files.go]"]
  node_command["Confirmed commands<br/>[command.go]"]
end

subgraph group_state["Plans and conversations"]
  node_plan_tools["Plan operations<br/>[planhelpers.go]"]
  node_plan_model["Plan step types<br/>[plan.go]"]
  node_conversation[("Conversation storage<br/>[conversation.go]")]
end

subgraph group_config["Prompt configuration"]
  node_prompt["System prompt loader<br/>[prompt.go]"]
end

node_user(("Terminal user"))
node_ollama_service(("Ollama server"))
node_prompt_file["Custom prompt file"]

node_user -->|"launches"| node_entry
node_entry -->|"loads prompt"| node_prompt
node_prompt -->|"loads or creates"| node_prompt_file
node_entry -->|"starts"| node_cli
node_cli -->|"reads prompts"| node_user
node_cli -->|"submits turn"| node_agent
node_cli -->|"routes commands"| node_slash
node_cli -->|"uses while waiting"| node_spinner
node_slash -->|"lists models"| node_ollama
node_slash -->|"saves and loads"| node_conversation
node_agent -->|"sends chat"| node_ollama
node_ollama -->|"calls chat API"| node_ollama_service
node_ollama_service -->|"returns response"| node_ollama
node_agent -->|"advertises tools"| node_definitions
node_agent -->|"dispatches calls"| node_dispatch
node_dispatch -->|"dispatches file calls"| node_file_ops
node_dispatch -->|"dispatches command"| node_command
node_dispatch -->|"dispatches plan calls"| node_plan_tools
node_plan_tools -->|"updates plan items"| node_plan_model
node_ollama -->|"lists models"| node_ollama_service
node_user -->|"approves edits"| node_file_ops
node_user -->|"approves execution"| node_command

click node_entry "https://github.com/edwin-metcalf/metcode/blob/main/cmd/metcode/main.go"
click node_cli "https://github.com/edwin-metcalf/metcode/blob/main/internal/ui/ui.go"
click node_slash "https://github.com/edwin-metcalf/metcode/blob/main/internal/ui/commands.go"
click node_spinner "https://github.com/edwin-metcalf/metcode/blob/main/internal/ui/spinner.go"
click node_agent "https://github.com/edwin-metcalf/metcode/blob/main/internal/agent/agent.go"
click node_ollama "https://github.com/edwin-metcalf/metcode/blob/main/internal/ollama/ollama.go"
click node_definitions "https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/definitions.go"
click node_dispatch "https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/tools.go"
click node_file_ops "https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/files.go"
click node_command "https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/command.go"
click node_plan_tools "https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/planhelpers.go"
click node_plan_model "https://github.com/edwin-metcalf/metcode/blob/main/internal/plan/plan.go"
click node_conversation "https://github.com/edwin-metcalf/metcode/blob/main/internal/conversation/conversation.go"
click node_prompt "https://github.com/edwin-metcalf/metcode/blob/main/internal/prompt/prompt.go"

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_entry,node_cli,node_slash,node_spinner,node_user toneBlue
class node_agent,node_ollama toneAmber
class node_definitions,node_dispatch,node_file_ops,node_command,node_ollama_service toneMint
class node_plan_tools,node_plan_model,node_conversation toneRose
class node_prompt,node_prompt_file toneIndigo
```

## Components

### CLI runtime

- [Startup wiring](https://github.com/edwin-metcalf/metcode/blob/main/cmd/metcode/main.go): `cmd/metcode/main.go`
- [Interactive CLI](https://github.com/edwin-metcalf/metcode/blob/main/internal/ui/ui.go): `internal/ui/ui.go`
- [Slash commands](https://github.com/edwin-metcalf/metcode/blob/main/internal/ui/commands.go): `internal/ui/commands.go`
- [Request spinner](https://github.com/edwin-metcalf/metcode/blob/main/internal/ui/spinner.go): `internal/ui/spinner.go`

### Agent and model

- [Turn and tool loop](https://github.com/edwin-metcalf/metcode/blob/main/internal/agent/agent.go): `internal/agent/agent.go`
- [Ollama HTTP client](https://github.com/edwin-metcalf/metcode/blob/main/internal/ollama/ollama.go): `internal/ollama/ollama.go`

### Workspace tools

- [Tool definitions](https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/definitions.go): `internal/tools/definitions.go`
- [Tool dispatcher](https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/tools.go): `internal/tools/tools.go`
- [Sandboxed file tools](https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/files.go): `internal/tools/files.go`
- [Confirmed commands](https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/command.go): `internal/tools/command.go`

### Plans and conversations

- [Plan operations](https://github.com/edwin-metcalf/metcode/blob/main/internal/tools/planhelpers.go): `internal/tools/planhelpers.go`
- [Plan step types](https://github.com/edwin-metcalf/metcode/blob/main/internal/plan/plan.go): `internal/plan/plan.go`
- [Conversation storage](https://github.com/edwin-metcalf/metcode/blob/main/internal/conversation/conversation.go): `internal/conversation/conversation.go`

### Prompt configuration

- [System prompt loader](https://github.com/edwin-metcalf/metcode/blob/main/internal/prompt/prompt.go): `internal/prompt/prompt.go`

### Other components

- **Terminal user**
- **Ollama server**
- **Custom prompt file**

## Connections

- Terminal user → Startup wiring: launches (evidence: `README.md`)
- Startup wiring → System prompt loader: loads prompt (evidence: `cmd/metcode/main.go`)
- System prompt loader → Custom prompt file: loads or creates (evidence: `README.md`)
- Startup wiring → Interactive CLI: starts (evidence: `cmd/metcode/main.go`)
- Interactive CLI → Terminal user: reads prompts (evidence: `internal/ui/ui.go`)
- Interactive CLI → Turn and tool loop: submits turn (evidence: `internal/ui/ui.go`)
- Interactive CLI → Slash commands: routes commands (evidence: `internal/ui/ui.go`)
- Interactive CLI → Request spinner: uses while waiting (evidence: `internal/ui/ui.go`)
- Slash commands → Ollama HTTP client: lists models (evidence: `internal/ui/commands.go`)
- Slash commands → Conversation storage: saves and loads (evidence: `internal/ui/commands.go`)
- Turn and tool loop → Ollama HTTP client: sends chat (evidence: `internal/agent/agent.go`)
- Ollama HTTP client → Ollama server: calls chat API (evidence: `internal/ollama/ollama.go`)
- Ollama server → Ollama HTTP client: returns response (evidence: `internal/ollama/ollama.go`)
- Turn and tool loop → Tool definitions: advertises tools (evidence: `internal/agent/agent.go`)
- Turn and tool loop → Tool dispatcher: dispatches calls (evidence: `internal/agent/agent.go`)
- Tool dispatcher → Sandboxed file tools: dispatches file calls (evidence: `internal/tools/tools.go`)
- Tool dispatcher → Confirmed commands: dispatches command (evidence: `internal/tools/tools.go`)
- Tool dispatcher → Plan operations: dispatches plan calls (evidence: `internal/tools/tools.go`)
- Plan operations → Plan step types: updates plan items (evidence: `internal/tools/planhelpers.go`)
- Ollama HTTP client → Ollama server: lists models (evidence: `internal/ollama/ollama.go`)
- Terminal user → Sandboxed file tools: approves edits (evidence: `internal/tools/files.go`)
- Terminal user → Confirmed commands: approves execution (evidence: `internal/tools/command.go`)
