# muhammadtalha-prog/local-coding-agent architecture

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

- Interactive diagram: https://gitdiagram.com/muhammadtalha-prog/local-coding-agent
- Repository: https://github.com/muhammadtalha-prog/local-coding-agent

## Overview

#### Purpose and Entry Points
This is a local Python CLI for generating verified base-MATLAB `.m` functions from natural-language tasks. It uses a local Ollama-hosted coding model, optionally invokes installed MATLAB for validation, and saves successful output into a workspace.

Primary entry point: `main.py`. Central runtime settings and environment-derived defaults are in `config.py`.

#### Pipeline Orchestrator
`main.py` owns the end-to-end control flow: parse task/model/timeout/retry options, check LLM availability, invoke pipeline stages, report status, and copy verified artifacts to the output workspace. It also supports interactive task input when no task is supplied.

Paths: `main.py`, `config.py`.

#### Local LLM Boundary
The LLM integration is intentionally thin and direct: `agents/llm_client.py` communicates with Ollama’s local OpenAI-compatible API. Model selection, token limits, temperature, base URL, and request timeouts are configuration concerns rather than agent concerns.

Paths: `agents/llm_client.py`, `config.py`.

External service/runtime: Ollama must be running locally, typically at `http://localhost:11434/v1`; intended models include Qwen coder variants.

#### Planning Stage
The planner translates the user task into an in-memory structured implementation plan, including expected MATLAB file/function intent. This separates requirements decomposition from source generation and provides the coder with constrained context.

Paths: `agents/planner.py`, `agents/llm_client.py`.

#### Code Generation Stage
The coder consumes the task and plan to produce MATLAB source. The generated artifact is first written into the transient sandbox rather than directly to final output, establishing a validation boundary before publication.

Paths: `agents/coder.py`, `sandbox/moving_average_filter.m`.

The generation policy targets base MATLAB and avoids licensed toolbox dependencies.

#### MATLAB Execution and Verification
`agents/matlab_executor.py` is the system-process boundary. It runs MATLAB as a subprocess against sandboxed code, captures execution success/failure, and enforces a configurable execution timeout. MATLAB is optional: unavailable execution does not prevent code generation and saving, but eliminates runtime verification.

Paths: `agents/matlab_executor.py`, `config.py`, `sandbox/`.

External runtime: installed MATLAB executable, auto-detected or supplied through configuration.

#### Debug/Repair Loop
On MATLAB errors, the debugger receives the current code and execution diagnostics, asks the LLM for a correction, and returns revised source for another sandbox execution. The orchestrator bounds this feedback loop through `MAX_DEBUG_RETRIES` (default three), preventing unbounded model/subprocess work.

Paths: `agents/debugger.py`, `agents/matlab_executor.py`, `main.py`.

#### Artifact Lifecycle
Code moves through: user task → plan → generated sandbox `.m` file → optional MATLAB validation → debugger retries if needed → final verified `.m` file under a task-named workspace directory. Sandbox files are temporary pipeline artifacts; workspace output is the durable deliverable.

Paths: `sandbox/`, `main.py`, `LOCAL_OPTIMIZATION_GUIDE.md`.

