# jybaek/llm-with-slack architecture

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

- Interactive diagram: https://gitdiagram.com/jybaek/llm-with-slack
- Repository: https://github.com/jybaek/llm-with-slack

## Overview

##### Project type and purpose
- This is a backend API service built with FastAPI that acts as a “bridge” between Slack and multiple LLM providers (OpenAI GPT, Google Gemini, Anthropic Claude).
- Its sole purpose is to receive messages (and images) from Slack, forward them to the configured LLM, and relay the generated response back to Slack.

##### File structure
- Top‐level files: Dockerfile, .dockerignore, requirements.txt, README.md – indicate containerized deployment.
- app/
- config/ – environment‐based constants and messages
- dependencies.py – FastAPI dependency‐injection bindings
- main.py – FastAPI application instantiation and router mounting
- routers/ – HTTP endpoints, one for Slack event ingestion, one for ChatGPT testing
- services/ – wrappers around each LLM’s API (openai_chat, openai_images, google_gemini, anthropic_claude) plus Slack API calls
- utils/ – helper modules for file handling and message formatting
- internal/admin.py – (likely) internal administration or health endpoints

##### README for additional insights
- Describes environment variables (Slack token, LLM tokens, conversation history limits, default models).
- Describes local and Docker‐based execution flow.
- Mentions multimodal support (image processing via openai_images service).

##### Elements
- Clear labels: “Slack Events Webhook,” “FastAPI Routers,” “Service Layer,” “LLM API Clients,” “Slack Web API”
- from Slack → router endpoint
- from router → dependency‐injected service
- from service → external LLMs and back
- from service → Slack Web API
- Rectangles for internal components (routers, services, utils)

7. Detailed breakdown of components (don’t over-compartmentalize, but capture all major parts)
- FastAPI Application
- main.py
- dependencies.py
- Routers
- slack.py (handles incoming Slack events)
- chatgpt.py (test endpoint for direct ChatGPT calls)
- Services
- openai_chat.py, openai_images.py
- google_gemini.py
- anthropic_claude.py
- slack.py (sends messages back to Slack)
- Utils
- file.py (handle image upload/download)
- message.py (format payloads)
- Configuration
- constants.py, messages.py

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Slack
    SlackEvents["Slack Events Webhook"]:::external

    %% 3rd-Party Services
    SlackWebAPI["Slack Web API"]:::third
    OpenAIAPI["OpenAI API"]:::third
    GoogleAPI["Google Gemini API"]:::third
    AnthropicAPI["Anthropic Claude API"]:::third

    subgraph "Docker Container"
      subgraph "FastAPI Service"
        Main["main.py"]:::fastapi
        Dependencies["dependencies.py"]:::fastapi

        subgraph "Routers"
          SlackRouter["slack.py"]:::fastapi
          ChatRouter["chatgpt.py"]:::fastapi
        end

        subgraph "Services"
          SlackSvc["slack.py"]:::service
          OpenAIChat["openai_chat.py"]:::service
          OpenAIImg["openai_images.py"]:::service
          GoogleGem["google_gemini.py"]:::service
          AnthropicClaude["anthropic_claude.py"]:::service
        end

        subgraph "Utils"
          FileUtil["file.py"]:::util
          MsgUtil["message.py"]:::util
        end

        subgraph "Config"
          Constants["constants.py"]:::config
          Messages["messages.py"]:::config
        end

        Admin["admin.py"]:::fastapi
      end
    end

    %% Flows
    SlackEvents -->|POST event| SlackRouter
    Main -->|instantiates| Dependencies
    Main -->|mounts| SlackRouter
    Main -->|mounts| ChatRouter

    Dependencies -->|injects into| SlackRouter
    Dependencies -->|injects into| ChatRouter

    SlackRouter -->|calls| SlackSvc
    SlackRouter -->|calls| OpenAIChat
    SlackRouter -->|calls| OpenAIImg
    SlackRouter -->|calls| GoogleGem
    SlackRouter -->|calls| AnthropicClaude

    ChatRouter -->|calls| OpenAIChat

    SlackSvc -->|posts| SlackWebAPI
    OpenAIChat -->|requests| OpenAIAPI
    OpenAIImg -->|requests| OpenAIAPI
    GoogleGem -->|requests| GoogleAPI
    AnthropicClaude -->|requests| AnthropicAPI

    %% Utilities & Config usage
    SlackSvc --> MsgUtil
    OpenAIChat --> MsgUtil
    OpenAIImg --> FileUtil
    GoogleGem --> MsgUtil
    AnthropicClaude --> MsgUtil

    SlackSvc --> Constants
    OpenAIChat --> Constants
    OpenAIImg --> Constants
    GoogleGem --> Constants
    AnthropicClaude --> Constants

    %% Click Events
    click Main "https://github.com/jybaek/llm-with-slack/blob/main/app/main.py"
    click Dependencies "https://github.com/jybaek/llm-with-slack/blob/main/app/dependencies.py"
    click SlackRouter "https://github.com/jybaek/llm-with-slack/blob/main/app/routers/slack.py"
    click ChatRouter "https://github.com/jybaek/llm-with-slack/blob/main/app/routers/chatgpt.py"
    click SlackSvc "https://github.com/jybaek/llm-with-slack/blob/main/app/services/slack.py"
    click OpenAIChat "https://github.com/jybaek/llm-with-slack/blob/main/app/services/openai_chat.py"
    click OpenAIImg "https://github.com/jybaek/llm-with-slack/blob/main/app/services/openai_images.py"
    click GoogleGem "https://github.com/jybaek/llm-with-slack/blob/main/app/services/google_gemini.py"
    click AnthropicClaude "https://github.com/jybaek/llm-with-slack/blob/main/app/services/anthropic_claude.py"
    click FileUtil "https://github.com/jybaek/llm-with-slack/blob/main/app/utils/file.py"
    click MsgUtil "https://github.com/jybaek/llm-with-slack/blob/main/app/utils/message.py"
    click Constants "https://github.com/jybaek/llm-with-slack/blob/main/app/config/constants.py"
    click Messages "https://github.com/jybaek/llm-with-slack/blob/main/app/config/messages.py"
    click Admin "https://github.com/jybaek/llm-with-slack/blob/main/app/internal/admin.py"

    %% Styles
    classDef external fill:#f9d,stroke:#333,stroke-width:1px
    classDef third fill:#afa,stroke:#333,stroke-width:1px
    classDef fastapi fill:#8ad,stroke:#333,stroke-width:1px
    classDef service fill:#cfa,stroke:#333,stroke-width:1px
    classDef util fill:#fc9,stroke:#333,stroke-width:1px
    classDef config fill:#6af,stroke:#333,stroke-width:1px
```
