# timfanda35/simple-channel-notify architecture

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

- Interactive diagram: https://gitdiagram.com/timfanda35/simple-channel-notify
- Repository: https://github.com/timfanda35/simple-channel-notify

## Overview

##### Project Type and Purpose
- This is an open-source, single-binary CLI tool (written in Go) packaged as a Docker container.
- Its sole purpose is to send a simple text notification to one of several supported “channels” via each channel’s RESTful API endpoint (Telegram Bot API, LINE Notify, Hangouts Chat webhook, Slack Incoming Webhook, Discord Webhook).

##### Main Components
a. Host/CI System
- Local developer machine or CI/CD runner (GitHub Actions, GitLab CI, Google Cloud Build)
- Responsible for pulling the container image from `ghcr.io/timfanda35/simple-channel-notify` and setting environment variables for credentials.
b. Docker Container Image
- Multi-stage build (from Dockerfile) that compiles the Go code and produces a minimal runtime image.
c. Go CLI Application (inside container)
- Entry point: `main.go`
- Command parser: reads the first CLI argument (`telegram`, `linenotify`, `slack`, `discord`, or `hangoutschat`) and `--message` flag.
- Strategy Dispatcher: maps the channel name to the appropriate handler.
- Channel Handlers: for each supported channel, a small module/function that reads its specific environment variable(s) and formats an HTTP request.
- HTTP Client: issues a POST (or GET) to the external API endpoint with authentication and payload.
d. External Channel Services
- Telegram Bot API
- LINE Notify API
- Google Hangouts Chat Incoming Webhook
- Slack Incoming Webhook
- Discord Execute Webhook

##### Relationships & Data Flow
1. Developer/CI pulls the container image from GitHub Container Registry.
2. Environment variables (e.g. `NOTIFY_TELEGRAM_TOKEN`, `NOTIFY_TELEGRAM_CHAT_ID`) are injected by the host or CI runner.
3. `docker run ... simple-channel-notify <channel> --message="..."` starts the Go CLI inside the container.
4. The CLI parses the arguments, picks the correct channel handler, constructs an HTTP request.
5. The HTTP client in the container issues the request to the external service’s REST API.
6. The channel service returns an HTTP status; the CLI exits.

##### Architectural Patterns & Design Principles
- Single-responsibility: each channel handler only knows how to talk to its own API.
- Strategy pattern: a central dispatcher routes calls to the correct handler based on the CLI argument.
- Containerized deployment: isolating runtime dependencies and simplifying distribution.
- Environment-driven configuration: all secrets and endpoints are injected as environment variables.

##### Detail Level
- Every channel as a distinct handler component.
- Where environment variables map into each handler.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build & Registry
    subgraph "Build & Registry" 
        direction TB
        DF["Dockerfile"]:::build
        MI["Makefile"]:::build
        GM["go.mod"]:::build
        DI[".dockerignore"]:::build
        CI["CI/CD Pipeline"]:::build
        DOC["README.md"]:::build
        DF -->|multi-stage build| CI
        MI --> CI
        GM --> CI
        DI --> CI
        CI -->|"push image to ghcr.io"| IMG["ghcr.io/timfanda35/simple-channel-notify"]:::build
    end

    %% Host/CI Runner
    HCI["Host / CI Runner"]:::external
    IMG -->|pull image| HCI

    %% Docker Container Runtime
    subgraph "Docker Container : simple-channel-notify"
        direction TB
        CLI["Command Parser"]:::internal
        DISP["Strategy Dispatcher"]:::internal
        subgraph "Channel Handlers" 
            direction TB
            H_TG["Telegram Handler"]:::internal
            H_LN["LINE Notify Handler"]:::internal
            H_HC["Hangouts Chat Handler"]:::internal
            H_SL["Slack Handler"]:::internal
            H_DS["Discord Handler"]:::internal
        end
        HTTP["HTTP Client"]:::internal
        CLI --> DISP
        DISP --> H_TG
        DISP --> H_LN
        DISP --> H_HC
        DISP --> H_SL
        DISP --> H_DS
        H_TG --> HTTP
        H_LN --> HTTP
        H_HC --> HTTP
        H_SL --> HTTP
        H_DS --> HTTP
    end

    %% Flow from Host to Container
    HCI -->|docker run <channel> --message| CLI

    %% External Services
    subgraph "External Channel Services"
        direction TB
        TG["Telegram Bot API"]:::service
        LN["LINE Notify API"]:::service
        HC["Hangouts Chat Webhook"]:::service
        SL["Slack Incoming Webhook"]:::service
        DS["Discord Webhook"]:::service
    end

    HTTP -->|HTTP POST| TG
    HTTP -->|HTTP POST| LN
    HTTP -->|HTTP POST| HC
    HTTP -->|HTTP POST| SL
    HTTP -->|HTTP POST| DS

    %% Click Events
    click DF "https://github.com/timfanda35/simple-channel-notify/tree/master/Dockerfile"
    click MI "https://github.com/timfanda35/simple-channel-notify/tree/master/Makefile"
    click GM "https://github.com/timfanda35/simple-channel-notify/blob/master/go.mod"
    click DI "https://github.com/timfanda35/simple-channel-notify/blob/master/.dockerignore"
    click CI "https://github.com/timfanda35/simple-channel-notify/blob/master/.github/workflows/docker-publish.yml"
    click CLI "https://github.com/timfanda35/simple-channel-notify/blob/master/main.go"
    click DISP "https://github.com/timfanda35/simple-channel-notify/blob/master/main.go"
    click H_TG "https://github.com/timfanda35/simple-channel-notify/blob/master/main.go"
    click H_LN "https://github.com/timfanda35/simple-channel-notify/blob/master/main.go"
    click H_HC "https://github.com/timfanda35/simple-channel-notify/blob/master/main.go"
    click H_SL "https://github.com/timfanda35/simple-channel-notify/blob/master/main.go"
    click H_DS "https://github.com/timfanda35/simple-channel-notify/blob/master/main.go"
    click DOC "https://github.com/timfanda35/simple-channel-notify/blob/master/README.md"

    %% Styles
    classDef build fill:#F9E79F,stroke:#B7950B
    classDef internal fill:#D6EAF8,stroke:#1B4F72
    classDef external fill:#D5DBDB,stroke:#616A6B
    classDef service fill:#D5F5E3,stroke:#196F3D
```
