# mapembert/bolt.new-any-llm architecture

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

- Interactive diagram: https://gitdiagram.com/mapembert/bolt.new-any-llm
- Repository: https://github.com/mapembert/bolt.new-any-llm

## Overview

##### Main Components

a) Frontend Layer:
- React-based UI components (under app/components/)
- Key modules:
- Chat interface
- Code editor (CodeMirror integration)
- Workbench
- Terminal emulator
- File tree viewer

b) Core Services Layer:
- LLM Integration Service
- Multiple model providers (OpenAI, Anthropic, Ollama, Groq, etc.)
- Model switching capability
- Streaming response handling

c) Runtime Environment:
- WebContainer System
- Node.js runtime
- Package management
- File system operations
- Terminal emulation

d) State Management:
- Multiple stores for:
- Chat
- Editor
- Files
- Previews
- Settings
- Terminal
- Theme
- Workbench

**┌─ User Interface Layer ─────────────────────────────┐**
- ┌─────────┐ ┌──────────┐ ┌────────┐ ┌──────────┐  │
- Chat   │ │  Editor  │ │Preview │ │ Terminal │  │
- ┘ └──────────┘ └────────┘ └──────────┘  │
- ┬───────────────────────────┘

**┌───────────────────────▼───────────────────────────┐**
- Core Services Layer                               │
- ┌─────────────────┐  ┌────────────────────────┐  │
- LLM Integration │  │ Message Parser/Runtime  │  │
- OpenAI       │  │ - Action Runner         │  │
- Anthropic    │  │ - Stream Processing     │  │
- Ollama       │  └────────────────────────┘  │
- Groq         │                              │
- ┘                              │
- ┬───────────────────────────┘

**┌───────────────────────▼───────────────────────────┐**
- WebContainer Runtime                              │
- ┌─────────┐ ┌──────────┐ ┌────────────────────┐  │
- Node.js │ │   NPM    │ │ File System Access │  │
- ┘ └──────────┘ └────────────────────┘  │
- ┘

##### Important Flows to Highlight

a) User Input Flow:
- Chat input → LLM Processing → Action Generation → Runtime Execution

b) File Operation Flow:
- Editor Changes → File System → Preview Updates

c) Terminal Command Flow:
- Terminal Input → WebContainer Execution → Output Display

##### Additional Elements

- Version/environment indicators
- External service connections (API endpoints)
- Security boundaries

##### Implementation Notes

- Use double lines for data streaming

- In-browser full-stack development capability
- Multi-model LLM integration
- Real-time preview and execution
- Seamless state management across components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        direction TB
        WB["Workbench"]
        ED["Code Editor"]
        TE["Terminal"]
        CI["Chat Interface"]
        
        subgraph WBC["Workbench Components"]
            direction TB
            FT["File Tree"]
            PV["Preview"]
        end
        
        WB --> WBC
    end
    
    subgraph CORE["Application Core"]
        direction TB
        subgraph SS["State Stores"]
            direction TB
            CS["Chat Store"]
            ES["Editor Store"]
            FS["Files Store"]
            PS["Previews Store"]
            SS1["Settings Store"]
            TS["Terminal Store"]
            THS["Theme Store"]
            WS["Workbench Store"]
        end
        
        subgraph RS["Runtime Services"]
            direction TB
            WC["WebContainer"]
            PM["Package Management"]
            FSO["File System Operations"]
            AR["Action Runner"]
            MP["Message Parser"]
        end
    end
    
    subgraph LLM["LLM Integration Layer"]
        direction TB
        MR["Model Provider Router"]
        MS["Model Service"]
        PS1["Prompt Service"]
        ST["Stream Text Service"]
        
        subgraph API["API Endpoints"]
            direction TB
            AC["/api/chat"]
            AE["/api/enhancer"]
            AM["/api/models"]
        end
    end
    
    %% Relationships
    UI <--> CORE
    CORE <--> LLM
    
    %% Click events
    click CI "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/components/chat/BaseChat.tsx"
    click ED "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/components/editor/codemirror/CodeMirrorEditor.tsx"
    click WB "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/components/workbench/Workbench.client.tsx"
    click TE "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/components/workbench/terminal/Terminal.tsx"
    click FT "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/components/workbench/FileTree.tsx"
    click MS "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/.server/llm/model.ts"
    click PS1 "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/.server/llm/prompts.ts"
    click ST "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/.server/llm/stream-text.ts"
    click WC "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/webcontainer/index.ts"
    click CS "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/stores/chat.ts"
    click ES "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/stores/editor.ts"
    click FS "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/stores/files.ts"
    click PS "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/stores/previews.ts"
    click SS1 "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/stores/settings.ts"
    click TS "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/stores/terminal.ts"
    click THS "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/stores/theme.ts"
    click WS "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/stores/workbench.ts"
    click AR "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/runtime/action-runner.ts"
    click MP "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/lib/runtime/message-parser.ts"
    click AC "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/routes/api.chat.ts"
    click AE "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/routes/api.enhancer.ts"
    click AM "https://github.com/mapembert/bolt.new-any-llm/blob/main/app/routes/api.models.ts"
    
    %% Styling
    classDef ui fill:#2374ab
    classDef core fill:#2a9d8f
    classDef llm fill:#8338ec
    classDef api fill:#ff006e
    
    class WB,ED,TE,CI,FT,PV ui
    class CS,ES,FS,PS,SS1,TS,THS,WS,WC,PM,FSO,AR,MP core
    class MR,MS,PS1,ST llm
    class AC,AE,AM api
```
