中台服务,包含许多公共服务
graph TD
%% Client/Consumer Layer
subgraph "Client/Consumer Layer"
CA1["Auth Client"]:::client
CA2["Chat Client"]:::client
CA3["Other Clients"]:::client
CT1["Auth Integration Tests"]:::test
end
%% API Gateway / Edge Services
subgraph "API Gateway / Edge Services"
GW1["Auth REST Gateway"]:::gateway
GW2["Chat REST Gateway"]:::gateway
end
%% Microservices Layer
subgraph "Microservices Layer"
MI1["Auth Service (public/private)"]:::service
MI2["Analytics Service (public/private)"]:::service
MI3["Buddy Service (public/private)"]:::service
MI4["Chat Service (public/private)"]:::service
MI5["Knapsack Service (public/private)"]:::service
MI6["Leaderboard Service (public/private)"]:::service
MI7["Mail Service (public/private)"]:::service
MI8["Matchmaking Service (public/private)"]:::service
MI9["Party Service (public/private)"]:::service
MI10["Profile Service (public/private)"]:::service
MI11["Room Service (public/private)"]:::service
end
%% Data Storage / Database Layer
subgraph "Data Storage / Database Layer"
DB1["Auth DB/Redis"]:::database
DB2["Buddy DB"]:::database
DB3["Knapsack DB"]:::database
DB4["Leaderboard DB"]:::database
DB5["Profile Redis"]:::database
end
%% External Integrations
subgraph "External Integrations"
EX1["Analytics BI (ThinkingData,MixPanel,ClickHouse)"]:::external
EX2["Matchmaking (Agones/OpenMatch)"]:::external
end
%% API Definitions / Contracts
subgraph "API Definitions / Contracts"
API["API Contracts (Protobuf)"]:::apicontracts
end
%% Containerization & Deployment
subgraph "Containerization & Deployment"
DOCKER["Docker"]:::container
KUBE["Kubernetes"]:::container
CI["CI/CD (GitHub Workflows)"]:::container
end
%% Connections between Layers
%% Client Layer to API Gateway
CA1 -->|"requests"| GW1
CA2 -->|"requests"| GW2
CA3 -->|"requests"| GW1
CT1 -->|"tests"| GW1
%% API Gateway to Microservices (public endpoints)
GW1 -->|"forwards"| MI1
GW2 -->|"forwards"| MI4
%% Inter-service communication (example flows)
MI1 -->|"gRPC"| MI2
MI4 -->|"gRPC"| MI1
%% Microservices to Data Storage
MI1 -->|"stores"| DB1
MI3 -->|"stores"| DB2
MI5 -->|"stores"| DB3
MI6 -->|"stores"| DB4
MI10 -->|"stores"| DB5
%% Microservices to External Integrations
MI2 -->|"BI calls"| EX1
MI8 -->|"matchmaking"| EX2
%% API Contracts used by Microservices
API -->|"defines"| MI1
API -->|"defines"| MI2
API -->|"defines"| MI3
API -->|"defines"| MI4
API -->|"defines"| MI5
API -->|"defines"| MI6
API -->|"defines"| MI7
API -->|"defines"| MI8
API -->|"defines"| MI9
API -->|"defines"| MI10
API -->|"defines"| MI11
%% Containerization & Deployment flow
CI -->|"triggers build"| DOCKER
DOCKER -->|"deploys to"| KUBE
KUBE -->|"runs"| MI1
%% Styles
classDef client fill:#AEDFF7,stroke:#333,stroke-width:2px;
classDef gateway fill:#FFA07A,stroke:#333,stroke-width:2px;
classDef service fill:#90EE90,stroke:#333,stroke-width:2px;
classDef database fill:#F4A460,stroke:#333,stroke-width:2px;
classDef external fill:#87CEFA,stroke:#333,stroke-width:2px;
classDef container fill:#DDA0DD,stroke:#333,stroke-width:2px;
classDef apicontracts fill:#F5DEB3,stroke:#333,stroke-width:2px;
classDef test fill:#FFB6C1,stroke:#333,stroke-width:2px;
%% Click Events
click CA1 "https://github.com/moke-game/platform/tree/main/cmd/auth/client"
click CA2 "https://github.com/moke-game/platform/tree/main/cmd/chat/client"
click CT1 "https://github.com/moke-game/platform/tree/main/tests/auth"
click GW1 "https://github.com/moke-game/platform/blob/main/api/gen/auth/api/auth.pb.gw.go"
click GW2 "https://github.com/moke-game/platform/blob/main/api/gen/chat/api/chat.pb.gw.go"
click MI1 "https://github.com/moke-game/platform/tree/main/services/auth"
click MI2 "https://github.com/moke-game/platform/tree/main/services/analytics"
click MI3 "https://github.com/moke-game/platform/tree/main/services/buddy"
click MI4 "https://github.com/moke-game/platform/tree/main/services/chat"
click MI5 "https://github.com/moke-game/platform/tree/main/services/knapsack"
click MI6 "https://github.com/moke-game/platform/tree/main/services/leaderboard"
click MI7 "https://github.com/moke-game/platform/tree/main/services/mail"
click MI8 "https://github.com/moke-game/platform/tree/main/services/matchmaking"
click MI9 "https://github.com/moke-game/platform/tree/main/services/party"
click MI10 "https://github.com/moke-game/platform/tree/main/services/profile"
click MI11 "https://github.com/moke-game/platform/tree/main/services/room"
click DB1 "https://github.com/moke-game/platform/tree/main/services/auth/internal/db"
click DB2 "https://github.com/moke-game/platform/tree/main/services/buddy/internal/db"
click DB3 "https://github.com/moke-game/platform/tree/main/services/knapsack/internal/db"
click DB4 "https://github.com/moke-game/platform/tree/main/services/leaderboard/internal/db"
click DB5 "https://github.com/moke-game/platform/tree/main/services/profile/internal/db/redis"
click EX1 "https://github.com/moke-game/platform/tree/main/services/analytics/internal/service/bi"
click EX2 "https://github.com/moke-game/platform/tree/main/services/matchmaking/internal/agones"
click DOCKER "https://github.com/moke-game/platform/tree/main/build/package/docker/Dockerfile"
click KUBE "https://github.com/moke-game/platform/tree/main/deployment/k8s"
click CI "https://github.com/moke-game/platform/tree/main/.github/workflows"
click API "https://github.com/moke-game/platform/tree/main/api"
工程目录结构参考project-layout
fxmain.Main(...) 自带:进程设置、日志、gRPC/gateway 绑定、Mongo、Redis 客户端、MQ 路由。
用一句话拼进程(pkg/assembly 会补齐 NATS / cache / JWT):
assembly.Main("profile")
assembly.Main("profile", "knapsack", "chat")
assembly.Main("platform")
assembly.Main("认证", "玩家", "背包")
assembly.Main("auth.mw", "profile.client", "knapsack.client")
单服务进程用 module.App(只链本服务 + 依赖,镜像更小):
fxmain.Main(profile.App) // == nats + cache + JWT + profile
或按积木手拼:
fxmain.Main(assembly.NATS, assembly.Cache, assembly.AuthMW, assembly.Profile)
| 名字 | 自动带上 | 说明 |
|---|---|---|
auth |
cache + AuthAll | 登录仍 WithoutAuth |
analytics |
PrivateServiceAuth | 仅内部 WithoutAuth |
profile / knapsack / buddy |
nats + cache + JWT | 文档 ICache |
chat / mail / party |
nats + JWT | 发布/订阅 |
leaderboard / matchmaking |
JWT | 无 NATS/cache |
room |
Agones SDK | zinx,不走 gRPC 中间件 |
platform |
cache + nats + AuthAll + 上表服务 | 不含 room |
中文别名:认证 玩家 背包 聊天 邮件 组队 好友 排行 匹配 房间 统计 中台。
cmd/platform → assembly.Main("platform")cmd/{name} → fxmain.Main(module.App)services/auth/README.mdpkg/platformfx# fix {appname} to service name
docker buildx build -t {appname}.registry.com:latest --build-arg APP_NAME={appname} -f ./build/package/docker/Dockerfile . --push
go build -o client.exe ./cmd/{game-name}/client/main.go
# help
./{game-name}.exe help
tips: http client use Postman to connect localhost:8081. # fix the game-name to your game name
k6 run ./tests/{game-name}/{game-name}.js
AuthMiddlewareModule(或 AuthAllModule)。*PrivateService):嵌入 utility.WithoutAuth,仅内网 / mTLS。