# prateek1217/knabit-coding-agent architecture

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

- Interactive diagram: https://gitdiagram.com/prateek1217/knabit-coding-agent
- Repository: https://github.com/prateek1217/knabit-coding-agent

## Overview

This is a local AI coding assistant. A user enters a request in the agent’s command-line loop; its LangGraph chat node prepares conversation context, calls Gemini with discovered MCP tools, and executes any requested tools through the MCP server before displaying the response. The agent also summarizes older turns and checkpoints graph state in SQLite. The server exposes file editing, project search/navigation, shell execution, and Git operations. Relationships follow the README and shown source; the MCP transport is documented, but individual tool-to-server dispatch details are not expanded beyond the shown calls.

Main entry points: [`server.py`](https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py) (FastMCP tool server), [`agent.py`](https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py) (LangGraph chat flow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["User interaction"]
  node_cli["Command-line loop<br/>[agent.py]"]
end

subgraph group_reasoning["Agent reasoning"]
  node_graph["LangGraph chat flow<br/>[agent.py]"]
  node_context["Windowed context<br/>[agent.py]"]
  node_summarizer["Turn summarization<br/>[agent.py]"]
  node_checkpoint[("SQLite checkpoint<br/>[agent.py]")]
end

subgraph group_bridge["MCP tool bridge"]
  node_mcp_client["MCP client setup<br/>[agent.py]"]
  node_tool_dispatch["Tool invocation<br/>[agent.py]"]
  node_mcp_server["FastMCP tool server<br/>[server.py]"]
end

subgraph group_capabilities["Project capabilities"]
  node_file_tools["File operations<br/>[server.py]"]
  node_project_tools["Project search<br/>[server.py]"]
  node_shell_tool["Shell execution<br/>[server.py]"]
  node_git_tools["Git operations<br/>[server.py]"]
end

node_user(("User"))
node_gemini["Gemini model"]
node_workspace["Project files"]
node_shell["Host shell"]
node_git_repo["Git repository"]

node_user -->|"enters request"| node_cli
node_cli -->|"invokes graph"| node_graph
node_graph -->|"prepares context"| node_context
node_context -->|"summarizes old turns"| node_summarizer
node_summarizer -->|"requests summary"| node_gemini
node_context -->|"sends conversation"| node_gemini
node_graph -->|"checkpoints state"| node_checkpoint
node_mcp_client -->|"opens stdio session"| node_mcp_server
node_mcp_client -->|"loads tools"| node_tool_dispatch
node_graph -->|"invokes requested tools"| node_tool_dispatch
node_tool_dispatch -->|"dispatches tools"| node_mcp_server
node_mcp_server -->|"registers tools"| node_file_tools
node_mcp_server -->|"registers tools"| node_project_tools
node_mcp_server -->|"registers tool"| node_shell_tool
node_mcp_server -->|"registers tools"| node_git_tools
node_file_tools -->|"reads and edits"| node_workspace
node_project_tools -->|"searches files"| node_workspace
node_shell_tool -->|"runs commands"| node_shell
node_git_tools -->|"runs Git commands"| node_git_repo

click node_cli "https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py"
click node_graph "https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py"
click node_context "https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py"
click node_summarizer "https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py"
click node_checkpoint "https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py"
click node_mcp_client "https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py"
click node_tool_dispatch "https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py"
click node_mcp_server "https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py"
click node_file_tools "https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py"
click node_project_tools "https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py"
click node_shell_tool "https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py"
click node_git_tools "https://github.com/prateek1217/knabit-coding-agent/blob/main/server.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_cli,node_user toneBlue
class node_graph,node_context,node_summarizer,node_checkpoint toneAmber
class node_mcp_client,node_tool_dispatch,node_mcp_server toneMint
class node_file_tools,node_project_tools,node_shell_tool,node_git_tools toneRose
class node_gemini,node_workspace,node_shell,node_git_repo toneIndigo
```

## Components

### User interaction

- [Command-line loop](https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py): `agent.py`

### Agent reasoning

- [LangGraph chat flow](https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py): `agent.py`
- [Windowed context](https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py): `agent.py`
- [Turn summarization](https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py): `agent.py`
- [SQLite checkpoint](https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py): `agent.py`

### MCP tool bridge

- [MCP client setup](https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py): `agent.py`
- [Tool invocation](https://github.com/prateek1217/knabit-coding-agent/blob/main/agent.py): `agent.py`
- [FastMCP tool server](https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py): `server.py`

### Project capabilities

- [File operations](https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py): `server.py`
- [Project search](https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py): `server.py`
- [Shell execution](https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py): `server.py`
- [Git operations](https://github.com/prateek1217/knabit-coding-agent/blob/main/server.py): `server.py`

### Other components

- **User**
- **Gemini model**
- **Project files**
- **Host shell**
- **Git repository**

## Connections

- User → Command-line loop: enters request (evidence: `agent.py`)
- Command-line loop → LangGraph chat flow: invokes graph (evidence: `agent.py`)
- LangGraph chat flow → Windowed context: prepares context (evidence: `agent.py`)
- Windowed context → Turn summarization: summarizes old turns (evidence: `agent.py`)
- Turn summarization → Gemini model: requests summary (evidence: `agent.py`)
- Windowed context → Gemini model: sends conversation (evidence: `agent.py`)
- LangGraph chat flow → SQLite checkpoint: checkpoints state (evidence: `agent.py`)
- MCP client setup → FastMCP tool server: opens stdio session (evidence: `agent.py`)
- MCP client setup → Tool invocation: loads tools (evidence: `agent.py`)
- LangGraph chat flow → Tool invocation: invokes requested tools (evidence: `agent.py`)
- Tool invocation → FastMCP tool server: dispatches tools (evidence: `README.md`)
- FastMCP tool server → File operations: registers tools (evidence: `server.py`)
- FastMCP tool server → Project search: registers tools (evidence: `server.py`)
- FastMCP tool server → Shell execution: registers tool (evidence: `server.py`)
- FastMCP tool server → Git operations: registers tools (evidence: `server.py`)
- File operations → Project files: reads and edits (evidence: `server.py`)
- Project search → Project files: searches files (evidence: `server.py`)
- Shell execution → Host shell: runs commands (evidence: `server.py`)
- Git operations → Git repository: runs Git commands (evidence: `server.py`)
