# hanesauce/slack-tipbot architecture

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

- Interactive diagram: https://gitdiagram.com/hanesauce/slack-tipbot
- Repository: https://github.com/hanesauce/slack-tipbot

## Overview

##### Project type and purpose
- This is a single-service Slack bot written in Ruby (using Sinatra and slack-ruby-client) that lets teammates tip each other in bitcoin (via Coinbase).
- It’s deployed as one Heroku dyno, connects to Redis for state, interacts with the Coinbase API for wallet operations, and uses the Slack RealTime and Web APIs for messaging and slash commands.

##### Key parts of the file tree
- tipbot.rb / commands.rb – the core bot logic and command handlers
- web.rb / config.ru – the HTTP endpoints (Sinatra) that receive slash-command webhooks or health checks
- initializers/ – setup code for Money gem, Redis client, Slack client
- Procfile / app.json – Heroku deployment config
- images/ – static emoji assets for reaction-based tipping
- Gemfile – dependencies (sinatra, slack-ruby-client, redis, coinbase, money, etc.)

##### Main components
A. Slack Platform (external)
– RealTime API (websocket events)
– Web API (messages, slash command responses)
B. Heroku Dyno (single process)
1. Slack RealTime Client (slack-ruby-client)
2. HTTP Server (Sinatra in web.rb)
3. Bot Core / Command Dispatcher (tipbot.rb + commands.rb)
4. Initializers (configuration for Redis, Money, Slack client)
C. Data Layer
– Redis (Heroku Redis add-on) stores user balances, transaction history
D. External Service
– Coinbase API Client for on/off-chain wallet creation, transfers
E. Static Assets
– images/ custom emoji files

##### Relationships and data flows
- Redis is read or written by dispatcher when querying/updating balances.
- Coinbase API calls (create account, send coins) occur in command handlers via coinbase‐ruby.

##### Architectural patterns and principles
- Event-driven: reacts to Slack events (messages, reactions, slash commands)
- Single responsibility: separate modules for configuration (initializers), web endpoints (web.rb), real-time client (tipbot.rb), and business logic (commands.rb)
- Adapter layers for external APIs (Slack, Coinbase)
- Stateless HTTP endpoints; ephemeral Process state backed by Redis

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Services
    subgraph "Slack Platform" 
        direction TB
        SlackRTM["RealTime API (WebSocket)"]:::external
        SlackWeb["Web API (HTTPS)"]:::external
    end

    %% Heroku Dyno Internal Components
    subgraph "Heroku Dyno (Ruby Bot)" 
        direction TB
        subgraph "Initializers"
            direction TB
            InitMoney["money.rb"]:::config
            InitRedis["redis.rb"]:::config
            InitSlackClient["slack_ruby_client.rb"]:::config
        end
        RTMClient["Slack RealTime Client"]:::internal
        HTTPServer["HTTP Server (Sinatra)"]:::internal
        CommandDispatcher["Bot Core / Command Dispatcher"]:::internal
    end

    %% Data Layer
    Redis["Redis (Heroku Add-on)"]:::datastore

    %% External Service Adapter
    Coinbase["Coinbase API"]:::external

    %% Static Assets
    Images["Custom Emoji Images"]:::assets

    %% Deployment Config
    subgraph "Deployment Configuration"
        direction TB
        ProcfileNode["Procfile"]:::deployment
        AppJson["app.json"]:::deployment
        GemfileNode["Gemfile"]:::deployment
    end

    %% Data Flows
    SlackRTM -->|"WebSocket event"| RTMClient
    SlackWeb -->|"Incoming slash command response"| HTTPServer
    RTMClient -->|"Event payload"| CommandDispatcher
    HTTPServer -->|"Slash command POST"| CommandDispatcher
    CommandDispatcher -->|"Read/Write"| Redis
    CommandDispatcher -->|"REST API calls"| Coinbase
    CommandDispatcher -->|"Post message"| SlackWeb

    %% Config Wiring
    InitMoney -.->|configures| CommandDispatcher
    InitRedis -.->|configures| CommandDispatcher
    InitSlackClient -.->|configures| RTMClient
    InitSlackClient -.->|configures| HTTPServer
    InitSlackClient -.->|configures| CommandDispatcher

    %% Static Assets Access
    CommandDispatcher -->|"Loads emoji"| Images

    %% Click Events
    click InitSlackClient "https://github.com/hanesauce/slack-tipbot/blob/master/initializers/slack_ruby_client.rb"
    click RTMClient "https://github.com/hanesauce/slack-tipbot/blob/master/tipbot.rb"
    click HTTPServer "https://github.com/hanesauce/slack-tipbot/blob/master/web.rb"
    click HTTPServer "https://github.com/hanesauce/slack-tipbot/blob/master/config.ru"
    click CommandDispatcher "https://github.com/hanesauce/slack-tipbot/blob/master/commands.rb"
    click InitMoney "https://github.com/hanesauce/slack-tipbot/blob/master/initializers/money.rb"
    click InitRedis "https://github.com/hanesauce/slack-tipbot/blob/master/initializers/redis.rb"
    click Redis "https://github.com/hanesauce/slack-tipbot/blob/master/initializers/redis.rb"
    click Coinbase "https://github.com/hanesauce/slack-tipbot/blob/master/commands.rb"
    click Images "https://github.com/hanesauce/slack-tipbot/tree/master/images/"
    click ProcfileNode "https://github.com/hanesauce/slack-tipbot/tree/master/Procfile"
    click AppJson "https://github.com/hanesauce/slack-tipbot/blob/master/app.json"
    click GemfileNode "https://github.com/hanesauce/slack-tipbot/tree/master/Gemfile"

    %% Styles
    classDef external fill:#F9F,stroke:#333,stroke-width:1px;
    classDef internal fill:#BBF,stroke:#333,stroke-width:1px;
    classDef datastore fill:#BFB,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
    classDef config fill:#FFB,stroke:#333,stroke-width:1px;
    classDef assets fill:#FFD,stroke:#333,stroke-width:1px;
    classDef deployment fill:#DDF,stroke:#333,stroke-width:1px;
```
