# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Rybbit Analytics Platform
spec:
    description: Rybbit is a powerful web analytics platform with real-time data tracking and analytics capabilities.
    coverImage: https://cdn-console.zeabur.com/f/5WSW/rybbit-cover.png
    icon: https://avatars.githubusercontent.com/u/208537280?s=200&v=4
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Domain
          description: What is the domain for your Rybbit analytics platform?
    tags:
        - Analytics
        - Dashboard
        - Database
        - Monitoring
    readme: |
        # Rybbit Analytics Platform

        Rybbit is a powerful and privacy-focused web analytics platform that provides real-time insights into your website's performance and user behavior.

        ⚠️ Note: Make sure to bind your domain to the `caddy` service, as it is the single entry point for accessing your Rybbit analytics platform.

        ## Usage

        The `caddy` service acts as the entry point for your Rybbit instance. It is a reverse proxy that routes all traffic to the appropriate services. You should bind your custom domain to this service to access your Rybbit platform.

        Key features of the entry service:
        - Handles all incoming HTTP/HTTPS traffic
        - Routes requests to the correct services (backend API, frontend client)
        - Provides SSL/TLS termination
        - Manages domain binding and routing rules

        ## Features

        - **Real-time Analytics**: Track visitor behavior and site performance in real-time
        - **Privacy-Focused**: Respects user privacy while providing valuable insights
        - **Custom Dashboard**: Beautiful and intuitive dashboard for data visualization
        - **Multi-database Support**: Utilizes both PostgreSQL and ClickHouse for optimal performance
        - **Scalable Architecture**: Built to handle high-traffic websites

        ## Services Included

        This template deploys a complete Rybbit analytics stack:

        - **Caddy**: Reverse proxy with automatic HTTPS (entry point)
        - **PostgreSQL**: Primary database for user data and configuration
        - **ClickHouse**: High-performance analytics database for event tracking
        - **Backend**: Node.js API server
        - **Client**: Next.js frontend application

        ## Configuration

        After deployment:

        1. **Access your dashboard** using the domain you configured
        2. **Configure authentication** with the provided auth secret
        3. **Set up tracking** by adding the Rybbit tracking script to your websites
        4. **Monitor analytics** through the beautiful dashboard interface

        ## Database Access

        - **PostgreSQL**: Used for user accounts, site configurations, and metadata
        - **ClickHouse**: Optimized for storing and querying large volumes of analytics data

        ## Environment Variables

        The template configures all necessary environment variables automatically. You can modify these in the service settings if needed:

        - Database connections and credentials
        - Authentication settings
        - Feature toggles (like signup disable)

        ## Getting Started

        1. Deploy this template
        2. Bind your domain to the Caddy service
        3. Access your Rybbit dashboard
        4. Create your first tracking site
        5. Add the tracking code to your website

        For more information, visit the [Rybbit documentation](https://github.com/rybbit-io/rybbit).
    services:
        - name: caddy
          icon: https://cdn.zeabur.com/caddy.png
          dependencies:
            - backend
            - client
          template: PREBUILT
          spec:
            source:
                image: caddy:2-alpine
            ports:
                - id: web
                  port: 80
                  type: HTTP
            env:
                BACKEND_ENDPOINT:
                    default: http://backend:3001
                CLIENT_ENDPOINT:
                    default: http://client:3000
                PORT:
                    default: "80"
                RYBBIT_PUBLIC_URL:
                    default: https://${ZEABUR_WEB_DOMAIN}
                    expose: true
            configs:
                - path: /etc/caddy/Caddyfile
                  template: |
                    {
                      admin off
                      persist_config off
                      auto_https off
                      log {
                        format json
                      }
                      servers {
                        trusted_proxies static private_ranges 100.0.0.0/8
                      }
                    }

                    :${PORT} {
                      log {
                        format json
                      }

                      # Health check endpoint
                      handle /health {
                        reverse_proxy ${BACKEND_ENDPOINT} {
                          header_up Host {upstream_hostport}
                        }
                      }

                      # API endpoints
                      handle /api/* {
                        reverse_proxy ${BACKEND_ENDPOINT} {
                          header_up Host {upstream_hostport}
                        }
                      }

                      # All other requests go to frontend
                      reverse_proxy /* ${CLIENT_ENDPOINT} {
                        header_up Host {upstream_hostport}
                      }
                    }
                  permission: null
                  envsubst: true
          domainKey: PUBLIC_DOMAIN
        - name: clickhouse
          icon: https://avatars.githubusercontent.com/u/54801242
          template: PREBUILT
          spec:
            source:
                image: clickhouse/clickhouse-server:24-alpine
            ports:
                - id: http
                  port: 8123
                  type: HTTP
                - id: native
                  port: 9000
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/clickhouse
            instructions:
                - title: ClickHouse HTTP URL
                  content: http://${PORT_FORWARDED_HOSTNAME}:${HTTP_PORT_FORWARDED_PORT}
                - title: ClickHouse Native URL
                  content: clickhouse://${PORT_FORWARDED_HOSTNAME}:${NATIVE_PORT_FORWARDED_PORT}
                - title: ClickHouse Database
                  content: ${CLICKHOUSE_DB}
                - title: ClickHouse Username
                  content: ${CLICKHOUSE_USER}
                - title: ClickHouse Password
                  content: ${CLICKHOUSE_PASSWORD}
                - title: ClickHouse host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: ClickHouse HTTP port
                  content: ${HTTP_PORT_FORWARDED_PORT}
                - title: ClickHouse Native port
                  content: ${NATIVE_PORT_FORWARDED_PORT}
            env:
                CLICKHOUSE_DB:
                    default: analytics
                    expose: true
                CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT:
                    default: "1"
                CLICKHOUSE_PASSWORD:
                    default: frog
                    expose: true
                CLICKHOUSE_USER:
                    default: default
                    expose: true
                PORT:
                    default: "8123"
            configs:
                - path: /etc/clickhouse-server/config.d/docker_related_config.xml
                  template: |-
                    <clickhouse>
                         <!-- Listen wildcard address to allow accepting connections from other containers and host network. -->
                        <listen_host>::</listen_host>
                        <listen_host>0.0.0.0</listen_host>
                        <listen_try>1</listen_try>

                        <logger>
                            <level>information</level>
                            <console>1</console>
                        </logger>
                    </clickhouse>
                  permission: null
                  envsubst: null
                - path: /etc/clickhouse-server/users.d/experimental_settings.xml
                  template: |-
                    <clickhouse>
                        <profiles>
                            <default>
                                <allow_experimental_json_type>1</allow_experimental_json_type>
                            </default>
                        </profiles>
                    </clickhouse>
                  permission: null
                  envsubst: null
        - name: postgresql
          icon: https://cdn.zeabur.com/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: postgres:15
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/data
            instructions:
                - title: Connection String
                  content: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DB}
                - title: PostgreSQL Connect Command
                  content: psql "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DB}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USER}
                - title: PostgresSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgresSQL database
                  content: ${POSTGRES_DB}
                - title: PostgreSQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                POSTGRES_DB:
                    default: analytics
                    expose: true
                POSTGRES_PASSWORD:
                    default: frog
                    expose: true
                POSTGRES_USER:
                    default: frog
                    expose: true
            healthCheck:
                type: TCP
                port: database
        - name: backend
          icon: https://avatars.githubusercontent.com/u/208537280?s=200&v=4
          dependencies:
            - postgresql
            - clickhouse
          template: PREBUILT
          spec:
            source:
                image: ghcr.io/rybbit-io/rybbit-backend:latest
            ports:
                - id: api
                  port: 3001
                  type: HTTP
            env:
                BASE_URL:
                    default: ${RYBBIT_PUBLIC_URL}
                BETTER_AUTH_SECRET:
                    default: ${PASSWORD}
                CLICKHOUSE_DB:
                    default: analytics
                CLICKHOUSE_HOST:
                    default: http://clickhouse:8123
                CLICKHOUSE_PASSWORD:
                    default: frog
                CLICKHOUSE_USER:
                    default: default
                DISABLE_SIGNUP:
                    default: "false"
                NODE_ENV:
                    default: production
                PORT:
                    default: "3001"
                POSTGRES_DB:
                    default: analytics
                POSTGRES_HOST:
                    default: postgresql
                POSTGRES_PASSWORD:
                    default: frog
                POSTGRES_PORT:
                    default: "5432"
                POSTGRES_USER:
                    default: frog
        - name: client
          icon: https://avatars.githubusercontent.com/u/208537280?s=200&v=4
          dependencies:
            - backend
          template: PREBUILT
          spec:
            source:
                image: ghcr.io/rybbit-io/rybbit-client:latest
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            env:
                NEXT_PUBLIC_BACKEND_URL:
                    default: ${RYBBIT_PUBLIC_URL}
                NEXT_PUBLIC_DISABLE_SIGNUP:
                    default: "false"
                NODE_ENV:
                    default: production
                PORT:
                    default: "3000"
localization:
    zh-CN:
        readme: |
            # Rybbit 网站分析平台

            Rybbit 是一个强大且注重隐私的网站分析平台，提供实时的网站性能与用户行为洞察。

            ⚠️ 注意：请务必将您的域名绑定到 `caddy` 服务，这是访问 Rybbit 分析平台的唯一入口。

            ## 使用方法

            `caddy` 服务是您 Rybbit 实例的入口点。它是一个反向代理，会将所有流量路由到正确的服务。您应该将自定义域名绑定到该服务，才能访问 Rybbit 平台。

            入口服务的主要功能：
            - 处理所有进入的 HTTP/HTTPS 流量
            - 将请求路由到正确的服务（后端 API、前端客户端）
            - 提供 SSL/TLS 终端
            - 管理域名绑定和路由规则

            ## 功能特色

            - **实时分析**：实时跟踪访客行为与网站性能
            - **隐私优先**：在提供有价值洞察的同时尊重用户隐私
            - **自定义仪表盘**：美观直观的数据可视化仪表盘
            - **多数据库支持**：结合 PostgreSQL 与 ClickHouse 达到最佳性能
            - **可扩展架构**：专为高流量网站设计

            ## 包含的服务

            此模板部署完整的 Rybbit 分析堆栈：

            - **Caddy**：自动 HTTPS 的反向代理（入口点）
            - **PostgreSQL**：用户数据与配置的主要数据库
            - **ClickHouse**：事件跟踪的高性能分析数据库
            - **Backend**：Node.js API 服务器
            - **Client**：Next.js 前端应用程序

            ## 配置

            部署后：

            1. **使用您配置的域名访问仪表盘**
            2. **使用提供的认证密钥配置身份验证**
            3. **添加 Rybbit 跟踪脚本到您的网站来设置跟踪**
            4. **通过美观的仪表盘界面监控分析**

            ## 数据库访问

            - **PostgreSQL**：用于用户账户、网站配置与元数据
            - **ClickHouse**：针对存储与查询大量分析数据进行优化

            ## 环境变量

            模板会自动配置所有必要的环境变量。如有需要，您可以在服务配置中修改：

            - 数据库连接与认证
            - 身份验证设置
            - 功能开关（如禁用注册）

            ## 开始使用

            1. 部署此模板
            2. 将您的域名绑定到 Caddy 服务
            3. 访问您的 Rybbit 仪表盘
            4. 创建您的第一个跟踪网站
            5. 将跟踪代码添加到您的网站

            更多信息请参考 [Rybbit 官方文档](https://github.com/rybbit-io/rybbit)。
    zh-TW:
        readme: |
            # Rybbit 網站分析平台

            Rybbit 是一個強大且注重隱私的網站分析平台，提供即時的網站效能與用戶行為洞察。

            ⚠️ 注意：請務必將您的網域綁定到 `caddy` 服務，這是存取 Rybbit 分析平台的唯一入口。

            ## 使用方式

            `caddy` 服務是您 Rybbit 實例的入口點。它是一個反向代理，會將所有流量路由到正確的服務。您應該將自訂網域綁定到這個服務，才能存取 Rybbit 平台。

            入口服務的主要功能：
            - 處理所有進入的 HTTP/HTTPS 流量
            - 將請求路由到正確的服務（後端 API、前端客戶端）
            - 提供 SSL/TLS 終端
            - 管理網域綁定與路由規則

            ## 功能特色

            - **即時分析**：即時追蹤訪客行為與網站效能
            - **隱私優先**：在提供有價值洞察的同時尊重用戶隱私
            - **客製化儀表板**：美觀直覺的資料視覺化儀表板
            - **多資料庫支援**：結合 PostgreSQL 與 ClickHouse 達到最佳效能
            - **可擴展架構**：專為高流量網站設計

            ## 包含的服務

            此模板部署完整的 Rybbit 分析堆疊：

            - **Caddy**：自動 HTTPS 的反向代理（入口點）
            - **PostgreSQL**：用戶資料與設定的主要資料庫
            - **ClickHouse**：事件追蹤的高效能分析資料庫
            - **Backend**：Node.js API 伺服器
            - **Client**：Next.js 前端應用程式

            ## 設定

            部署後：

            1. **使用您設定的網域存取儀表板**
            2. **使用提供的認證密鑰設定身份驗證**
            3. **新增 Rybbit 追蹤腳本到您的網站來設定追蹤**
            4. **透過美觀的儀表板介面監控分析**

            ## 資料庫存取

            - **PostgreSQL**：用於用戶帳戶、網站設定與中繼資料
            - **ClickHouse**：針對儲存與查詢大量分析資料進行最佳化

            ## 環境變數

            模板會自動設定所有必要的環境變數。如有需要，您可以在服務設定中修改：

            - 資料庫連接與認證
            - 身份驗證設定
            - 功能開關（如停用註冊）

            ## 開始使用

            1. 部署此模板
            2. 將您的網域綁定到 Caddy 服務
            3. 存取您的 Rybbit 儀表板
            4. 建立您的第一個追蹤網站
            5. 將追蹤代碼新增到您的網站

            更多資訊請參考 [Rybbit 官方文件](https://github.com/rybbit-io/rybbit)。
