# code-creations-io/create-self-healing-code-agent architecture

> Architecture diagram of the GitHub repository code-creations-io/create-self-healing-code-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/code-creations-io/create-self-healing-code-agent
- Repository: https://github.com/code-creations-io/create-self-healing-code-agent

## Overview

##### Project type and purpose
- This is a CLI-driven, Python-based “self-healing code generation” tool.
- It uses a small multi-agent framework (Smolagents) and an LLM (OpenAI) to draft code, write tests, run them, and iteratively patch until tests pass.

##### File structure
- Top level:
- main.py (entry point; loads env, invokes orchestrator)
- requirements.txt, .gitignore, .env (config & deps)
- agents/ (contains each agent’s code + LLM backend + orchestrator)
- agents/:
- llm_backends.py (wraps OpenAI / LiteLLMModel)
- code_writer.py (CodeWriter agent)
- test_writer.py (TestWriter agent)
- critic.py (CodeCritic agent)
- orchestrator.py (threads them together, runs pytest in work_dir)

##### README for additional insights
- Describes a “self-correcting loop” of up to 5 rounds.
- Workflow: prompt → code_writer → write user_code.py → test_writer → write test_user_code.py → pytest → if fail → critic → patch code → repeat.
- Tech stack: Python 3.11, Smolagents, OpenAI LLM, pytest, rich, dotenv.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level entry
    CLI["CLI Entry Point<br/>(main.py)"]:::process
    click CLI "https://github.com/code-creations-io/create-self-healing-code-agent/blob/main/main.py"

    %% Orchestrator
    ORCH["Orchestrator<br/>(agents/orchestrator.py)"]:::process
    click ORCH "https://github.com/code-creations-io/create-self-healing-code-agent/blob/main/agents/orchestrator.py"

    %% Config
    ENV[".env Config"]:::file

    %% Agents group
    subgraph "Agents"
        CW["CodeWriter Agent<br/>(agents/code_writer.py)"]:::agent
        click CW "https://github.com/code-creations-io/create-self-healing-code-agent/blob/main/agents/code_writer.py"
        TW["TestWriter Agent<br/>(agents/test_writer.py)"]:::agent
        click TW "https://github.com/code-creations-io/create-self-healing-code-agent/blob/main/agents/test_writer.py"
        CR["CodeCritic Agent<br/>(agents/critic.py)"]:::agent
        click CR "https://github.com/code-creations-io/create-self-healing-code-agent/blob/main/agents/critic.py"
    end

    %% LLM backend
    LLM["LLM Backend<br/>(agents/llm_backends.py)"]:::llm
    click LLM "https://github.com/code-creations-io/create-self-healing-code-agent/blob/main/agents/llm_backends.py"

    %% External API
    API["OpenAI API"]:::external

    %% Work directory files
    CODE["user_code.py"]:::file
    TEST["test_user_code.py"]:::file

    %% Test runner
    PYT["pytest Runner"]:::process

    %% Dependencies
    REQ["Project Dependencies<br/>(requirements.txt)"]:::file
    click REQ "https://github.com/code-creations-io/create-self-healing-code-agent/blob/main/requirements.txt"

    %% Connections
    CLI -->|1. load .env & invoke| ORCH
    ENV -->|env vars| ORCH

    ORCH -->|2. prompt spec| CW
    CW -->|writes code| CODE
    CODE -->|returned path| ORCH

    ORCH -->|3. code file| TW
    TW -->|writes tests| TEST
    TEST -->|returned path| ORCH

    ORCH -->|4. run tests| PYT
    PYT -->|5. result| ORCH

    ORCH -->|6a. on fail| CR
    CR -->|patch code| CODE
    CR -.->|loop| ORCH

    %% Agents use LLM
    CW -->|use model| LLM
    TW -->|use model| LLM
    CR -->|use model| LLM
    LLM -->|calls| API

    %% After success
    ORCH -->|7. final code| CLI

    %% Subprocess dependency
    REQ -->|deps| ORCH
    REQ -->|deps| CW
    REQ -->|deps| TW
    REQ -->|deps| CR
    REQ -->|deps| PYT

    %% File I/O
    ORCH -->|work_dir| CODE
    ORCH -->|work_dir| TEST

    classDef process fill:#AEDFF7,stroke:#333,stroke-width:1px
    classDef agent fill:#C4F1BE,stroke:#333,stroke-width:1px
    classDef file fill:#F9E79F,stroke:#333,stroke-width:1px
    classDef external fill:#F5B7B1,stroke:#333,stroke-width:1px
    classDef llm fill:#D2B4DE,stroke:#333,stroke-width:1px
```
