# aider-ai/aider architecture

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

- Interactive diagram: https://gitdiagram.com/aider-ai/aider
- Repository: https://github.com/aider-ai/aider
- Video tour (about a minute): https://gitdiagram.com/aider-ai/aider/video

## Overview

#### Purpose and Entry Points
Aider is a Python terminal-based AI pair-programming tool. It operates inside a user’s code repository, sends contextualized requests to cloud or local LLMs, applies model-produced code edits, and can validate and commit them. CLI startup is through `aider/__main__.py`, with application orchestration in `aider/main.py`; argument parsing and startup configuration live in `aider/args.py`.

#### Session Orchestration and User Interface
`aider/main.py` constructs the interactive session: repository access, model selection, I/O, chat history, coder mode, and optional integrations. Terminal interaction, command dispatch, and chat persistence are separated into `aider/io.py`, `aider/commands.py`, and `aider/history.py`. Optional alternate interaction surfaces include browser/copypaste support in `aider/gui.py` and voice input in `aider/voice.py`.

#### Coder Strategy Layer
The `aider/coders/` package is the core behavior boundary between a conversation and concrete filesystem edits. `aider/coders/base_coder.py` provides the common chat/edit lifecycle, while specialized subclasses select distinct response and patch protocols: whole-file, search/replace, unified diff, edit blocks, and architect/editor workflows. Key implementations include `aider/coders/editblock_coder.py`, `aider/coders/udiff_coder.py`, and `aider/coders/architect_coder.py`; paired `*_prompts.py` files define each protocol’s model contract.

#### LLM and Model Integration
Model abstraction, capability/settings resolution, and request routing are centralized in `aider/models.py` and `aider/llm.py`. `aider/sendchat.py` manages sending and streamed model responses; `aider/openrouter.py` is a provider-specific integration. Model metadata/settings are bundled in `aider/resources/model-metadata.json` and `aider/resources/model-settings.yml`. The external-service boundary is LLM provider APIs, including OpenAI-compatible endpoints, Anthropic, DeepSeek, OpenRouter, and local model servers.

#### Repository Context and Git Boundary
`aider/repo.py` encapsulates the working repository and Git-facing operations. `aider/repomap.py` builds a token-budgeted structural map of the codebase so the model can reason about files beyond those explicitly added to chat. Language-aware symbol extraction is driven by Tree-sitter query assets such as `aider/queries/tree-sitter-language-pack/python-tags.scm`. This layer reads and changes the local filesystem/Git worktree; coder output must pass through it rather than directly representing trusted edits.

#### Edit Application and Validation Loop
A typical turn flows: user request → selected coder assembles prompts from chat history, selected files, repository map, and attachments → model response streams back → coder parses and applies edits → diffs are presented → optional lint/test commands run. Patch and diff handling is concentrated in `aider/diffs.py`, `aider/coders/search_replace.py`, and format-specific coder classes. `aider/linter.py` and `aider/run_cmd.py` execute validation commands, whose output can be fed back into another repair turn.

#### Supporting Context Inputs and Automation
Aider can incorporate URLs/web content and images through `aider/urls.py` and `aider/scrape.py`, and monitor files/comments for IDE-adjacent workflows through `aider/watch.py`. Analytics is isolated in `aider/analytics.py`, avoiding coupling core edit execution to telemetry. Docker packaging is defined by `docker/Dockerfile`; the separate `benchmark/` subsystem evaluates coding/model performance rather than serving the interactive application.

