# builderio/micro-agent architecture

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

- Interactive diagram: https://gitdiagram.com/builderio/micro-agent
- Repository: https://github.com/builderio/micro-agent

## Overview

##### Main Components

a) CLI Interface Layer
- Entry point through cli.ts
- Command handlers (config.ts, update.ts)
- Interactive mode components

b) Core Processing Layer
- Test Generation System
- Code Generation System
- Iteration Engine

c) LLM Integration Layer
- Multiple LLM Provider Support (OpenAI, Anthropic, Ollama)
- API Communication

d) Testing Framework
- Unit Test Matcher
- Visual Test Matcher
- Test Execution Engine

e) Helper Systems
- Configuration Management
- File Operations
- Error Handling

**┌─────────────────────────────────────────────────┐**
- User Interface                  │
- (CLI Commands, Interactive Mode, Config UI)    │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- Core Processing Engine               │
- ┬─────────────────┬────────────┤
- Test Generator │  Code Generator │  Iterator   │
- ┴─────────────────┴────────────┘
- ↕
**┌─────────────────────────────────────────────────┐**
- LLM Integration Layer              │
- ┬──────────────┬───────────────────┤
- OpenAI    │   Anthropic  │  Custom Endpoint  │
- ┴──────────────┴───────────────────┘
- ↕
**┌─────────────────────────────────────────────────┐**
- Testing Framework                  │
- ┬────────────────┬──────────────┤
- Unit Testing  │ Visual Testing │ Test Runner  │
- ┴────────────────┴──────────────┘
- ↕
**┌─────────────────────────────────────────────────┐**
- Support Systems                    │
- ┬────────────────┬──────────────┤
- Config      │ File Handlers  │    Utils     │
- ┴────────────────┴──────────────┘

##### Data Flow Indicators

**┌─────────────────────────────────────────┐**
- Visual Matching Pipeline        │
- ┬─────────────┬────────────┤
- Screenshot │   Claude    │  OpenAI    │
- Capture    │   Analysis  │  Generator │
- ┴─────────────┴────────────┘

##### Important Notes
- "micro" nature of the agent by showing clear boundaries
- Test-driven development approach
- Multi-model AI approach for visual matching
- Configuration points for API keys and endpoints

##### Additional Elements
- Version information
- Supported Node.js version requirements
- File extension patterns (.ts, .test.ts, .prompt.md)

Remember to include a note about the experimental nature of the visual matching feature and the specific requirements for different LLM providers.

This system design will help developers understand both the high-level architecture and the specific implementation details of the Micro Agent project.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI[User Interface Layer]
        CLI[CLI Entry Point]
        CMD[Command Handlers]
        INT[Interactive Mode]
    end

    subgraph CORE[Core Processing Layer]
        TG[Test Generator]
        CG[Code Generator]
        IE[Iteration Engine]
    end

    subgraph LLM[LLM Integration Layer]
        LH[LLM Handler]
        ML[Mock LLM]
        SP[System Prompts]
    end

    subgraph TEST[Testing Framework]
        VTM[Visual Test Matcher]
        VG[Visual Generation]
        TR[Test Runner]
        SS[Screenshot System]
    end

    subgraph HELP[Support Systems]
        CM[Configuration Management]
        FO[File Operations]
        EH[Error Handling]
        PV[Project Validation]
    end

    UI --> CORE
    CORE <--> LLM
    CORE <--> TEST
    TEST <--> HELP
    LLM <--> HELP

    %% Component Mappings
    click CLI "https://github.com/BuilderIO/micro-agent/blob/main/src/cli.ts"
    click CMD "https://github.com/BuilderIO/micro-agent/tree/main/src/commands"
    click INT "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/interactive-mode.ts"
    click TG "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/test.ts"
    click CG "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/generate.ts"
    click IE "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/iterate-on-test.ts"
    click LH "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/llm.ts"
    click ML "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/mock-llm.ts"
    click SP "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/systemPrompt.ts"
    click VTM "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/visual-test.ts"
    click VG "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/visual-generate.ts"
    click TR "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/run.ts"
    click SS "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/get-screenshot.ts"
    click CM "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/config.ts"
    click FO "https://github.com/BuilderIO/micro-agent/tree/main/src/helpers"
    click EH "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/error.ts"
    click PV "https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/validate-project.ts"

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef ui fill:#b3e0ff,stroke:#333
    classDef core fill:#b3ffb3,stroke:#333
    classDef llm fill:#e6b3ff,stroke:#333
    classDef test fill:#ffcc99,stroke:#333
    classDef help fill:#e6e6e6,stroke:#333

    class CLI,CMD,INT ui
    class TG,CG,IE core
    class LH,ML,SP llm
    class VTM,VG,TR,SS test
    class CM,FO,EH,PV help
```
