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

UBA Code Generation Pipeline Tutorial

The project adopts Contract-First: write .proto / Ent schemas first, then generate Go / TypeScript / OpenAPI code. Understanding this pipeline is a prerequisite for secondary development. This tutorial is written based on the project's real toolchain; the commands can be copied and executed directly.


1. Toolchain Installation

cd backend
make init    # install protoc plugins + CLI tools (buf / wire / ent etc.)
ToolPurpose
bufproto compilation (replaces protoc)
protoc-gen-go / protoc-gen-go-grpcGo messages + gRPC stubs
protoc-gen-go-httpkratos REST handlers
protoc-gen-typescript-httpadmin frontend TS client
protoc-gen-openapiSwagger docs
wireCompile-time dependency injection
entORM entity code generation

2. Core Commands (run under backend/)

make api       # generate Go (proto → gen/go/) + struct tags
make ts        # generate the frontend TS client (only admin/service/v1 as input)
make openapi   # generate OpenAPI / Swagger
make ent       # generate ent entities (in each service directory)
make wire      # regenerate dependency injection (wire_gen.go)
make gen       # = ent + wire + api + openapi (not including ts)
make build     # compile all services

Top-level Makefile vs service-level app.mk

  • backend/Makefile: top-level orchestration, recursing into each service via app/*/*/Makefile.
  • backend/app.mk: the common fragment included by every service, containing build / build_only / run / app / gen / ent / wire / api / openapi / docker etc.

3. Key Configuration Files

FilePurpose
backend/api/buf.yamlbuf module definition, dependencies
backend/api/buf.gen.yamlGo generation config (managed mode injects go_package)
backend/api/buf.admin.typescript.gen.yamlTS generation config; note that inputs.paths only contains protos/admin/service/v1 — only admin protos generate the TS client
backend/app/core/service/app.mkent generation command (with feature flags: privacy/entql/sql/modifier etc.)

4. ⚠️ Ent Generation Pitfall (important)

Do not run ent generate ./schema directly! It loses the project's extensions (privacy / sql modifier), causing the generated query methods to lack Modify/Filter, and compilation fails.

The correct way (see backend/app/core/service/app.mk):

cd backend/app/core/service
ent generate \
  --feature privacy --feature entql \
  --feature sql/modifier --feature sql/upsert --feature sql/lock \
  ./internal/data/ent/schema

Or simply run make ent in that service directory.


5. ⚠️ Syncing TS Generation Artifacts

make ts outputs to:

frontend/admin/apps/admin/src/api/generated/admin/service/v1/index.ts

But the composables actually import from:

frontend/admin/apps/admin/src/generated/api/admin/service/v1/index.ts

Manual sync is required after generation:

cp frontend/admin/apps/admin/src/api/generated/admin/service/v1/index.ts \
   frontend/admin/apps/admin/src/generated/api/admin/service/v1/index.ts

This is a known step in the current project setup and easy to miss. If "the proto change did not take effect", check this step first.


6. Output Locations of Generated Artifacts

backend/
├── api/
│   └── gen/go/                  # Go artifacts of make api
└── app/core/service/
    └── internal/
        ├── data/ent/            # entity artifacts of make ent (ent client, queries, mixins)
        └── cmd/server/wire_gen.go  # dependency injection artifact of make wire

frontend/admin/apps/admin/src/
├── api/generated/.../index.ts   # output of make ts
└── generated/api/.../index.ts   # actually imported by composables (needs manual sync)

Generated artifacts should be committed to version control (the project does not gitignore them), so the project compiles even without the toolchain installed.


7. Typical Workflows

Changed proto (added/modified interfaces)

cd backend
make api && make openapi && make ts
# Sync TS (see section 5)
# If service constructors/Providers changed, also:
cd app/core/service && make wire
cd app/admin/service && make wire
make build

Changed Ent schema (added/modified business entities)

cd backend/app/core/service
make ent        # use the correct command with feature flags
cd ../../..
make api        # if the entity also has a corresponding proto
make wire       # if Providers changed
make build

Changed service dependency injection (added Providers)

cd backend/app/<svc>/service
make wire

8. Debugging Tips

  • Integrating the admin frontend: cd frontend/admin && pnpm dev, with the backend admin running on 5600.
  • Integrating SDK reporting: go run ./app/collector/service/cmd/server/ (5700), using the Web SDK's test.html.
  • gRPC debugging: the core port is dynamic; query registrations via etcd, or temporarily change the grpc addr in server.yaml to a fixed port.
  • Proto change not taking effect? Most likely you forgot make ts + the TS sync (section 5), or forgot make wire.
  • ent compile error about missing Modify? You used the wrong ent generation command (see section 4).

9. Related Documentation

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