Main entry points: [`aider/main.py`](https://github.com/aider-ai/aider/blob/main/aider/main.py) (Session orchestration), [`aider/coders/base_coder.py`](https://github.com/aider-ai/aider/blob/main/aider/coders/base_coder.py) (Coder lifecycle), [`aider/repo.py`](https://github.com/aider-ai/aider/blob/main/aider/repo.py) (Repository & Git worktree), [`aider/repomap.py`](https://github.com/aider-ai/aider/blob/main/aider/repomap.py) (Repository map)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_session["Session &amp; UI"]
  node_entry["CLI entry point<br/>Python module<br/>[__main__.py]"]
  node_main["Session orchestration<br/>application runtime<br/>[main.py]"]
  node_args["Arguments &amp; startup config<br/>CLI configuration<br/>[args.py]"]
  node_io["Terminal I/O<br/>interactive interface<br/>[io.py]"]
  node_commands["Command dispatch<br/>command handler<br/>[commands.py]"]
  node_history[("Chat history<br/>persistence<br/>[history.py]")]
end

subgraph group_coding["Coding &amp; Repository"]
  node_coder_base["Coder lifecycle<br/>strategy base<br/>[base_coder.py]"]
  node_coder_protocols["Edit protocol coders<br/>coder strategies<br/>[editblock_coder.py]"]
  node_repo[("Repository &amp; Git worktree<br/>repository boundary<br/>[repo.py]")]
  node_repomap["Repository map<br/>code context builder<br/>[repomap.py]"]
  node_symbols["Tree-sitter symbol queries<br/>language assets<br/>[python-tags.scm]"]
  node_diffs["Diff &amp; patch handling<br/>edit application<br/>[diffs.py]"]
  node_validation["Validation runner<br/>lint/test execution<br/>[linter.py]"]
end

subgraph group_llm["LLM Integration"]
  node_models["Model resolution<br/>model abstraction<br/>[models.py]"]
  node_llm_runtime["LLM request routing<br/>LLM runtime<br/>[llm.py]"]
  node_sendchat["Streaming chat transport<br/>response streaming<br/>[sendchat.py]"]
  node_providers{{"LLM provider APIs<br/>external services"}}
end

subgraph group_support["Inputs &amp; Automation"]
  node_attachments["Web &amp; image context<br/>context input<br/>[urls.py]"]
  node_watch["File/comment watch<br/>automation input<br/>[watch.py]"]
  node_analytics["Analytics<br/>telemetry<br/>[analytics.py]"]
end

node_entry -->|"starts"| node_main
node_args -->|"configures"| node_main
node_main -->|"runs interaction"| node_io
node_io -->|"dispatches commands"| node_commands
node_main -->|"loads and persists chat"| node_history
node_main -->|"selects and drives"| node_coder_base
node_main -->|"opens worktree"| node_repo
node_main -->|"selects model"| node_models
node_main -.->|"adds external context"| node_attachments
node_main -.->|"optional monitoring"| node_watch
node_main -.->|"optional telemetry"| node_analytics
node_coder_base -->|"uses protocol strategy"| node_coder_protocols
node_coder_base -->|"assembles conversation"| node_history
node_coder_base -->|"uses selected files"| node_repo
node_coder_base -->|"adds codebase map"| node_repomap
node_coder_base -->|"sends prompt"| node_sendchat
node_repomap -->|"reads repository"| node_repo
node_repomap -->|"extracts symbols with"| node_symbols
node_sendchat -->|"routes request"| node_llm_runtime
node_models -->|"supplies settings"| node_llm_runtime
node_llm_runtime -->|"calls"| node_providers
node_providers -->|"streams response"| node_sendchat
node_coder_protocols -->|"parses edits"| node_diffs
node_diffs -->|"applies through"| node_repo
node_repo -->|"validates changed worktree"| node_validation
node_validation -.->|"feeds repair output"| node_coder_base

click node_entry "https://github.com/aider-ai/aider/blob/main/aider/__main__.py"
click node_main "https://github.com/aider-ai/aider/blob/main/aider/main.py"
click node_args "https://github.com/aider-ai/aider/blob/main/aider/args.py"
click node_io "https://github.com/aider-ai/aider/blob/main/aider/io.py"
click node_commands "https://github.com/aider-ai/aider/blob/main/aider/commands.py"
click node_history "https://github.com/aider-ai/aider/blob/main/aider/history.py"
click node_coder_base "https://github.com/aider-ai/aider/blob/main/aider/coders/base_coder.py"
click node_coder_protocols "https://github.com/aider-ai/aider/blob/main/aider/coders/editblock_coder.py"
click node_repo "https://github.com/aider-ai/aider/blob/main/aider/repo.py"
click node_repomap "https://github.com/aider-ai/aider/blob/main/aider/repomap.py"
click node_symbols "https://github.com/aider-ai/aider/blob/main/aider/queries/tree-sitter-language-pack/python-tags.scm"
click node_diffs "https://github.com/aider-ai/aider/blob/main/aider/diffs.py"
click node_validation "https://github.com/aider-ai/aider/blob/main/aider/linter.py"
click node_models "https://github.com/aider-ai/aider/blob/main/aider/models.py"
click node_llm_runtime "https://github.com/aider-ai/aider/blob/main/aider/llm.py"
click node_sendchat "https://github.com/aider-ai/aider/blob/main/aider/sendchat.py"
click node_attachments "https://github.com/aider-ai/aider/blob/main/aider/urls.py"
click node_watch "https://github.com/aider-ai/aider/blob/main/aider/watch.py"
click node_analytics "https://github.com/aider-ai/aider/blob/main/aider/analytics.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_entry,node_main,node_args,node_io,node_commands,node_history toneBlue
class node_coder_base,node_coder_protocols,node_repo,node_repomap,node_symbols,node_diffs,node_validation toneAmber
class node_models,node_llm_runtime,node_sendchat,node_providers toneMint
class node_attachments,node_watch,node_analytics toneRose
```

## Components

### Session & UI

- [CLI entry point](https://github.com/aider-ai/aider/blob/main/aider/__main__.py): Python module · `aider/__main__.py`
- [Session orchestration](https://github.com/aider-ai/aider/blob/main/aider/main.py): application runtime · Constructs the interactive coding session. · `aider/main.py`
- [Arguments & startup config](https://github.com/aider-ai/aider/blob/main/aider/args.py): CLI configuration · `aider/args.py`
- [Terminal I/O](https://github.com/aider-ai/aider/blob/main/aider/io.py): interactive interface · `aider/io.py`
- [Command dispatch](https://github.com/aider-ai/aider/blob/main/aider/commands.py): command handler · `aider/commands.py`
- [Chat history](https://github.com/aider-ai/aider/blob/main/aider/history.py): persistence · `aider/history.py`

### Coding & Repository

- [Coder lifecycle](https://github.com/aider-ai/aider/blob/main/aider/coders/base_coder.py): strategy base · Builds context, requests responses, and coordinates edits. · `aider/coders/base_coder.py`
- [Edit protocol coders](https://github.com/aider-ai/aider/blob/main/aider/coders/editblock_coder.py): coder strategies · Edit blocks, unified diffs, and architect/editor workflows. · `aider/coders/editblock_coder.py`
- [Repository & Git worktree](https://github.com/aider-ai/aider/blob/main/aider/repo.py): repository boundary · The trusted boundary for local file and Git operations. · `aider/repo.py`
- [Repository map](https://github.com/aider-ai/aider/blob/main/aider/repomap.py): code context builder · Builds a token-budgeted structural codebase map. · `aider/repomap.py`
- [Tree-sitter symbol queries](https://github.com/aider-ai/aider/blob/main/aider/queries/tree-sitter-language-pack/python-tags.scm): language assets · `aider/queries/tree-sitter-language-pack/python-tags.scm`
- [Diff & patch handling](https://github.com/aider-ai/aider/blob/main/aider/diffs.py): edit application · `aider/diffs.py`
- [Validation runner](https://github.com/aider-ai/aider/blob/main/aider/linter.py): lint/test execution · `aider/linter.py`

### LLM Integration

- [Model resolution](https://github.com/aider-ai/aider/blob/main/aider/models.py): model abstraction · Resolves capabilities and provider settings. · `aider/models.py`
- [LLM request routing](https://github.com/aider-ai/aider/blob/main/aider/llm.py): LLM runtime · `aider/llm.py`
- [Streaming chat transport](https://github.com/aider-ai/aider/blob/main/aider/sendchat.py): response streaming · `aider/sendchat.py`
- **LLM provider APIs**: external services · Cloud and local OpenAI-compatible model endpoints.

### Inputs & Automation

- [Web & image context](https://github.com/aider-ai/aider/blob/main/aider/urls.py): context input · `aider/urls.py`
- [File/comment watch](https://github.com/aider-ai/aider/blob/main/aider/watch.py): automation input · `aider/watch.py`
- [Analytics](https://github.com/aider-ai/aider/blob/main/aider/analytics.py): telemetry · Isolated from core edit execution. · `aider/analytics.py`

## Connections

- CLI entry point → Session orchestration: starts
- Arguments & startup config → Session orchestration: configures
- Session orchestration → Terminal I/O: runs interaction
- Terminal I/O → Command dispatch: dispatches commands
- Session orchestration → Chat history: loads and persists chat
- Session orchestration → Coder lifecycle: selects and drives
- Session orchestration → Repository & Git worktree: opens worktree
- Session orchestration → Model resolution: selects model
- Session orchestration → Web & image context: adds external context
- Session orchestration → File/comment watch: optional monitoring
- Session orchestration → Analytics: optional telemetry
- Coder lifecycle → Edit protocol coders: uses protocol strategy
- Coder lifecycle → Chat history: assembles conversation
- Coder lifecycle → Repository & Git worktree: uses selected files
- Coder lifecycle → Repository map: adds codebase map
- Coder lifecycle → Streaming chat transport: sends prompt
- Repository map → Repository & Git worktree: reads repository
- Repository map → Tree-sitter symbol queries: extracts symbols with
- Streaming chat transport → LLM request routing: routes request
- Model resolution → LLM request routing: supplies settings
- LLM request routing → LLM provider APIs: calls
- LLM provider APIs → Streaming chat transport: streams response
- Edit protocol coders → Diff & patch handling: parses edits
- Diff & patch handling → Repository & Git worktree: applies through
- Repository & Git worktree → Validation runner: validates changed worktree
- Validation runner → Coder lifecycle: feeds repair output
