GoWindGoWind
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
  • Introduction

    • GoWind UBA Product Introduction
  • Architecture Reference

    • UBA System Architecture
    • UBA Backend Module Overview
    • UBA Backend API Contract
    • UBA Frontend Architecture
  • Developer Guide

    • UBA Installation Guide
    • UBA Code Generation Pipeline Tutorial
    • Adding an External Service Tutorial
    • Adding a Business Entity Tutorial
    • Adding a Frontend Page Tutorial
  • Operations Guide

    • UBA Docker Deployment Guide
    • UBA Configuration Reference & Security Checklist
    • UBA PM2 Deployment Guide
    • UBA Superset BI Deployment Guide
  • Analyst Guide

    • Data Analyst Getting Started Guide
    • Basic Aggregation

      • Event Trend Analysis
      • Active Users Analysis
      • Group By Aggregation
    • Conversion & Paths

      • Funnel Analysis
      • Retention Analysis
      • Top Conversion Paths
      • Behavior Sequence Analysis
    • User Depth

      • Attribution Analysis
      • Distribution Analysis
      • User Segmentation
      • Click Heatmap
      • Interval Analysis
    • Lifecycle

      • User Lifecycle
      • Churn & Reactivation Analysis
      • New vs Returning Users
      • Matrix Quadrant Analysis
    • Revenue & Value

      • Revenue Analysis
      • Whale Tier (Payer Segmentation)
      • Historical LTV Analysis
    • Sessions & Anomalies

      • Session Analysis
      • Period-over-Period Comparison and Anomaly Detection
    • Gaming

      • Level Analysis (Game)
      • Server Retention (Game)
      • Online Stats Analysis (Game)
      • Economy Analysis (Game)
    • OLAP Cookbook
  • SDK Integration

    • Web SDK Integration Guide
    • C# SDK Integration Guide (Unity / Godot / .NET)
  • Appendix

    • UBA Appendix: Ports, Glossary, Known Limitations & FAQ

Adding an External Service Tutorial

This tutorial demonstrates how to add a new external HTTP capability on UBA (admin REST interface + core business implementation + admin forwarding), using the already-implemented AnalyticsService (data analytics) in the project as a reference. This is the most common secondary development scenario in UBA.

Prerequisites: first read the "Three-Layer Service Architecture" section of System Architecture and the Code Generation Pipeline.


1. Goal & Pattern Recap

UBA's three-layer pattern:

admin/service/v1/i_xxx.proto        # HTTP gateway interface (with google.api.http annotations)
uba/service/v1/xxx.proto            # Domain messages + gRPC service contract
core/service/internal/service/      # Business implementation (implements the uba gRPC server)
admin/service/internal/service/     # Forwarding implementation (implements the admin HTTP server → calls the uba client)

The admin layer is pure forwarding with no business logic; business logic is concentrated in core. A new capability requires one set of additions in each of the two layers.


2. Steps

Step 1: Define the domain proto

File: backend/api/protos/uba/service/v1/xxx.proto

syntax = "proto3";
package uba.service.v1;

service XxxService {
  rpc DoSomething(DoSomethingRequest) returns (DoSomethingResponse) {}
}

message DoSomethingRequest {
  // business fields
}
message DoSomethingResponse {
  // business fields
}

Key points:

  • package uba.service.v1;
  • Define service XxxService { rpc ... } (gRPC contract, no http annotations)
  • Define all message XxxRequest/Response

Step 2: Define the admin gateway proto

File: backend/api/protos/admin/service/v1/i_xxx.proto

syntax = "proto3";
package admin.service.v1;

import "uba/service/v1/xxx.proto";

service XxxService {
  rpc DoSomething(uba.service.v1.DoSomethingRequest) returns (uba.service.v1.DoSomethingResponse) {
    option (google.api.http) = {
      post: "/admin/v1/xxx"
      body: "*"
    };
  }
}

