# appleboy/gorush architecture

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

- Interactive diagram: https://gitdiagram.com/appleboy/gorush
- Repository: https://github.com/appleboy/gorush

## Overview

##### Main Components Identification

a) Core Services:
- HTTP/HTTPS Server (Port 8088)
- gRPC Server (Optional, Port 9000)
- Queue System (Local Channel, NSQ, NATS, or Redis)
- Storage System (Memory, Redis, BoltDB, BuntDB, LevelDB, or BadgerDB)

b) Push Notification Services:
- APNS (Apple Push Notification Service)
- FCM (Firebase Cloud Messaging)
- HMS (Huawei Mobile Services)

**┌─────────────────────────────────────────────────────────────┐**
- Client Requests                         │
- (HTTP/HTTPS REST API, gRPC, Command Line Interface)      │
- ┬─────────────────────┬─────────────────┘

**┌───────────────────▼─────────────────────▼─────────────────┐**
- Gorush Server                           │
- ┌───────────────┐  ┌────────────┐  ┌─────────────┐      │
- API Router    │  │ Metrics    │  │ Health Check│      │
- ┬───────┘  └────────────┘  └─────────────┘      │

- ┌───────▼───────┐  ┌────────────┐  ┌─────────────┐      │
- Queue System  │  │ Worker Pool│  │ Status/Stats│      │
- ┬───────┘  └─────┬──────┘  └─────────────┘      │

- ┌───────▼────────────────▼──────┐   ┌──────────────┐    │
- Notification Manager     │   │Storage System │    │
- ┬──────────┬───────┘   └──────────────┘    │
- ┬┴──────────┴─────────┬────────────────────┘

**┌─────────────▼─────┐   ┌──────────▼────────┐   ┌─────────┐**
- APNS         │   │        FCM        │   │   HMS   │
- (iOS Platform)   │   │(Android Platform) │   │(Huawei) │
- ┘   └───────────────────┘   └─────────┘

##### Component Details

For each component, include:

a) API Router:
- HTTP endpoints (/api/push, /api/stat/go, /api/stat/app)
- gRPC service endpoints
- Configuration endpoints

b) Queue System:
- Support for multiple queue backends
- Worker pool configuration
- Queue size and worker numbers

c) Notification Manager:
- Platform-specific handlers (iOS, Android, Huawei)
- Retry mechanism
- Error handling

d) Storage System:
- Multiple storage backend options
- Stat storage
- Configuration storage

##### Additional Elements

Include:
- Configuration components
- Monitoring and metrics endpoints
- Health check endpoints
- Authentication/Security layers
- Docker/Kubernetes deployment options
- AWS Lambda integration

##### Deployment Options

Different deployment scenarios:
- Standalone server
- Docker container
- Kubernetes cluster
- AWS Lambda function

