# pallavi-sinha-12/bitefix architecture

> Architecture diagram of the GitHub repository pallavi-sinha-12/bitefix, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pallavi-sinha-12/bitefix
- Repository: https://github.com/pallavi-sinha-12/bitefix

## Overview

##### Project Type and Purpose
- Project Type: Open-source Python library (not a full-stack app)
- Purpose: Provide two decorators (`@resolve`, `@resolve_with_openai`) that automatically orchestrate a team of AI agents to diagnose and fix runtime errors in user functions, using either OpenAI’s API or a local LLM.

##### File Structure
- `bitefix/` package
– BiteFixAITasks.py: task definitions for each agent
– BiteFixAIAgents.py: agent role classes (Diagnosis, Senior Dev, Lead, Code Developer)
– BiteFixAICrew.py: crew/agent assembly logic
– BiteFixAIRunner.py: orchestrator/pipeline manager that runs agents in sequence
– bitefix_utils.py: logging, export directory management, utilities
- Top-level scripts: `setup.py`, `requirements.txt`, CI config in `.github/`, assets for README images

##### README for Insights
- Two decorators wrap user functions and catch runtime errors.
- In case of error: decorator triggers a “crew” of AI agents.
- Agents interact with external LLM backends (OpenAI via `openai` library or any `langchain`-compatible LLM, e.g. Ollama).
- The pipeline: diagnosis → idea generation → idea evaluation → code rewriting → apply fix → re-execute.

##### Main Components
A. User Function (client code) with a BiteFix decorator
B. Decorator Layer (`resolve_with_openai` / `resolve`)
C. AIRunner (pipeline manager)
D. AICrew (agent factory, from crewAI)
E. AIAgents (4 roles)
F. AITasks (prompt templates & task specs)
G. External LLM Service(s)
– OpenAI API (GPT-4, etc.)
– Local LLM via Ollama / other `langchain` backends
H. Utilities & Export (logging, report generation in `export_dir`)

##### Relationships and Data Flows
1. User invokes decorated function
2. Decorator intercepts; on exception, calls AIRunner
3. AIRunner uses AICrew to spawn AIAgents with AITasks
4. Each agent sends prompts to the chosen LLM service (via `openai` or `langchain_community.llms.ollama.Ollama`)
5. Agents return results (diagnosis, ideas, selected fix, rewritten code) back to AIRunner
6. AIRunner aggregates feedback, writes logs and error-resolution report (`assets/`, `export_dir`)
7. Optionally, the fixed code is re-executed or returned to the user

##### Architectural Patterns & Design Principles
- Decorator Pattern – wraps user functions transparently
- Pipeline & Chain of Responsibility – sequential agent handling
- Strategy/Plugin Pattern – pluggable LLM backends (OpenAI vs custom)
- Modular Separation – cleanly separated modules for tasks, agents, orchestration, utilities

##### Detailed Elements
– Component names matching module names (bitefix_utils, BiteFixAIRunner, etc.)
– Notes or annotations for key design patterns (Decorator, Pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Output
    User["User Function"]:::user
    Output["Fixed Code / Report"]:::user

    %% Internal Modules
    Decorator["Decorator Layer<br/>(@resolve, @resolve_with_openai)"]:::internal
    AIRunner["AIRunner<br/>(Pipeline Manager)"]:::internal
    AICrew["AICrew<br/>(Agent Factory)"]:::internal
    Utils["Utilities & Export<br/>(logging, export_dir)"]:::internal

    %% AI Agents and Tasks
    subgraph "AI Agents Pipeline"
        direction TB
        AITasks["AITasks<br/>(Prompt Templates & Specs)"]:::internal
        diag["Diagnosis Expert"]:::internal
        senior["Senior Developer"]:::internal
        lead["Lead Developer"]:::internal
        codeDev["Code Developer"]:::internal
    end

    %% External Services
    OpenAI(("OpenAI API")):::external
    LocalLLM(("Local LLM (Ollama)")):::external

    %% Connections
    User -->|"invokes"| Decorator
    Decorator -->|"on error calls"| AIRunner
    AIRunner -->|"create crew"| AICrew
    AICrew -->|"uses tasks"| AITasks
    AICrew -->|"spawn"| diag
    diag -->|"after diagnosis"| senior
    senior -->|"after review"| lead
    lead -->|"after planning"| codeDev
    %% Agents to LLM
    diag -->|"prompt via AITasks"| OpenAI
    senior -->|"prompt via AITasks"| OpenAI
    lead -->|"prompt via AITasks"| LocalLLM
    codeDev -->|"prompt via AITasks"| LocalLLM
    OpenAI -->|"model response"| diag
    OpenAI -->|"model response"| senior
    LocalLLM -->|"model response"| lead
    LocalLLM -->|"model response"| codeDev
    %% Back to runner and export
    codeDev -->|"fixed code output"| AIRunner
    AIRunner -->|"write logs & report"| Utils
    Utils -->|"export to user"| Output

    %% Click Events
    click Decorator "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/__init__.py"
    click AIRunner "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/BiteFixAIRunner.py"
    click AICrew "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/BiteFixAICrew.py"
    click diag "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/BiteFixAIAgents.py"
    click senior "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/BiteFixAIAgents.py"
    click lead "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/BiteFixAIAgents.py"
    click codeDev "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/BiteFixAIAgents.py"
    click AITasks "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/BiteFixAITasks.py"
    click Utils "https://github.com/pallavi-sinha-12/bitefix/blob/master/bitefix/bitefix_utils.py"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#0066CC,color:#000
    classDef external fill:#90EE90,stroke:#228B22,color:#000
    classDef user fill:#D3D3D3,stroke:#696969,color:#000
```