Key points:

  • package admin.service.v1;
  • import "uba/service/v1/xxx.proto"; to reuse domain messages
  • GET queries use query parameters: get: "/admin/v1/xxx"
  • POST aggregations use the body: post: "/admin/v1/xxx" body: "*"

Step 3: Generate code

cd backend && make api && make ts
# Sync TS (see section 5 of the Code Generation Pipeline tutorial)

Step 4: Implement the business logic in the core layer

Directory: backend/app/core/service/

  1. Service implementation internal/service/xxx_service.go: implement ubaV1.UnimplementedXxxServiceServer and write the business logic.

  2. Data repo internal/data/:

    • ent entities → use the generic Repository wrapper from go-crud (see uba_tag_definition_repo.go).
    • OLAP aggregations → native SQL (Doris uses r.db.SelectContext, ClickHouse uses r.db.Select; mirrored implementations for both engines, see analytics_repo.go).
  3. gRPC server registration internal/server/grpc_server.go: add the service as a parameter of NewGrpcServer and call ubaV1.RegisterXxxServiceServer.

  4. Provider registration: add providers in internal/service/providers/wire_set.go + internal/data/providers/wire_set.go.

  5. Regenerate injection:

    cd backend/app/core/service && make wire
    

Step 5: Forward in the admin layer

Directory: backend/app/admin/service/

  1. Service forwarding internal/service/xxx_service.go: implement adminV1.XxxServiceHTTPServer, with method bodies forwarding directly:

    func (s *XxxService) DoSomething(ctx context.Context, req *ubaV1.DoSomethingRequest) (*ubaV1.DoSomethingResponse, error) {
        return s.client.DoSomething(ctx, req)
    }
    
  2. Client factory internal/data/data.go: add NewXxxServiceClient (modeled on existing client factories, discovering core via etcd).

  3. REST server registration internal/server/rest_server.go: add the service as a parameter of NewRESTServer and call adminV1.RegisterXxxServiceHTTPServer.

  4. Provider registration: add providers in internal/data/providers/wire_set.go + internal/service/providers/wire_set.go.

  5. Regenerate injection:

    cd backend/app/admin/service && make wire
    

Step 6: Verify

cd backend && go build ./...

After starting the admin/core services, verify the new interface via the admin Swagger; or test directly with curl:

curl -X POST http://localhost:5600/admin/v1/xxx \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{...}'

3. Reference the Real Implementation

ReferenceFile
Domain proto (25 analysis models)api/protos/uba/service/v1/analytics.proto
Admin gateway protoapi/protos/admin/service/v1/i_analytics.proto
Core service (branches by engine)app/core/service/internal/service/analytics_service.go
Core OLAP repo (dual engines)app/core/service/internal/data/{doris,clickhouse}/analytics_repo.go
Admin forwardingapp/admin/service/internal/service/analytics_service.go
Admin client factoryapp/admin/service/internal/data/data.go (NewAnalyticsServiceClient)

For OLAP implementation details of analytics aggregations (injection prevention, whitelisted dimensions, dual-engine dialect differences), see the OLAP Query Cookbook.


4. Common Pitfalls

  • Frontend does not update after proto change: forgot make ts + manually syncing the TS artifacts (see Code Generation Pipeline).
  • wire reports "no provider": the Provider was not added to the corresponding wire_set.go, or was added to the wrong file.
  • Cannot connect to core over gRPC: core uses a dynamic port; confirm etcd registration is working, and that discovery in admin's remote.yaml points to etcd.
  • One of the dual-engine OLAP repos missed: after changing the Doris implementation, remember to sync the ClickHouse implementation to keep the mirror consistent.

5. Related Documentation

  • System Architecture
  • Code Generation Pipeline
  • Adding a Business Entity
  • Adding a Frontend Page
  • Backend API Contract
Edit this page
Last Updated:: 11/3/26, 2:14 PM
Contributors: Bobo
Prev
UBA Code Generation Pipeline Tutorial
Next
Adding a Business Entity Tutorial