- High availability
- Scalability
- Multiple platform support
- Flexible storage options
- Monitoring and metrics
- Multiple deployment options

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        HTTP["HTTP/HTTPS API (8088)"]
        GRPC["gRPC API (9000)"]
        CLI["Command Line Interface"]
    end

    subgraph "Server Layer"
        Router["API Router"]:::router
        GRPCServer["gRPC Server"]:::grpc
        Lambda["Lambda Server"]:::lambda
    end

    subgraph "Core Layer"
        Core["Core System"]:::core
        Queue["Queue System"]:::queue
        Health["Health Check"]:::health
        Metrics["Metrics System"]:::metrics
        Status["Status/Stats"]:::status
        Config["Configuration"]:::config
        Logger["Logging System"]:::logger
    end

    subgraph "Storage Layer"
        StorageInterface["Storage Interface"]:::storage
        subgraph "Storage Implementations"
            Redis["Redis"]:::storage
            BoltDB["BoltDB"]:::storage
            Memory["Memory"]:::storage
            LevelDB["LevelDB"]:::storage
            BadgerDB["BadgerDB"]:::storage
            BuntDB["BuntDB"]:::storage
        end
    end

    subgraph "Notification Layer"
        NotifyCore["Notification Core"]:::notify
        APNS["APNS (iOS)"]:::notify
        FCM["FCM (Android)"]:::notify
        HMS["HMS (Huawei)"]:::notify
    end

    subgraph "Deployment Layer"
        Docker["Docker"]:::deploy
        K8s["Kubernetes"]:::deploy
        Helm["Helm Charts"]:::deploy
    end

    %% Connections
    HTTP --> Router
    GRPC --> GRPCServer
    CLI --> Core

    Router --> Core
    GRPCServer --> Core
    Lambda --> Core

    Core --> Queue
    Core --> Health
    Core --> Metrics
    Core --> Status
    Core --> Logger
    Core --> Config

    Core --> StorageInterface
    StorageInterface --> Redis
    StorageInterface --> BoltDB
    StorageInterface --> Memory
    StorageInterface --> LevelDB
    StorageInterface --> BadgerDB
    StorageInterface --> BuntDB

    Core --> NotifyCore
    NotifyCore --> APNS
    NotifyCore --> FCM
    NotifyCore --> HMS

    %% Styles
    classDef router fill:#9cf
    classDef grpc fill:#9cf
    classDef lambda fill:#9cf
    classDef core fill:#90EE90
    classDef queue fill:#FFB347
    classDef health fill:#D3D3D3
    classDef metrics fill:#D3D3D3
    classDef status fill:#D3D3D3
    classDef config fill:#D3D3D3
    classDef logger fill:#D3D3D3
    classDef storage fill:#FFB347
    classDef notify fill:#FF6961
    classDef deploy fill:#B19CD9

    %% Click events
    click Router "https://github.com/appleboy/gorush/blob/master/router/server_normal.go"
    click GRPCServer "https://github.com/appleboy/gorush/blob/master/rpc/server.go"
    click Lambda "https://github.com/appleboy/gorush/blob/master/router/server_lambda.go"
    click Core "https://github.com/appleboy/gorush/blob/master/core/core.go"
    click Queue "https://github.com/appleboy/gorush/blob/master/core/queue.go"
    click Health "https://github.com/appleboy/gorush/blob/master/core/health.go"
    click Metrics "https://github.com/appleboy/gorush/blob/master/metric/metrics.go"
    click Status "https://github.com/appleboy/gorush/blob/master/status/status.go"
    click Config "https://github.com/appleboy/gorush/blob/master/config/config.go"
    click Logger "https://github.com/appleboy/gorush/blob/master/logx/log.go"
    click StorageInterface "https://github.com/appleboy/gorush/blob/master/storage/storage.go"
    click Redis "https://github.com/appleboy/gorush/blob/master/storage/redis/redis.go"
    click BoltDB "https://github.com/appleboy/gorush/blob/master/storage/boltdb/boltdb.go"
    click Memory "https://github.com/appleboy/gorush/blob/master/storage/memory/memory.go"
    click LevelDB "https://github.com/appleboy/gorush/blob/master/storage/leveldb/leveldb.go"
    click BadgerDB "https://github.com/appleboy/gorush/blob/master/storage/badger/badger.go"
    click BuntDB "https://github.com/appleboy/gorush/blob/master/storage/buntdb/buntdb.go"
    click NotifyCore "https://github.com/appleboy/gorush/blob/master/notify/notification.go"
    click APNS "https://github.com/appleboy/gorush/blob/master/notify/notification_apns.go"
    click FCM "https://github.com/appleboy/gorush/blob/master/notify/notification_fcm.go"
    click HMS "https://github.com/appleboy/gorush/blob/master/notify/notification_hms.go"
    click Docker "https://github.com/appleboy/gorush/tree/master/docker/Dockerfile"
    click K8s "https://github.com/appleboy/gorush/blob/master/k8s/gorush-deployment.yaml"
    click Helm "https://github.com/appleboy/gorush/blob/master/helm/gorush/templates/deployment.yaml"
```