Main entry points: [`main.py`](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/main.py) (Pipeline CLI), [`agents/llm_client.py`](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/llm_client.py) (LLM client), [`agents/matlab_executor.py`](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/matlab_executor.py) (MATLAB executor), [`agents/coder.py`](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/coder.py) (MATLAB coder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI &amp; orchestration"]
  node_user_task["User task<br/>input"]
  node_main["Pipeline CLI<br/>Python entry point<br/>[main.py]"]
  node_config["Runtime settings<br/>Python config<br/>[config.py]"]
end

subgraph group_agents["Generation agents"]
  node_ollama{{"Local Ollama<br/>external LLM service"}}
  node_llm_client["LLM client<br/>Python API adapter<br/>[llm_client.py]"]
  node_planner["Task planner<br/>Python agent<br/>[planner.py]"]
  node_coder["MATLAB coder<br/>Python agent<br/>[coder.py]"]
  node_debugger["Repair agent<br/>Python agent<br/>[debugger.py]"]
end

subgraph group_execution["Validation &amp; artifacts"]
  node_sandbox[("Transient sandbox<br/>artifact directory")]
  node_sandbox_file["Generated .m file<br/>MATLAB source"]
  node_matlab_executor["MATLAB executor<br/>Python subprocess adapter<br/>[matlab_executor.py]"]
  node_matlab{{"Installed MATLAB<br/>external runtime"}}
  node_workspace[("Task workspace<br/>durable output")]
  node_guide["Optimization guide<br/>documentation"]
end

node_user_task -->|"task input"| node_main
node_config -->|"CLI defaults"| node_main
node_main -->|"availability check"| node_llm_client
node_config -->|"model/API settings"| node_llm_client
node_llm_client -->|"API requests"| node_ollama
node_main -->|"task"| node_planner
node_planner -->|"plan prompt"| node_llm_client
node_planner -->|"implementation plan"| node_coder
node_main -->|"task"| node_coder
node_coder -->|"generation prompt"| node_llm_client
node_coder -->|"write candidate"| node_sandbox_file
node_sandbox_file -->|"stored in"| node_sandbox
node_main -->|"validate candidate"| node_matlab_executor
node_config -->|"execution timeout"| node_matlab_executor
node_matlab_executor -->|"subprocess execution"| node_matlab
node_sandbox_file -->|"source under test"| node_matlab_executor
node_matlab_executor -.->|"failure diagnostics"| node_debugger
node_debugger -->|"repair prompt"| node_llm_client
node_debugger -->|"revised source"| node_sandbox_file
node_main -.->|"bounded retries"| node_debugger
node_main -->|"publish generated or verified file"| node_workspace
node_guide -.->|"workflow guidance"| node_main

click node_main "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/main.py"
click node_config "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/config.py"
click node_llm_client "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/llm_client.py"
click node_planner "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/planner.py"
click node_coder "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/coder.py"
click node_debugger "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/debugger.py"
click node_sandbox "https://github.com/muhammadtalha-prog/local-coding-agent/tree/main/sandbox"
click node_sandbox_file "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/sandbox/moving_average_filter.m"
click node_matlab_executor "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/matlab_executor.py"
click node_guide "https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/LOCAL_OPTIMIZATION_GUIDE.md"

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_user_task,node_main,node_config toneBlue
class node_ollama,node_llm_client,node_planner,node_coder,node_debugger toneAmber
class node_sandbox,node_sandbox_file,node_matlab_executor,node_matlab,node_workspace,node_guide toneMint
```

## Components

### CLI & orchestration

- **User task**: input · Natural-language MATLAB function request.
- [Pipeline CLI](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/main.py): Python entry point · Parses options, coordinates stages, and publishes artifacts. · `main.py`
- [Runtime settings](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/config.py): Python config · Environment-derived model, timeout, and retry defaults. · `config.py`

### Generation agents

- **Local Ollama**: external LLM service · Local OpenAI-compatible coding-model endpoint.
- [LLM client](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/llm_client.py): Python API adapter · Direct boundary to the local Ollama API. · `agents/llm_client.py`
- [Task planner](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/planner.py): Python agent · Builds an in-memory MATLAB implementation plan. · `agents/planner.py`
- [MATLAB coder](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/coder.py): Python agent · Generates base-MATLAB source from the task and plan. · `agents/coder.py`
- [Repair agent](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/debugger.py): Python agent · Revises source using MATLAB diagnostics. · `agents/debugger.py`

### Validation & artifacts

- [Transient sandbox](https://github.com/muhammadtalha-prog/local-coding-agent/tree/main/sandbox): artifact directory · Holds generated code before publication. · `sandbox`
- [Generated .m file](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/sandbox/moving_average_filter.m): MATLAB source · Candidate source written for validation. · `sandbox/moving_average_filter.m`
- [MATLAB executor](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/agents/matlab_executor.py): Python subprocess adapter · Runs sandboxed code with a configurable timeout. · `agents/matlab_executor.py`
- **Installed MATLAB**: external runtime · Optional executable used for runtime verification.
- **Task workspace**: durable output · Task-named directory containing the final .m deliverable.
- [Optimization guide](https://github.com/muhammadtalha-prog/local-coding-agent/blob/main/LOCAL_OPTIMIZATION_GUIDE.md): documentation · Documents local workflow guidance. · `LOCAL_OPTIMIZATION_GUIDE.md`

## Connections

- User task → Pipeline CLI: task input
- Runtime settings → Pipeline CLI: CLI defaults
- Pipeline CLI → LLM client: availability check
- Runtime settings → LLM client: model/API settings
- LLM client → Local Ollama: API requests
- Pipeline CLI → Task planner: task
- Task planner → LLM client: plan prompt
- Task planner → MATLAB coder: implementation plan
- Pipeline CLI → MATLAB coder: task
- MATLAB coder → LLM client: generation prompt
- MATLAB coder → Generated .m file: write candidate
- Generated .m file → Transient sandbox: stored in
- Pipeline CLI → MATLAB executor: validate candidate
- Runtime settings → MATLAB executor: execution timeout
- MATLAB executor → Installed MATLAB: subprocess execution
- Generated .m file → MATLAB executor: source under test
- MATLAB executor → Repair agent: failure diagnostics
- Repair agent → LLM client: repair prompt
- Repair agent → Generated .m file: revised source
- Pipeline CLI → Repair agent: bounded retries · Limited by MAX_DEBUG_RETRIES.
- Pipeline CLI → Task workspace: publish generated or verified file
- Optimization guide → Pipeline CLI: workflow guidance
