# leporejoseph/crewbot architecture

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

- Interactive diagram: https://gitdiagram.com/leporejoseph/crewbot
- Repository: https://github.com/leporejoseph/crewbot

## Overview

##### Main Components

a) Frontend Layer:
- Streamlit UI components (primary user interface)
- User interaction components (forms, buttons, chat interface)
- Document upload/download interface

b) Application Core:
- CrewAI integration layer
- LLM handler system
- Document processing system
- Configuration management

c) External Services:
- OpenAI API integration
- Groq API integration
- LM Studio integration
- Optional API services (Browserbase, Serper)

d) Storage Layer:
- Local JSON storage (crews.json, user_preferences.json, user_chat_history.json)
- Document storage
- Environment configuration (.env)

**[User Interface Layer]**
- ↕
**[Application Core Layer]**
- ↕
**[External Services & Storage Layer]**

##### Component Relationships

a) User Interface Flow:
**Streamlit UI → Application Core**
- ↓
**Chat Interface ←→ LLM Handler**
- ↓
**Document Interface ←→ Document Handler**

b) Core Processing Flow:
**CrewAI Utils ←→ LLM Handler**
- ↓
**Document Handler ←→ Storage**
- ↓
**Configuration Manager**

##### Specific Implementation Details

**1. User Input → Streamlit Interface**
**2. Streamlit → CrewAI Utils (crew creation/management)**
**3. CrewAI Utils → LLM Handler (model selection/interaction)**
**4. Document Handler → Storage (PDF/text processing)**
**5. Configuration → All Components (env vars, preferences)**

##### Important Subsystems to Highlight

a) CrewAI Management System:
- Agent creation/editing
- Task management
- Crew execution pipeline

b) LLM Integration System:
- Model switching capability
- API key management
- Response handling

c) Document Processing Pipeline:
- Upload handling
- Processing chain
- PDF generation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        direction TB
        StreamlitUI["Streamlit UI"]
        ChatInterface["Chat Interface"]
        DocInterface["Document Interface"]
    end

    subgraph Core["Application Core"]
        direction TB
        AppEntry["Main Application"]
        Config["Configuration Manager"]
        CrewAI["CrewAI Integration"]
        LLMHandler["LLM Handler"]
        DocHandler["Document Handler"]
    end

    subgraph External["External Services"]
        direction TB
        OpenAI["OpenAI API"]
        Groq["Groq API"]
        LMStudio["LM Studio"]
        OptAPIs["Optional APIs"]
    end

    subgraph Storage["Storage Layer"]
        direction TB
        CrewStorage["Crew Data"]
        UserPrefs["User Preferences"]
        ChatHistory["Chat History"]
        EnvConfig["Environment Config"]
        DocStorage["Document Storage"]
    end

    %% Relationships
    StreamlitUI --> AppEntry
    ChatInterface --> LLMHandler
    DocInterface --> DocHandler

    AppEntry --> Config
    AppEntry --> CrewAI
    CrewAI --> LLMHandler
    LLMHandler --> DocHandler

    LLMHandler --> OpenAI
    LLMHandler --> Groq
    LLMHandler --> LMStudio
    LLMHandler --> OptAPIs

    CrewAI --> CrewStorage
    Config --> UserPrefs
    Config --> EnvConfig
    ChatInterface --> ChatHistory
    DocHandler --> DocStorage

    %% Click Events
    click StreamlitUI "https://github.com/leporejoseph/crewBot/blob/main/src/utils/streamlit_expander.py"
    click AppEntry "https://github.com/leporejoseph/crewBot/blob/main/src/app.py"
    click Config "https://github.com/leporejoseph/crewBot/blob/main/src/config.py"
    click CrewAI "https://github.com/leporejoseph/crewBot/blob/main/src/crew_ai/crewai_utils.py"
    click LLMHandler "https://github.com/leporejoseph/crewBot/blob/main/src/utils/llm_handler.py"
    click DocHandler "https://github.com/leporejoseph/crewBot/blob/main/src/utils/document_handler.py"
    click CrewStorage "https://github.com/leporejoseph/crewBot/blob/main/src/crew_ai/crews.json"
    click UserPrefs "https://github.com/leporejoseph/crewBot/blob/main/src/utils/user_preferences.json"
    click ChatHistory "https://github.com/leporejoseph/crewBot/blob/main/src/utils/user_chat_history.json"
    click EnvConfig "https://github.com/leporejoseph/crewBot/blob/main/src/.env"

    %% Styling
    classDef ui fill:#2374AB,color:#fff
    classDef core fill:#45B7D1,color:#fff
    classDef external fill:#F7A072,color:#000
    classDef storage fill:#848FA5,color:#fff

    class StreamlitUI,ChatInterface,DocInterface ui
    class AppEntry,Config,CrewAI,LLMHandler,DocHandler core
    class OpenAI,Groq,LMStudio,OptAPIs external
    class CrewStorage,UserPrefs,ChatHistory,EnvConfig,DocStorage storage
```
