# nimastic/berkeley-llm-agent-hackathon architecture

> Architecture diagram of the GitHub repository nimastic/berkeley-llm-agent-hackathon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nimastic/berkeley-llm-agent-hackathon
- Repository: https://github.com/nimastic/berkeley-llm-agent-hackathon

## Overview

##### Data Flow Representation

a) Primary User Interaction Flow:
- User → Frontend → Backend → OpenAI API → Backend → Frontend → User

b) Code Execution Flow:
- Code Input → Frontend → Backend Python Executor → Results → Frontend

c) Knowledge Retrieval Flow:
- Query → Backend → Vector DB → RAG Processing → LLM → Response

##### Component Details

- Rectangles: Main containers (Frontend, Backend)
- Rounded rectangles: UI components
- Hexagons: External services
- Blue: Frontend components
- Green: Backend services
- Purple: External APIs
- Orange: Data storage

##### Specific Implementation Details

Technical specifications:
- React (Frontend Framework)
- FastAPI (Backend Framework)
- OpenAI API Integration
- Vector Database for RAG
- WebSocket or HTTP communication between frontend and backend

##### Additional Elements

Following supporting information:
- Environment configuration (.env)
- Port specifications (3000, 8000)
- File storage locations (course_material.txt)
- API endpoints

##### Notes Section

A small notes section highlighting:
- CORS configuration between frontend and backend
- Authentication flow (if implemented)
- Rate limiting considerations
- Error handling paths

Key Considerations:
- RAG (Retrieval-Augmented Generation) architecture
- Clear separation between user interface, business logic, and external services
- Code execution pipeline
- Demonstrate how course materials are integrated into the system
- Error handling and fallback paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer (Port 3000)"]
        UI[React Frontend]
        Chat["Chat Interface"]
        Input["User Input Handler"]
        App["Main Application Logic"]
        
        UI --> Chat
        UI --> Input
        UI --> App
    end

    subgraph Server["Server Layer (Port 8000)"]
        API["FastAPI Backend"]
        CodeExec["Code Execution Engine"]
        Context["Context Retrieval System"]
        Materials[(Course Materials)]
        
        API --> CodeExec
        API --> Context
        Context --> Materials
    end

    subgraph External["External Services"]
        OpenAI["OpenAI API"]
        VectorDB[(Vector Database)]
    end

    %% Main Data Flows
    Input --> API
    API --> OpenAI
    OpenAI --> API
    API --> Chat
    
    %% Code Execution Flow
    CodeExec --> API
    
    %% Knowledge Retrieval Flow
    Context --> VectorDB
    VectorDB --> Context
    
    %% Click Events
    click Chat "https://github.com/Nimastic/Berkeley-LLM-Agent-Hackathon/blob/main/frontend/src/ChatBubble.js"
    click Input "https://github.com/Nimastic/Berkeley-LLM-Agent-Hackathon/blob/main/frontend/src/ChatInput.js"
    click App "https://github.com/Nimastic/Berkeley-LLM-Agent-Hackathon/blob/main/frontend/src/App.js"
    click API "https://github.com/Nimastic/Berkeley-LLM-Agent-Hackathon/blob/main/backend/main.py"
    click Materials "https://github.com/Nimastic/Berkeley-LLM-Agent-Hackathon/blob/main/backend/data/sample_course_material.txt"
    click UI "https://github.com/Nimastic/Berkeley-LLM-Agent-Hackathon/blob/main/frontend/public/index.html"

    %% Styling
    classDef frontend fill:#3498db,color:white
    classDef backend fill:#2ecc71,color:white
    classDef external fill:#9b59b6,color:white
    classDef storage fill:#e67e22,color:white
    
    class UI,Chat,Input,App frontend
    class API,CodeExec,Context backend
    class OpenAI,VectorDB external
    class Materials storage

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Service"]:::backend
        ExtService["External Service"]:::external
        Storage["Storage"]:::storage
    end
```
