# mochisuna/slack-reaction-award architecture

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

- Interactive diagram: https://gitdiagram.com/mochisuna/slack-reaction-award
- Repository: https://github.com/mochisuna/slack-reaction-award

## Overview

This project is a Go-based utility that calculates Slack reaction metrics and posts awards across four categories in your Slack workspace. The purpose is clearly outlined in the README, and the file tree reinforces a layered architecture that separates concerns into domain logic, application coordination, request handling, and configuration.

##### Main components
- Entry Point: The project entry is in cmd/app/main.go, which initializes and orchestrates the application.
- Application Layer: Located in the “application” directory, with files such as app.go, ranking.go, and slack.go. This layer acts as a coordinator between higher-level application flows and lower-level domain logic.
- Domain Layer: Found in the “domain” directory with files ranking.go and slack.go. This is where the core business logic resides – the rules and computations related to Slack reaction rankings.
- Handler Layer: The “handler” directory contains ranking.go and slack.go, which likely serve as adapters to handle incoming requests or events (for instance, formatting data from Slack or for posting messages).
- Configuration: The “config” directory (with config/config.go) is responsible for holding configuration data that the app uses, likely loaded at startup.
- Tools and Local Config: The _tools/local folder contains additional configuration (config.toml) needed to set Slack tokens, channels, and other runtime settings.
- External Service: Slack is a major external dependency, as the script interacts with Slack APIs (reading channels, posting messages, reading reactions, etc.).

##### Relationships and interactions
- The Entry Point (cmd/app/main.go) boots the application, reads configuration, and wires together the components.
- The Application Layer orchestrates the ranking calculations and Slack notifications by invoking methods from the Domain Layer.
- The Domain Layer encapsulates rules for computing awards based on Slack reaction counts (laughter, variety, amount, and thanks).
- The Handler Layer formats inputs and outputs. Although not a web server per se, handlers abstract input data from Slack and potentially convert responses for output into Slack messaging.
- The Config component is used by multiple layers to obtain necessary settings (like Slack token, channel IDs, and year) to call the Slack API.
- External Slack API is integrated via calls from both the Application and Domain layers (wrapped in “slack.go” files) to read reaction counts and to post messages.

##### Architectural patterns and design principles
- Layered Architecture: There is a clear separation into entry layer, application logic, domain business rules, and handlers.
- Separation of Concerns: Each directory or package handles distinct tasks (configuration, business logic, CLI tools, etc.).
- External Integration: The system uses clearly defined adapters to interact with external services (i.e., Slack API), respecting a separation between internal logic and external communication.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point and Configuration
    EP["Entry Point (cmd/app/main.go)"]:::internal
    CONFIG["Configuration (config/config.go)"]:::config
    TOOLS["Local Config (_tools/local/config.toml)"]:::config

    %% Application Layer Subgraph
    subgraph "Application Layer"
        APPCoord["App Coordination (app.go)"]:::internal
        APPRanking["Ranking Processor (ranking.go)"]:::internal
        APPSlack["Slack Adapter (slack.go)"]:::internal
    end

    %% Domain Layer Subgraph
    subgraph "Domain Layer"
        DOMRanking["Ranking Logic (ranking.go)"]:::internal
        DOMSlack["Slack Business (slack.go)"]:::internal
    end

    %% Handler Layer Subgraph
    subgraph "Handler Layer"
        HANDRanking["Ranking Handler (ranking.go)"]:::internal
        HANDSlack["Slack Handler (slack.go)"]:::internal
    end

    %% External Slack API
    EXTERNAL["External Slack API"]:::external

    %% Connections from Entry Point
    EP -->|"loads"| CONFIG
    EP -->|"initiates"| APPCoord
    EP -->|"activates"| HANDRanking

    %% Configuration usage
    CONFIG -->|"configures"| APPCoord
    CONFIG -->|"configures"| HANDRanking
    CONFIG -->|"configures"| APPSlack
    TOOLS -->|"provides"| CONFIG

    %% Internal Application flow
    APPCoord -->|"coordinates"| APPRanking
    APPCoord -->|"coordinates"| APPSlack

    %% Application to Domain communication
    APPRanking -->|"delegates"| DOMRanking
    APPSlack -->|"delegates"| DOMSlack

    %% Handler interactions
    HANDRanking -->|"forwards to"| APPCoord
    HANDSlack -->|"forwards to"| APPSlack

    %% External Slack API interactions
    APPSlack -->|"calls"| EXTERNAL
    DOMSlack -->|"calls"| EXTERNAL

    %% Click Events
    click EP "https://github.com/mochisuna/slack-reaction-award/blob/master/cmd/app/main.go"
    click APPCoord "https://github.com/mochisuna/slack-reaction-award/blob/master/application/app.go"
    click APPRanking "https://github.com/mochisuna/slack-reaction-award/blob/master/application/ranking.go"
    click APPSlack "https://github.com/mochisuna/slack-reaction-award/blob/master/application/slack.go"
    click DOMRanking "https://github.com/mochisuna/slack-reaction-award/blob/master/domain/ranking.go"
    click DOMSlack "https://github.com/mochisuna/slack-reaction-award/blob/master/domain/slack.go"
    click HANDRanking "https://github.com/mochisuna/slack-reaction-award/blob/master/handler/ranking.go"
    click HANDSlack "https://github.com/mochisuna/slack-reaction-award/blob/master/handler/slack.go"
    click CONFIG "https://github.com/mochisuna/slack-reaction-award/blob/master/config/config.go"
    click TOOLS "https://github.com/mochisuna/slack-reaction-award/blob/master/_tools/local/config.toml"

    %% Styles
    classDef internal fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef config fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
```
