# android-sms-gateway/server architecture

> Architecture diagram of the GitHub repository android-sms-gateway/server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/android-sms-gateway/server
- Repository: https://github.com/android-sms-gateway/server

## Overview

##### Main Components

a) Core Server Components:
- HTTP Server Layer (handling REST API endpoints)
- Authentication Module (for private mode access control)
- Device Management Service
- Message Processing Service
- Webhook Service
- Health Monitoring System
- Metrics Collection System

b) External Services:
- Firebase Cloud Messaging (FCM) Integration
- MySQL/MariaDB Database
- Upstream API Service (for private mode notifications)

##### Key Relationships to Highlight

- Client Applications → HTTP API Layer
- Android Devices ↔ Server (via REST API)
- Server ↔ FCM (for push notifications)
- Server ↔ Database (for persistence)
- Server ↔ Webhook Consumers (for notifications)

##### Detailed Component Breakdown

- Auth Module (auth/)
- Device Management (devices/)
- Message Handling (messages/)
- Push Notifications (push/)
- Webhook Management (webhooks/)
- Health Monitoring (health/)
- Metrics Collection (metrics/)

##### Two Mode Representations

- Public Mode Operation
- Private Mode Operation (with additional security layer)

##### Architectural Patterns to Emphasize

- Modular architecture (based on the internal/sms-gateway/modules structure)
- RESTful API design
- Event-driven architecture (webhooks)
- Database migration system
- Health check system

##### Technical Details

Annotations for:
- API endpoints (/api/mobile/v1/*)
- Database migrations (from db/migrations)
- Configuration options (from configs/)
- Deployment options (Docker/Docker Swarm)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Legend"
        L1[Core Server Component]:::core
        L2[External Service]:::external
        L3[Security Checkpoint]:::security
        L4[(Data Store)]:::datastore
        L5[API Endpoint]:::api
    end

    subgraph "HTTP Layer"
        API["HTTP Server Layer"]:::core
        MobileAPI["Mobile API"]:::api
        DeviceAPI["Device API"]:::api
        WebhookAPI["Webhook API"]:::api
    end

    subgraph "Core Services"
        Auth["Authentication Module"]:::core
        DeviceMgmt["Device Management"]:::core
        MessageProc["Message Processing"]:::core
        WebhookSvc["Webhook Service"]:::core
        Health["Health Monitoring"]:::core
        Metrics["Metrics Collection"]:::core
    end

    subgraph "External Services"
        FCM["Firebase Cloud Messaging"]:::external
        UpstreamAPI["Upstream API Service"]:::external
    end

    subgraph "Data Layer"
        DB[(MySQL/MariaDB)]:::datastore
        Migrations["Database Migrations"]:::core
        Config["Configuration"]:::core
    end

    %% Relationships
    API --> Auth
    API --> |REST| MobileAPI
    API --> |REST| DeviceAPI
    API --> |REST| WebhookAPI
    
    Auth --> DeviceMgmt
    Auth --> MessageProc
    Auth --> WebhookSvc
    
    DeviceMgmt --> DB
    MessageProc --> DB
    WebhookSvc --> DB
    
    MessageProc --> FCM
    MessageProc --> UpstreamAPI
    
    DB --> Migrations
    
    Health --> API
    Health --> DB
    Metrics --> API
    Metrics --> DB

    %% Click Events
    click API "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/handlers/"
    click Auth "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/modules/auth/"
    click DeviceMgmt "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/modules/devices/"
    click MessageProc "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/modules/messages/"
    click WebhookSvc "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/modules/webhooks/"
    click Health "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/modules/health/"
    click Metrics "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/modules/metrics/"
    click FCM "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/modules/push/fcm/"
    click Migrations "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/models/migrations/mysql/"
    click UpstreamAPI "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/modules/push/upstream/"
    click Config "https://github.com/android-sms-gateway/server/tree/master/internal/config/"
    click MobileAPI "https://github.com/android-sms-gateway/server/blob/master/internal/sms-gateway/handlers/mobile.go"
    click DeviceAPI "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/handlers/devices/"
    click WebhookAPI "https://github.com/android-sms-gateway/server/tree/master/internal/sms-gateway/handlers/webhooks/"

    %% Styles
    classDef core fill:#a8d1ff,stroke:#000
    classDef external fill:#90EE90,stroke:#000
    classDef security fill:#FFD700,stroke:#000
    classDef datastore fill:#DDA0DD,stroke:#000
    classDef api fill:#FFA07A,stroke:#000
```
