# frinsdev/ruby-semaphore-sms architecture

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

- Interactive diagram: https://gitdiagram.com/frinsdev/ruby-semaphore-sms
- Repository: https://github.com/frinsdev/ruby-semaphore-sms

## Overview

##### Main components
- Consumer Application: any Ruby/Rails app or script that uses the gem.
- Configuration Layer: initializer (`Semaphore.configure`) that holds API key & sender name.
- Core Gem Modules (in lib/semaphore/):
- Semaphore::Client – public API methods (messages, otp).
- Semaphore::HTTP – builds and sends HTTP requests.
- Semaphore::Compatibility – backwards-compat layer if needed.
- Semaphore::Railtie – Rails integration (initializer hooks).
- External Service: Semaphore REST API endpoints.

##### Relationships & data flow
- Consumer App → invokes → Semaphore::Client.new (with config)
- Semaphore::Client.method (e.g., messages) → delegates to → Semaphore::HTTP
- Semaphore::HTTP → makes HTTPS calls → Semaphore.co API → receives JSON response
- Response travels back: HTTP → Client → Consumer App
- If in Rails environment, Railtie wires up the initializer at boot.

##### Architectural patterns & principles
- Separation of concerns:
- Client (business-level API) vs. HTTP (transport) vs. Configuration.
- Dependency injection: API key & sender name passed into Client or globally via configure.
- Extension points:
- Compatibility module for legacy behaviors.
- Railtie for seamless Rails hookup.

##### Technologies & libraries
- Ruby
- Faraday or Net::HTTP (depending on implementation in HTTP module)
- Bundler (Gemfile)
- Rails (optional integration via Railtie)
- Rake (tasks in Rakefile)
- Bin scripts for console/setup

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Consumer Environment"
        App["Consumer App"]:::externalUser
        BinConsole["bin/console"]:::tool
        BinSetup["bin/setup"]:::tool
        RakefileNode["Rakefile"]:::tool
        Gemspec["ruby-semaphore.gemspec"]:::tool
    end

    subgraph "Semaphore Gem"
        subgraph "Configuration & Metadata"
            Version["Semaphore::Version"]:::config
            Config["Configuration Layer\n(Semaphore.configure)"]:::config
        end
        subgraph "Core Modules"
            Client["Semaphore::Client"]:::core
            HTTP["Semaphore::HTTP"]:::core
        end
        subgraph "Extensions & Integration"
            Compatibility["Semaphore::Compatibility"]:::core
            Railtie["Semaphore::Railtie"]:::config
        end
    end

    ExternalAPI["Semaphore REST API"]:::external
    RailsBoot["Rails Boot"]:::externalUser

    App -->|"calls messages()/otp()"| Client
    Config -->|"injects API key & sender"| Client
    Client -->|"delegates request"| HTTP
    HTTP -->|"HTTPS JSON"| ExternalAPI
    ExternalAPI -->|"JSON response"| HTTP
    HTTP --> Client
    Client --> App

    RailsBoot --> Railtie
    Railtie --> Config

    click Client "https://github.com/frinsdev/ruby-semaphore-sms/blob/main/lib/semaphore/client.rb"
    click HTTP "https://github.com/frinsdev/ruby-semaphore-sms/blob/main/lib/semaphore/http.rb"
    click Compatibility "https://github.com/frinsdev/ruby-semaphore-sms/blob/main/lib/semaphore/compatibility.rb"
    click Railtie "https://github.com/frinsdev/ruby-semaphore-sms/blob/main/lib/semaphore/railtie.rb"
    click Config "https://github.com/frinsdev/ruby-semaphore-sms/blob/main/lib/semaphore.rb"
    click Version "https://github.com/frinsdev/ruby-semaphore-sms/blob/main/lib/semaphore/version.rb"
    click BinConsole "https://github.com/frinsdev/ruby-semaphore-sms/tree/main/bin/console"
    click BinSetup "https://github.com/frinsdev/ruby-semaphore-sms/tree/main/bin/setup"
    click RakefileNode "https://github.com/frinsdev/ruby-semaphore-sms/tree/main/Rakefile"
    click Gemspec "https://github.com/frinsdev/ruby-semaphore-sms/blob/main/ruby-semaphore.gemspec"

    classDef core fill:#D6EAF8,stroke:#3498DB
    classDef config fill:#D5F5E3,stroke:#27AE60
    classDef external fill:#FCF3CF,stroke:#F1C40F
    classDef tool fill:#F2F4F4,stroke:#BDC3C7
    classDef externalUser fill:#FDEDEC,stroke:#E74C3Cinson
```
