# stewart86/bobby architecture

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

- Interactive diagram: https://gitdiagram.com/stewart86/bobby
- Repository: https://github.com/stewart86/bobby

## Overview

##### Project Type & Purpose
- Bobby is a self-hosted, Dockerized Discord chatbot service.
- It listens to Discord messages, uses Claude Code (Anthropic) for AI reasoning over a user’s GitHub-hosted codebase, and can open GitHub issues for detected bugs.

##### High-Level Structure from File Tree
- Root files:
– index.js: main bot logic (event handlers, orchestration).
– entrypoint.sh: container startup script (initializes CLI tools).
– Dockerfile & .dockerignore: build container image.
– .env.example: environment variables template.
- .github/workflows/docker-publish.yml: CI/CD pipeline building/publishing Docker images.
- CLAUDE.md: local memory/instructions for Claude Code CLI.
- package.json: Node/Bun dependencies (discord.js, @anthropic-ai/claude-code, @octokit or GitHub CLI).

##### Core Components to Model
a. Docker Container
b. Discord Client Module (Discord.js)
c. Claude Code CLI / Anthropic API (AI Engine)
d. GitHub CLI / GitHub API Integration
e. Local Data Volume (/app/data, houses CLAUDE.md, cloned repo)
f. External Services:
– Discord Gateway API
– Anthropic Claude API
– GitHub API
g. CI/CD Pipeline (GitHub Actions → Docker Hub)

##### Component Interactions & Data Flows
- On startup:
1. entrypoint.sh runs → installs/configures Claude CLI, authenticates GitHub CLI.
2. index.js connects to Discord Gateway with DISCORD_TOKEN.
- On “@Bobby” mention:
1. Discord Gateway → Discord.js event → index.js.
2. Bot clones (or updates) GITHUB_REPO locally using GitHub CLI → local volume.
3. index.js invokes Claude Code CLI with codebase context from /app/data & CLAUDE.md → Anthropic Claude API → CLI returns AI response.
4. index.js posts response back to Discord channel or thread.
5. If bug patterns detected, index.js calls GitHub CLI (or Octokit) → GitHub API → creates GitHub Issue.
- Persistent context:
– CLAUDE.md and thread-based session IDs stored on volume.
- CI/CD:
– GitHub Actions on push → builds image → docker-publish → Docker Hub.

##### Architectural Patterns & Principles
- Event-Driven: Discord events trigger AI and GitHub actions.
- Modular CLI Wrappers: Abstracts AI and Git interactions through CLIs.
- Read-Only Code Analysis: No code mutations—CLI & API calls only.
- Containerization & Isolation: Single-container service per repo.
- Thread-Based Session Management: Maintains per-thread context in Discord.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CI/CD Pipeline"
        GHActions["GitHub Actions"]:::external
        DockerHub["Docker Hub"]:::external
        GHActions -->|"build & publish"| DockerHub
        DockerHub -->|"deploy image"| Entrypoint
    end

    subgraph "Bobby Container"
        direction TB
        Env["Env Vars:\nDISCORD_TOKEN\nANTHROPIC_API_KEY\nGH_TOKEN\nGITHUB_REPO\nALLOWED_DISCORD_SERVERS"]:::internal
        Entrypoint["entrypoint.sh"]:::internal
        DockerfileNode["Dockerfile"]:::internal
        Dockerignore[".dockerignore"]:::internal
        DiscordClient["Discord Client\n(index.js)"]:::internal
        ClaudeAdapter["Claude Code Adapter"]:::internal
        GitHubAdapter["GitHub Adapter"]:::internal
        Volume["Local Data Volume\n(/app/data)"]:::storage
        CLAUDEmd["CLAUDE.md"]:::storage

        Entrypoint -->|"initialize CLI tools"| DiscordClient
        Entrypoint -->|"initialize CLI tools"| ClaudeAdapter
        Entrypoint -->|"initialize CLI tools"| GitHubAdapter
        DiscordClient -->|"invoke clone/update"| GitHubAdapter
        DiscordClient -->|"invoke analyze"| ClaudeAdapter
        GitHubAdapter -->|"access data"| Volume
        ClaudeAdapter -->|"read context"| Volume
        ClaudeAdapter -->|"read instructions"| CLAUDEmd
    end

    subgraph "External Services"
        direction TB
        DiscordGateway["Discord Gateway API"]:::external
        AnthropicAPI["Anthropic Claude API"]:::external
        GitHubAPI["GitHub API"]:::external

        DiscordGateway -->|"@mention event"| DiscordClient
        DiscordClient -->|"send message"| DiscordGateway
        GitHubAdapter -->|"clone/update"| GitHubAPI
        ClaudeAdapter -->|"analyze code"| AnthropicAPI
        DiscordClient -->|"create issue"| GitHubAPI
    end

    click Entrypoint "https://github.com/stewart86/bobby/blob/main/entrypoint.sh"
    click DockerfileNode "https://github.com/stewart86/bobby/tree/main/Dockerfile"
    click Dockerignore "https://github.com/stewart86/bobby/blob/main/.dockerignore"
    click DiscordClient "https://github.com/stewart86/bobby/blob/main/index.js"
    click CLAUDEmd "https://github.com/stewart86/bobby/blob/main/CLAUDE.md"
    click GHActions "https://github.com/stewart86/bobby/blob/main/.github/workflows/docker-publish.yml"

    classDef external fill:#ADD8E6,stroke:#000
    classDef internal fill:#9FE2BF,stroke:#000
    classDef storage fill:#FFA500,stroke:#000
```
