# mit-submit/a2rchi architecture

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

- Interactive diagram: https://gitdiagram.com/mit-submit/a2rchi
- Repository: https://github.com/mit-submit/a2rchi

## Overview

##### Main Components

a) Services Layer:
- Chat Service (service_chat.py)
- Cleo Service (service_cleo.py)
- Mailbox Service (service_mailbox.py)
- Piazza Service (service_piazza.py)
- Uploader Service (service_uploader.py)
- Account Creation Service (service_create_account.py)

b) Core AI Components:
- LLM Integration (chains/models.py)
- Chain Management (chains/chain.py, chains/base.py)
- Prompt Management (chains/prompts.py)

c) Data Storage:
- Vector Store (both HTTP ChromaDB and local options)
- SQL Database (utils/sql.py)

d) Interfaces:
- Chat Application (interfaces/chat_app)
- Uploader Application (interfaces/uploader_app)
- Cleo Interface (interfaces/cleo.py)

e) Utility Layer:
- Configuration Management (utils/config_loader.py)
- Data Management (utils/data_manager.py)
- Email Integration (utils/imap.py, utils/mailbox.py)
- Embedding Utilities (utils/embedding_utils.py)
- Web Scraping (utils/scraper.py)

**[Client Layer]**

**[Interface Layer]**

**[Service Layer]**

**[Core AI Layer]**

**[Data Layer]**

##### Deployment Aspects

A separate deployment view showing:
- Docker containers (from deploy/dockerfiles)
- Service composition (from deploy/*-compose.yaml files)
- Different deployment environments (dev, prod, etc.)

##### Additional Details

- Configuration management flow
- Where environment variables are used
- Points of extensibility
- Feedback loop for AI training

- Nested components
- Multiple connection types
- Export to high-resolution formats

Remember to maintain a balance between detail and clarity, focusing on the key architectural decisions while avoiding overwhelming detail at the component level.

This system design should reflect the modular nature of A2rchi, emphasizing its ability to work with different LLMs and its flexible data ingestion capabilities through various services.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef interface fill:#4287f5,stroke:#333,stroke-width:2px
    classDef service fill:#42f584,stroke:#333,stroke-width:2px
    classDef ai fill:#f5d742,stroke:#333,stroke-width:2px
    classDef data fill:#9642f5,stroke:#333,stroke-width:2px
    classDef utility fill:#a6a6a6,stroke:#333,stroke-width:2px
    classDef deployment fill:#f54242,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        Users[Users]
    end

    %% Interface Layer
    subgraph InterfaceLayer["Interface Layer"]
        ChatApp["Chat Application"]:::interface
        UploaderApp["Uploader Application"]:::interface
        CleoInterface["Cleo Interface"]:::interface
    end

    %% Service Layer
    subgraph ServiceLayer["Service Layer"]
        ChatService["Chat Service"]:::service
        CleoService["Cleo Service"]:::service
        MailboxService["Mailbox Service"]:::service
        PiazzaService["Piazza Service"]:::service
        UploaderService["Uploader Service"]:::service
        AccountService["Account Creation Service"]:::service
    end

    %% Core AI Layer
    subgraph CoreAILayer["Core AI Layer"]
        LLMIntegration["LLM Integration"]:::ai
        ChainManagement["Chain Management"]:::ai
        PromptManagement["Prompt Management"]:::ai
    end

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        VectorStore["Vector Store (ChromaDB)"]:::data
        SQLDatabase["SQL Database"]:::data
    end

    %% Utility Layer
    subgraph UtilityLayer["Utility Layer"]
        ConfigManager["Configuration Management"]:::utility
        DataManager["Data Management"]:::utility
        EmailIntegration["Email Integration"]:::utility
        EmbeddingUtils["Embedding Utilities"]:::utility
        WebScraper["Web Scraping"]:::utility
    end

    %% Connections
    Users --> ChatApp & UploaderApp & CleoInterface
    ChatApp --> ChatService
    UploaderApp --> UploaderService
    CleoInterface --> CleoService
    
    ChatService & CleoService & MailboxService & PiazzaService & UploaderService --> ChainManagement
    ChainManagement --> LLMIntegration
    ChainManagement --> PromptManagement
    
    LLMIntegration -.-> VectorStore
    ChainManagement -.-> SQLDatabase
    
    EmailIntegration --> MailboxService
    WebScraper --> PiazzaService
    
    DataManager --> VectorStore & SQLDatabase
    ConfigManager --> ServiceLayer
    EmbeddingUtils --> VectorStore

    %% Click Events
    click ChatService "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/bin/service_chat.py"
    click CleoService "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/bin/service_cleo.py"
    click MailboxService "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/bin/service_mailbox.py"
    click PiazzaService "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/bin/service_piazza.py"
    click UploaderService "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/bin/service_uploader.py"
    click AccountService "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/bin/service_create_account.py"
    click LLMIntegration "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/chains/models.py"
    click ChainManagement "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/chains/chain.py"
    click PromptManagement "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/chains/prompts.py"
    click SQLDatabase "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/utils/sql.py"
    click VectorStore "https://github.com/mit-submit/A2rchi/tree/main/deploy/dockerfiles/Dockerfile-chroma"
    click ChatApp "https://github.com/mit-submit/A2rchi/tree/main/a2rchi/interfaces/chat_app/"
    click UploaderApp "https://github.com/mit-submit/A2rchi/tree/main/a2rchi/interfaces/uploader_app/"
    click CleoInterface "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/interfaces/cleo.py"
    click ConfigManager "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/utils/config_loader.py"
    click DataManager "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/utils/data_manager.py"
    click EmailIntegration "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/utils/mailbox.py"
    click EmbeddingUtils "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/utils/embedding_utils.py"
    click WebScraper "https://github.com/mit-submit/A2rchi/blob/main/a2rchi/utils/scraper.py"

    %% Legend
    subgraph Legend
        L1["Interface Component"]:::interface
        L2["Service Component"]:::service
        L3["AI Component"]:::ai
        L4["Data Storage"]:::data
        L5["Utility Component"]:::utility
    end
```
